Skip to content

About

No description, website, or topics provided.

Resources

Code of conduct

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

e2e

A Dagger module, written in Dang, that runs e2e tests against the projects in a workspace. It reads what it needs from your project: the config, the toolchain, the browsers and the test files. Every test file is a check, and every test shows up in the TUI and Dagger Cloud.

Requires Dagger v1.0.0-beta.30 or later. Tested on beta.30 and beta.31, with e2e 0.24.0 and 0.26.1.

Usage

dagger module install github.com/dagger/e2e-module
dagger check                                      # every check in the workspace
dagger check e2e/projects/tests/test --e2e-project=apps/web
dagger check e2e/projects/tests/test --e2e-project=apps/web \
  --e2e-test-file=tests/login.e2e.ts              # one file

A project whose config starts its app (app.command) needs no settings. To test an app another module serves, wire it in:

[modules.e2e.settings]
service = "dag://myapp/serve"

Other functions, on dagger api call e2e project --path=apps/web:

Function
report The run's output directory (report.json, traces, screenshots), tolerating failures. Shards are merged.
doctor e2e doctor in the test container.
targets The config's targets: which run, and what serves the app of each.
update-snapshots Writes the stored screenshots for the Linux the checks run on. Returns a changeset.
record-cache Records agent steps into the replay cache. Returns a changeset.
base The test container.

What is detected

From
Projects Directories with an e2e.config.{ts,mts,js,mjs}; a TypeScript one wins
Test files The config's tests, see below
Install root The nearest pnpm, npm, Yarn or Bun workspace root, else lockfile, else package.json
Package manager packageManager in the install root's package.json, else its lockfile, else npm. Yarn Plug'n'Play works
Install inputs Manifests, lockfiles, and what the install copies: file:, link: and injected packages. The whole source when an install script may read it, or with injectWorkspacePackages
Node version .nvmrc, .node-version, .tool-versions or Volta, else the module's own
Browsers What e2e doctor says the targets need
Targets All a Linux container can run: those on a local simulator, emulator, desktop or Electron are left out, and named in the run's output. Hosted devices and browsers run
App Per target: the wired service, app.command, or a deployed URL
Replay cache cache.dir, when committed
Reporters The config's

All but the test files come from e2e loading the config in the test container, so conditions, imports and environment variables count.

Test files

Keys are the files tests selects, by e2e's glob rules (! exclusions and dot directories included). Listing installs nothing and runs nothing of the project:

  • tests is read from the config's text when that settles it, which runs no container;
  • otherwise a pinned container evaluates the config's syntax: constants, spreads, conditions, process.env (as the environment setting has it) and relative imports;
  • when neither tells, such as for a preset from a package, every file named *.e2e.{ts,mts,tsx,js,mjs,jsx} is a key.

e2e has the last word. A key it does not run fails as did not run, and a failure in a file that is no key fails the project's other checks. Files git ignores, and empty ones, are not keys.

The wired service

e2e allows plain HTTP only for loopback hosts. So the service answers on the loopback port each target's local app.url names, whatever port it exposes, and on every port it exposes. app.command is not started for those targets. Targets with a deployed URL are left alone. A service reaching several backends can expose a port for each.

Checks and the shared run

Each selected test file is its own check. All of a project's checks share one run (or one per shard), and an indexer attributes its report.json:

  • a file fails with its own failures, serial members and suite hooks included;
  • a file whose tests were skipped because something they needed failed (a setup test, a hook, a run limit) fails as not verified;
  • a failure with no file to blame fails every file that did not fail itself;
  • a file whose every test the args filter out passes;
  • a key e2e reports no test from fails as did not run;
  • a file that does not load stops e2e, so it fails every file of its run.

The shared run's logs and spans are on whichever check started it.

Runs use e2e's CI mode: one retry, one worker, a read-only replay cache, no .only. Raise what you need with args. As with any Dagger function, an unchanged run is not repeated.

The workspace is mounted as a fresh checkout: without .git, node_modules, or anything git ignores. --changed-since needs git, so it does not work here.

