Skip to content

Commit d4ccdf7

Browse files
codenemericallam
andauthored
v3 CLI compiling E2E test suite (#1135)
* Boilerplate server-only use case * wip: integration suite instrumentation setup * Working poc testing compileProject * Add pnpm script to run e2e tests only * Use vitest globals * Remove commented line * Remove useless export * Add modifier to test only one fixture project * Handle package manager and log level choice * Update server-only example * Setup / teardown + split compile for package manager capabilities * Ignore yarn files * Fix issue with corepack, store version in engines field * Rename test file * Fix npm updates yarn.lock * Move typecheking in a dedicated test * Stop bundling the compile command to allow for more granular testing * Put config resolving in separate test * Add no-config test case and add test case expected errors configuration * Add wantCompilationError option * Add dependencies handling * Use packageManager passed as option to resolve required deps * Remove unused guard clauses * Add postinstall & hash handling step * Add worker start test * Handle yarn.lock copy renaming on sigterm and sigkill * Update vitest and use concurrent option * Add a readme file * Add CI workflow * Fix handle cli deps * Run cli v3 e2e tests on publish action * Increase timeout on deps resolving step * Add changeset * Remove .pnp.cjs as we use yarn with nodeLinker node-modules * Add missing .yarnrc.yml file * No need to build CLI to run E2E tests * Remove bun.lockb files * Update beige-pears-explode.md --------- Co-authored-by: Eric Allam <[email protected]>
1 parent e08b456 commit d4ccdf7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+11635
-36
lines changed

.changeset/beige-pears-explode.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"trigger.dev": patch
3+
---
4+
5+
Add an e2e suite to test compiling with v3 CLI.

.github/workflows/e2e.yml

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,53 @@
1-
name: "🧪 E2E Tests"
1+
name: "E2E"
22
on:
33
workflow_call:
4+
inputs:
5+
package:
6+
description: The identifier of the job to run
7+
default: webapp
8+
required: false
9+
type: string
410
jobs:
5-
e2e:
6-
name: "🧪 E2E Tests"
11+
cli-v3:
12+
name: "🧪 CLI v3 tests"
13+
if: inputs.package == 'cli-v3' || inputs.package == ''
14+
runs-on: buildjet-8vcpu-ubuntu-2204
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
package-manager: ["npm", "pnpm", "yarn"]
19+
steps:
20+
- name: ⬇️ Checkout repo
21+
uses: actions/checkout@v3
22+
with:
23+
fetch-depth: 0
24+
25+
- name: ⎔ Setup pnpm
26+
uses: pnpm/[email protected]
27+
with:
28+
version: 8.15.5
29+
30+
- name: ⎔ Setup node
31+
uses: buildjet/setup-node@v3
32+
with:
33+
node-version: 20.11.1
34+
cache: "pnpm"
35+
36+
- name: 📥 Download deps
37+
run: pnpm install --frozen-lockfile --filter trigger.dev...
38+
39+
- name: 🔧 Build v3 cli monorepo dependencies
40+
run: pnpm run build --filter trigger.dev^...
41+
42+
- name: 🔧 Build worker template files
43+
run: pnpm --filter trigger.dev run build:workers
44+
45+
- name: Run E2E Tests
46+
run: |
47+
PM=${{ matrix.package-manager }} pnpm --filter trigger.dev run test:e2e
48+
webapp:
49+
name: "🧪 Webapp tests"
50+
if: inputs.package == 'webapp' || inputs.package == ''
751
runs-on: buildjet-16vcpu-ubuntu-2204
852
steps:
953
- name: 🐳 Login to Docker Hub

.github/workflows/pr_checks.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,6 @@ jobs:
2929

3030
# e2e:
3131
# uses: ./.github/workflows/e2e.yml
32+
# with:
33+
# package: webapp
3234
# secrets: inherit

.github/workflows/publish.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,11 @@ jobs:
4949
uses: ./.github/workflows/unit-tests.yml
5050
secrets: inherit
5151

52-
# e2e:
53-
# uses: ./.github/workflows/e2e.yml
54-
# secrets: inherit
52+
e2e:
53+
uses: ./.github/workflows/e2e.yml
54+
with:
55+
package: cli-v3
56+
secrets: inherit
5557

5658
publish:
5759
needs: [typecheck, units]

packages/cli-v3/e2e/README.md

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
# Trigger.dev CLI E2E suite
2+
3+
E2E test suite for the Trigger.dev v3 CLI.
4+
5+
Note: this only works with Trigger.dev v3 projects and later. There is no E2E test suite for the [@trigger.dev/cli](https://www.npmjs.com/package/@trigger.dev/cli) package yet.
6+
7+
Trigger.dev is an open source platform that makes it easy to create event-driven background tasks directly in your existing project.
8+
9+
## Description
10+
11+
This suite aims to test the outputs fo the `triggerdev deploy` command.
12+
To do so, it runs the deploy code against fixture projects that are located under `packages/cli-v3/e2e/fixtures/`.
13+
Those fixtures reproduce minimal project structure and contents, in order to reproduce known bugs and run fast.
14+
15+
**Notes**
16+
- The suite uses vitest
17+
- Everything happens locally
18+
- There is no login required
19+
- There is not real project reference needed
20+
- No docker image is created or built, instead, the bundled worker file is started with node directly inside the vitest process
21+
22+
## Usage
23+
24+
If you have not done it yet, build the CLI:
25+
26+
```sh
27+
pnpm run build --filter trigger.dev
28+
```
29+
30+
Then, run the v3 CLI E2E test suite:
31+
32+
```sh
33+
pnpm --filter trigger.dev run test:e2e
34+
```
35+
36+
| Option | Description |
37+
| ---------------------- | ---------------------------------------------------------------------------- |
38+
| `MOD=<fixture-name>` | The name of any folder directly nested under `packages/cli-v3/e2e/fixtures/` |
39+
| `PM=<package-manager>` | The package manager to use. One of `npm`, `pnpm`, `yarn`. Defaults to `npm` |
40+
41+
Example:
42+
43+
```sh
44+
MOD=server-only PM=yarn pnpm --filter trigger.dev run test:e2e
45+
```
46+
47+
This will run the test suite for the `server-only` fixture using `yarn` to install and resolve dependencies.
48+
49+
## Debugging
50+
51+
When debugging an issue with the `triggerdev deploy` or `triggerdev dev` command, it is recommended to reproduce it with a minimal project fixture in the e2e suite.
52+
Check [Adding a fixture](#adding-a-fixture) for more information.
53+
54+
Then run:
55+
56+
```sh
57+
MOD=<fixture-name> pnpm run test:e2e
58+
```
59+
60+
This will test your fixture project, and generate outputs in the `packages/cli-v3/e2e/fixtures/<fixture-name>/.trigger` folder, so you can easily debug.
61+
62+
## Adding a fixture
63+
64+
1. Create a new `packages/cli-v3/e2e/fixtures/<fixture-name>` folder.
65+
66+
It will hold the project to test.
67+
68+
2. Add a `package.json` file in your `packages/cli-v3/e2e/fixtures/<fixture-name>` folder.
69+
70+
Use the following template:
71+
72+
```json package.json
73+
{
74+
"name": "<fixture-name>",
75+
"private": true,
76+
"engines": {
77+
"pnpm": "8.15.5",
78+
"yarn": "4.2.2"
79+
},
80+
"packageManager": "[email protected]"
81+
}
82+
```
83+
84+
> The `engines` field is used to store the versions of pnpm and yarn to use when running the suite.
85+
86+
3. Add an empty `pnpm-workspace.yaml` in your `packages/cli-v3/e2e/fixtures/<fixture-name>` folder.
87+
88+
This is necessary to prevent the Trigger.dev monorepo from handling this project.
89+
Please check https://github.com/pnpm/pnpm/issues/2412 for more inforation.
90+
91+
4. Add an empty `yarn.lock` in your fixture folder.
92+
93+
This is necessary to allow to use `yarn` without having a warning on the current project being a `pnpm` project.
94+
95+
5. Install the fixture dependencies and generate lockfiles.
96+
97+
Like you would in any project.
98+
E.g. if your fixture contains a trigger task that uses the `jsdom` library:
99+
100+
```sh
101+
cd packages/cli-v3/e2e/fixtures/<fixture-name>
102+
corepack use [email protected]
103+
pnpm install jsdom
104+
```
105+
106+
> This will update the `package.json` and generate the `pnpm-lock.yaml` file.
107+
108+
6. To run the test suite against multiple package manager, we need to generate the other lockfiles.
109+
110+
```sh
111+
cd packages/cli-v3/e2e/fixtures/<fixture-name>
112+
rm -rf node_modules
113+
npm install
114+
rm -rf node_modules
115+
corepack use yarn # will update the yarn lockfile
116+
```
117+
118+
> Do it in this order, otherwise `npm install` will update the existing `yarn.lock` file with legacy version 1.
119+
120+
7. Create a new `packages/cli-v3/e2e/fixtures/trigger` folder, and create a trigger task in it.
121+
122+
Here is an example:
123+
124+
```javascript
125+
import { task } from "@trigger.dev/sdk/v3";
126+
127+
export const helloWorldTask = task({
128+
id: "hello-world",
129+
run: async (payload) => {
130+
console.log("Hello, World!", payload);
131+
},
132+
});
133+
```
134+
135+
8. Add a trigger configuration file.
136+
137+
The configuration file is mandatory here, the E2E suite does not execute `trigger.dev` commands.
138+
139+
```javascript
140+
export const config = {
141+
project: "<fixture-name>",
142+
triggerDirectories: ["./trigger"],
143+
};
144+
```
145+
146+
> The project reference can be anything here, as the suite runs locally without connecting to the platform.
147+
148+
9. Commit your changes.
149+
150+
10. Add your fixture test configuration in `testCases.json`.
151+
152+
```json testCases.json
153+
[
154+
...
155+
{
156+
"name": "<fixture-name>",
157+
},
158+
...
159+
]
160+
```
161+
162+
You can configure your test case by adding other properties to the JSON object. Here is the `TestCase` type for reference:
163+
164+
```typescript
165+
type TestCase = {
166+
name: string;
167+
skipTypecheck?: boolean;
168+
wantConfigNotFoundError?: boolean;
169+
wantBadConfigError?: boolean;
170+
wantCompilationError?: boolean;
171+
wantWorkerError?: boolean;
172+
wantDependenciesError?: boolean;
173+
wantInstallationError?: boolean;
174+
};
175+
```
176+
177+
> You might expect a specific error at a specific test, so use those configuration option at your discretion.

0 commit comments

Comments
 (0)