Skip to content

v3 CLI compiling E2E test suite #1135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
14843e1
Boilerplate server-only use case
codenem May 22, 2024
fd3e4a6
wip: integration suite instrumentation setup
codenem May 27, 2024
a042203
Working poc testing compileProject
codenem May 28, 2024
cf560ae
Add pnpm script to run e2e tests only
codenem May 28, 2024
a09039d
Use vitest globals
codenem May 28, 2024
bfea435
Remove commented line
codenem May 28, 2024
a1ebcf5
Remove useless export
codenem May 28, 2024
f8c1d2b
Add modifier to test only one fixture project
codenem May 29, 2024
3c63fe8
Handle package manager and log level choice
codenem May 29, 2024
04fa1e5
Update server-only example
codenem May 29, 2024
b164ecf
Setup / teardown + split compile for package manager capabilities
codenem Jun 4, 2024
41af77b
Ignore yarn files
codenem Jun 4, 2024
daea4ca
Fix issue with corepack, store version in engines field
codenem Jun 4, 2024
8c8c41d
Rename test file
codenem Jun 4, 2024
fbd3351
Fix npm updates yarn.lock
codenem Jun 4, 2024
e53276b
Move typecheking in a dedicated test
codenem Jun 5, 2024
b050946
Stop bundling the compile command to allow for more granular testing
codenem Jun 5, 2024
4416c91
Put config resolving in separate test
codenem Jun 5, 2024
a2ae82f
Add no-config test case and add test case expected errors configuration
codenem Jun 6, 2024
bd972ff
Add wantCompilationError option
codenem Jun 6, 2024
4eb0622
Add dependencies handling
codenem Jun 6, 2024
a04fe7f
Use packageManager passed as option to resolve required deps
codenem Jun 6, 2024
f724c2d
Remove unused guard clauses
codenem Jun 6, 2024
f54b300
Add postinstall & hash handling step
codenem Jun 6, 2024
29ce5ca
Add worker start test
codenem Jun 10, 2024
cc76ef2
Handle yarn.lock copy renaming on sigterm and sigkill
codenem Jun 11, 2024
6bc8f96
Update vitest and use concurrent option
codenem Jun 11, 2024
5a2c163
Add a readme file
codenem Jun 11, 2024
8152bdc
Add CI workflow
codenem Jun 11, 2024
916795c
Fix handle cli deps
codenem Jun 12, 2024
271d1b6
Run cli v3 e2e tests on publish action
codenem Jun 12, 2024
e8083cd
Increase timeout on deps resolving step
codenem Jun 12, 2024
29baa11
Add changeset
codenem Jun 12, 2024
a584e3d
Remove .pnp.cjs as we use yarn with nodeLinker node-modules
codenem Jun 12, 2024
ebd71df
Add missing .yarnrc.yml file
codenem Jun 12, 2024
d188b0b
No need to build CLI to run E2E tests
codenem Jun 12, 2024
b2d1de4
Remove bun.lockb files
codenem Jun 12, 2024
69ed24e
Update beige-pears-explode.md
ericallam Jun 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/beige-pears-explode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"trigger.dev": patch
---

Add an e2e suite to test compiling with v3 CLI.
50 changes: 47 additions & 3 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,53 @@
name: "🧪 E2E Tests"
name: "E2E"
on:
workflow_call:
inputs:
package:
description: The identifier of the job to run
default: webapp
required: false
type: string
jobs:
e2e:
name: "🧪 E2E Tests"
cli-v3:
name: "🧪 CLI v3 tests"
if: inputs.package == 'cli-v3' || inputs.package == ''
runs-on: buildjet-8vcpu-ubuntu-2204
strategy:
fail-fast: false
matrix:
package-manager: ["npm", "pnpm", "yarn"]
steps:
- name: ⬇️ Checkout repo
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: ⎔ Setup pnpm
uses: pnpm/[email protected]
with:
version: 8.15.5

- name: ⎔ Setup node
uses: buildjet/setup-node@v3
with:
node-version: 20.11.1
cache: "pnpm"

- name: 📥 Download deps
run: pnpm install --frozen-lockfile --filter trigger.dev...

- name: 🔧 Build v3 cli monorepo dependencies
run: pnpm run build --filter trigger.dev^...

- name: 🔧 Build worker template files
run: pnpm --filter trigger.dev run build:workers

- name: Run E2E Tests
run: |
PM=${{ matrix.package-manager }} pnpm --filter trigger.dev run test:e2e
webapp:
name: "🧪 Webapp tests"
if: inputs.package == 'webapp' || inputs.package == ''
runs-on: buildjet-16vcpu-ubuntu-2204
steps:
- name: 🐳 Login to Docker Hub
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/pr_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ jobs:

# e2e:
# uses: ./.github/workflows/e2e.yml
# with:
# package: webapp
# secrets: inherit
8 changes: 5 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ jobs:
uses: ./.github/workflows/unit-tests.yml
secrets: inherit

