dagger toolchain install github.com/dagger/jest
projects: List the Jest projects visible from the current directorytestAll: Execute the tests of every visible project (the automatic check)test: Execute the tests of a single projectlist: List the tests of a single project
Discovery is anchored at the directory you run Dagger from, not at the workspace
root: dagger check tests the project you are in and the projects beneath it. A
project is any directory holding a jest.config.* file (node_modules
excluded); a jest key in package.json also configures Jest, but
package.json marks every npm package, so it is not a discovery marker.
# from the workspace root of a monorepo holding a/ and b/
dagger call jest projects # -> a, b
# from a/
dagger call jest projects # -> .A directory holding no config of its own sits inside its enclosing project, so
that project is reported as a ..-relative path and runs too. To run a single
project, enter it.
The toolchain can be customized in your dagger.json to meet your needs:
{
"name": "my-module",
"engineVersion": "...",
"toolchains": [
{
"name": "jest",
"source": "github.com/dagger/jest@main",
"pin": "...",
"customizations": [
{
"argument": "baseImageAddress",
"default": "node:22" # default: node:25-alpine; use any container image
},
{
"argument": "packageManager",
"default": "yarn" # default: npm; alternatively use yarn, pnpm, or bun
},
{
"function": ["test"],
"argument": "files",
"default": ["Test1.js", "Test2.js"] # default: [] (all); List of files to test
},
{
"function": ["test"],
"argument": "build",
"default": true # default: false; Run build before test
},
{
"function": ["test"],
"argument": "useEnv",
"default": true # default: false; Use jest-defined environment
},
{
"function": ["test"],
"argument": "flags",
"default": ["--debug"] # default: []; Flags to pass to jest
}
]
}
]
}Automatically instrument Jest tests for Open Telemetry.
The toolchain does this automatically, however you can use the library without the toolchain as described below.
Test spans include dagger.io/ui.boundary plus OpenTelemetry test semantic convention attributes: test.case.name, test.case.result.status, and test.suite.name.
Suite spans include dagger.io/ui.boundary, test.suite.name, and test.suite.run.status.
Console output emitted with console.log, console.info, console.debug, console.warn,
and console.error is exported as OpenTelemetry logs on the active test span.
Install @dagger.io/jest in your project
npm install @dagger.io/jestYou can either follow a no-configuration setup or update your current jest.config.js file.
Add the following import in your NODE_OPTIONS to auto-instrument when running your test
"NODE_OPTIONS=\"$NODE_OPTIONS --require @dagger.io/jest/register \" jest💡 If your project is in ESM, make sure you first followed ECMAScript Module setup on Jest
The library export an environment that you can use to automatically instrument your tests:
testEnvironment: "@dagger.io/jest/node-environment"