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 package yet.
Trigger.dev is an open source platform that makes it easy to create event-driven background tasks directly in your existing project.
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
If you have not done it yet, build the CLI:
pnpm run build --filter trigger.devThen, run the v3 CLI E2E test suite:
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:
MOD=server-only PM=yarn pnpm --filter trigger.dev run test:e2eThis will run the test suite for the server-only fixture using yarn to install and resolve dependencies.
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 for more information.
Then run:
MOD=<fixture-name> pnpm run test:e2eThis will test your fixture project, and generate outputs in the packages/cli-v3/e2e/fixtures/<fixture-name>/.trigger folder, so you can easily debug.
-
Create a new
packages/cli-v3/e2e/fixtures/<fixture-name>folder.It will hold the project to test.
-
Add a
package.jsonfile in yourpackages/cli-v3/e2e/fixtures/<fixture-name>folder.Use the following template:
{ "name": "<fixture-name>", "private": true, "engines": { "pnpm": "8.15.5", "yarn": "4.2.2" }, "packageManager": "pnpm@8.15.5" }The
enginesfield is used to store the versions of pnpm and yarn to use when running the suite. -
Add an empty
pnpm-workspace.yamlin yourpackages/cli-v3/e2e/fixtures/<fixture-name>folder.This is necessary to prevent the Trigger.dev monorepo from handling this project. Please check pnpm/pnpm#2412 for more inforation.
-
Add an empty
yarn.lockin your fixture folder.This is necessary to allow to use
yarnwithout having a warning on the current project being apnpmproject. -
Add the following
.yarnrc.yamlin your fixture folder.This will avoid having
.pnp.cjsand.pnp.loader.mjsand keep versioned files to a minimum.nodeLinker: node-modules
-
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
jsdomlibrary:cd packages/cli-v3/e2e/fixtures/<fixture-name> corepack use pnpm@8.15.5 pnpm install jsdom
This will update the
package.jsonand generate thepnpm-lock.yamlfile. -
Make sure typescript is installed in the fixture project.
cd packages/cli-v3/e2e/fixtures/<fixture-name> corepack use pnpm@8.15.5 pnpm install typescript
This is necessary to typecheck the project during the test suite.
-
Add a tsconfig.json file similar to the one below:
{ "include": ["src/**/*.ts", "trigger.config.ts"], "compilerOptions": { "target": "es2022", "lib": ["ES2022", "DOM", "DOM.Iterable"], "module": "NodeNext", "moduleResolution": "NodeNext", "moduleDetection": "force", "verbatimModuleSyntax": false, "jsx": "react", "strict": true, "alwaysStrict": true, "strictPropertyInitialization": false, "skipLibCheck": true, "forceConsistentCasingInFileNames": true, "noUnusedLocals": false, "noUnusedParameters": false, "noImplicitAny": true, "noImplicitReturns": true, "noImplicitThis": true, "noFallthroughCasesInSwitch": true, "resolveJsonModule": true, "removeComments": false, "esModuleInterop": true, "emitDecoratorMetadata": false, "experimentalDecorators": false, "downlevelIteration": true, "isolatedModules": true, "noUncheckedIndexedAccess": true, "pretty": true } } -
To run the test suite against multiple package manager, we need to generate the other lockfiles.
cd packages/cli-v3/e2e/fixtures/<fixture-name> rm -rf **/node_modules npm install rm -rf **/node_modules corepack use yarn@4.2.2 # will update the yarn lockfile
Do it in this order, otherwise
npm installwill update the existingyarn.lockfile with legacy version 1. -
Create a new
packages/cli-v3/e2e/fixtures/triggerfolder, and create a trigger task in it.Here is an example:
import { task } from "@trigger.dev/sdk/v3"; export const helloWorldTask = task({ id: "hello-world", run: async (payload) => { console.log("Hello, World!", payload); }, });
-
Add a trigger configuration file.
The configuration file is mandatory here, the E2E suite does not execute
trigger.devcommands.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.
-
Commit your changes.
-
Add your fixture test configuration in
fixtures.config.js.export const fixturesConfig = [ // ... { id: "<fixture-name>", }, // ... ];
You might expect a specific error for a specific test, so use those configuration option at your discretion.
The @trigger.dev/sdk package is installed in the fixtures as a real dependency (not from the monorepo).
To update it, you'll need to update the version in the package.json file, and then run the following commands:
NOTE: Some fixtures don't support all the package managers, like the monorepo-react-email only supports yarn and pnpm.
cd packages/cli-v3/e2e/fixtures/<fixture-name>
rm -rf **/node_modules
corepack use pnpm@8.15.5
rm -rf **/node_modules
npm install
rm -rf **/node_modules
corepack use yarn@4.2.2
rm -rf **/node_modules