# e2e:
# uses: ./.github/workflows/e2e.yml
# secrets: inherit
e2e:
uses: ./.github/workflows/e2e.yml
with:
package: cli-v3
secrets: inherit

publish:
needs: [typecheck, units]
Expand Down
177 changes: 177 additions & 0 deletions packages/cli-v3/e2e/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
# Trigger.dev CLI E2E suite

E2E test suite for the Trigger.dev v3 CLI.

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.

Trigger.dev is an open source platform that makes it easy to create event-driven background tasks directly in your existing project.

## Description

This suite aims to test the outputs fo the `triggerdev deploy` command.
To do so, it runs the deploy code against fixture projects that are located under `packages/cli-v3/e2e/fixtures/`.
Those fixtures reproduce minimal project structure and contents, in order to reproduce known bugs and run fast.

**Notes**
- The suite uses vitest
- Everything happens locally
- There is no login required
- There is not real project reference needed
- No docker image is created or built, instead, the bundled worker file is started with node directly inside the vitest process

## Usage

If you have not done it yet, build the CLI:

```sh
pnpm run build --filter trigger.dev
```

Then, run the v3 CLI E2E test suite:

```sh
pnpm --filter trigger.dev run test:e2e
```

| Option | Description |
| ---------------------- | ---------------------------------------------------------------------------- |
| `MOD=<fixture-name>` | The name of any folder directly nested under `packages/cli-v3/e2e/fixtures/` |
| `PM=<package-manager>` | The package manager to use. One of `npm`, `pnpm`, `yarn`. Defaults to `npm` |

Example:

```sh
MOD=server-only PM=yarn pnpm --filter trigger.dev run test:e2e
```

This will run the test suite for the `server-only` fixture using `yarn` to install and resolve dependencies.

## Debugging

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.
Check [Adding a fixture](#adding-a-fixture) for more information.

Then run:

```sh
MOD=<fixture-name> pnpm run test:e2e
```

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.

## Adding a fixture

1. Create a new `packages/cli-v3/e2e/fixtures/<fixture-name>` folder.

It will hold the project to test.

2. Add a `package.json` file in your `packages/cli-v3/e2e/fixtures/<fixture-name>` folder.

Use the following template:

```json package.json
{
"name": "<fixture-name>",
"private": true,
"engines": {
"pnpm": "8.15.5",
"yarn": "4.2.2"
},
"packageManager": "[email protected]"
}
```

> The `engines` field is used to store the versions of pnpm and yarn to use when running the suite.

3. Add an empty `pnpm-workspace.yaml` in your `packages/cli-v3/e2e/fixtures/<fixture-name>` folder.

This is necessary to prevent the Trigger.dev monorepo from handling this project.
Please check https://github.com/pnpm/pnpm/issues/2412 for more inforation.

4. Add an empty `yarn.lock` in your fixture folder.

This is necessary to allow to use `yarn` without having a warning on the current project being a `pnpm` project.

5. Install the fixture dependencies and generate lockfiles.

Like you would in any project.
E.g. if your fixture contains a trigger task that uses the `jsdom` library:

```sh
cd packages/cli-v3/e2e/fixtures/<fixture-name>
corepack use [email protected]
pnpm install jsdom
```

> This will update the `package.json` and generate the `pnpm-lock.yaml` file.

6. To run the test suite against multiple package manager, we need to generate the other lockfiles.

```sh
cd packages/cli-v3/e2e/fixtures/<fixture-name>
rm -rf node_modules
npm install
rm -rf node_modules
corepack use yarn # will update the yarn lockfile
```

> Do it in this order, otherwise `npm install` will update the existing `yarn.lock` file with legacy version 1.

7. Create a new `packages/cli-v3/e2e/fixtures/trigger` folder, and create a trigger task in it.

Here is an example:

```javascript
import { task } from "@trigger.dev/sdk/v3";

export const helloWorldTask = task({
id: "hello-world",
run: async (payload) => {
console.log("Hello, World!", payload);
},
});
```

8. Add a trigger configuration file.

The configuration file is mandatory here, the E2E suite does not execute `trigger.dev` commands.

```javascript
export const config = {
project: "<fixture-name>",
triggerDirectories: ["./trigger"],
};
```

> The project reference can be anything here, as the suite runs locally without connecting to the platform.

9. Commit your changes.

10. Add your fixture test configuration in `testCases.json`.

```json testCases.json
[
...
{
"name": "<fixture-name>",
},
...
]
```

You can configure your test case by adding other properties to the JSON object. Here is the `TestCase` type for reference:

```typescript
type TestCase = {
name: string;
skipTypecheck?: boolean;
wantConfigNotFoundError?: boolean;
wantBadConfigError?: boolean;
wantCompilationError?: boolean;
wantWorkerError?: boolean;
wantDependenciesError?: boolean;
wantInstallationError?: boolean;
};
```

> You might expect a specific error at a specific test, so use those configuration option at your discretion.
Loading
Loading