Settings

Under [modules.e2e.settings] in dagger.toml, or as flags on dagger api call e2e. They apply to every project.

Setting Default
service none DAG address of the service under test
serviceHostname app hostname it is bound as
setup [] shell commands run in the project before the tests, such as a build app.command needs
targets detected target names to run, even ones left out by default
environment [] KEY=VALUE for the test containers
secrets, secretNames [] secrets set as variables, see below
args [] appended to every e2e run
reporters the config's built-in reporters to use instead
shards 1 parallel containers per project, sharing the service
browsers detected browsers to install
baseImageAddress node:<version>-bookworm image to run in
baseCtr none container to run in (wireable); needs Node and apt
packageManager detected npm, yarn, pnpm or bun
installFlags [] appended to the install command
beforeInstall [] shell commands run before the install
installInclude detected what the install reads beyond manifests and lockfiles
modelProvider, modelApiKey, model, modelEndpoint none the agent model, see below

Secrets

[modules.e2e.settings]
secrets = ["env://E2E_USER_ADMIN_PASSWORD", "op://ci/stripe/key"]
secretNames = ["", "E2E_SECRET_STRIPE_KEY"]

An env:// secret is set under its own name. Others need one in secretNames, at the same position. They are available to the config, the tests and setup, so only wire them for code you trust.

A package the install copies

pnpm copies injected workspace packages when it installs, so build them first:

[modules.e2e.settings]
installFlags = ["--filter", "web-e2e..."]
installInclude = ["packages/sdk/**"]
beforeInstall = ["pnpm --filter @acme/sdk install && pnpm --filter @acme/sdk build"]

Agent steps

The module can provide the model, whatever the provider:

[modules.e2e.settings]
modelProvider = "vercel"
modelApiKey = "env://E2E_MODEL_API_KEY"
Provider model
vercel, openrouter defaults to the one e2e init writes
openai, anthropic, google, xai required
openai-compatible required, with modelEndpoint (HTTPS, or loopback)

They are set as E2E_MODEL_PROVIDER, E2E_MODEL_API_KEY, E2E_MODEL and E2E_MODEL_ENDPOINT, and make the default agent's model unless the config gives it one. The key is also set as the provider's own variable, for a config that constructs its own model.

Replay cache

Take .e2e/cache/ out of .gitignore and commit it, and checks replay it. Recordings made outside Dagger replay here and the other way round, wired service or not: the module keeps the app identity they are keyed by.

Replaying calls no model, but e2e wants one configured: a modelProvider without a key is enough when everything replays. Add args = ["--strict-cache"] to fail on a stale recording rather than call the model.

Telemetry

The module runs each project with a generated config beside its own (e2e.dagger.config.*), which imports it and adds a reporter. The reporter uses e2e's public API, and sends the spans and logs Dagger's Playwright and Vitest modules do:

  • target (when there are several) › file › describe blocks › test › steps, test.step blocks included;
  • one span per test with its final outcome, and a retry #N span per retry;
  • a test's output and errors, as logs on its span.

Spans a test body creates itself are not under its span: e2e runs tests in worker processes and has no hook for that.

Not supported

Local simulators, emulators, macOS apps and Electron, which a Linux container cannot run, and --changed-since.

Development

dagger check runs the suite in .dagger/modules/e2e-dev, on fixtures/, with a fake model:

  • selected-* checks run the real dagger check on fixture workspaces, since only the CLI applies a selection: which files run, that a project's checks share one run, what each failure is attributed to, and that listing installs nothing;
  • telemetry checks compare the whole span tree a run exports;
  • the rest cover discovery, package managers, settings, services, shards, snapshots, the replay cache, and the oldest supported e2e.

The biome module checks the JavaScript; npx biome check --write fixes it. Format Dang with dang fmt -w main.dang .dagger/modules/e2e-dev/main.dang (Dang v2.5 or later). fixtures/*/server.mjs are copies of fixtures/server/server.mjs.

License

Apache-2.0

About

No description, website, or topics provided.

Resources

Code of conduct

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages