E2E kit
The exports of the DMS e2e kit, the journeys config, the journey fields, the fixtures, the workers, retries and shards, and the environment variables.
The e2e kit runs a DMS playground for Playwright tests and for any other test runner. Test your module end to end shows how to set up a suite.
Exports
| Import | Export | What it is |
|---|---|---|
@antelopejs/dms/e2e | e2eConfig(options?) | The Playwright config of a suite |
@antelopejs/dms/e2e | registerJourneys() | Registers one test per journey of the suite |
@antelopejs/dms/e2e | test, expect | Playwright's test with the kit's fixtures, and Playwright's expect |
@antelopejs/dms/e2e | JourneysConfig, Journey, Ctx, Tab, Check, SuiteOptions | Types of the journeys config, a journey, the journey context, a tab, a check and the options of e2eConfig |
@antelopejs/dms/e2e/run | startRun(options?) | Starts a run without Playwright |
@antelopejs/dms/e2e/run | onboard, apiRequest, runJourney, freshDatabase, restartBackend, capturedMail, loadRun, saveRun | Drive a run that startRun started |
@antelopejs/dms/e2e needs @playwright/test, an optional peer dependency. @antelopejs/dms/e2e/run loads no Playwright.
The journeys config
The default export of e2e/journeys.config.ts, typed JourneysConfig.
| Key | Type | Required | Description |
|---|---|---|---|
playground | string | Yes | The playground folder, relative to the repository root, or absolute for a playground in another checkout |
prepare | string[][] | Yes | The install and build commands that run before the runs start, each as a program and its arguments, run from the repository root with CI=1 |
smoke | string | Yes | The feature whose journeys run first |
renderer | string | No | The built @antelopejs/dms-frontend checkout that the run serves, for the renderer's own repository. Without it, the run serves the renderer that the playground installs |
The features of the suite are the *.mjs files of the journeys/ folder beside the config, each named after its file, in alphabetical order. Subfolders hold helpers and are not features.
Suite options
e2eConfig(options) takes these options. startRun(options) takes them too, with prepare. registerJourneys() reads them from the config that loaded it.
| Option | Type | Default | Description |
|---|---|---|---|
config | string | "e2e/journeys.config.ts" | A journeys config file, relative to the repository root. Its journeys are the *.mjs files of journeys/ beside it. Use it for a second suite, such as e2eConfig({ config: "e2e/builder/journeys.config.ts" }) |
frontend | "dev" | Unset | Serves the dashboard with ajs dms dev instead of a build, and runs only the journeys that set frontend: "dev". Without it, the suite serves a build and leaves those journeys out |
e2eConfig refuses any other key, and a config that names no file.
The returned Playwright config
e2eConfig() returns a plain Playwright config. Change any key with defineConfig(e2eConfig(), overrides) from @playwright/test.
| Key | Value |
|---|---|
testDir | ".", the folder of the config |
testMatch | Files that end in .spec.ts |
outputDir | test-results, or test-results-dev with frontend: "dev" |
fullyParallel | true |
workers | 1 with DMS_E2E_RUN, else DMS_E2E_WORKERS, else 2 |
retries | 1 |
forbidOnly | true when CI is set |
timeout | 15 minutes |
globalSetup | The kit's global setup, which starts the runs |
reporter | list. When CI is set, list, github, html in playwright-report and json in playwright-report/results.json. The report folder ends in -dev with frontend: "dev" |
use.trace | "retain-on-failure" |
projects | One project, chromium |
Journey fields
A feature file exports journeys, an array of objects with these fields.
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Yes | The test name, unique across the suite |
title | string | Yes | What the journey proves, shown as an annotation |
entryPoint | string | Yes | Where the user starts, shown as an annotation |
run | (ctx: Ctx) => Promise<void> | Yes | The body of the journey |
tag | string | string[] | No | Playwright tags in @kebab-case, such as @smoke |
knownFailures | Record<string, string> | No | The name of each check that fails today, mapped to the finding that makes it fail. A listed check that fails does not fail the journey. A listed check that passes does |
last | boolean | No | Runs the journey after every other journey, for a journey that changes the run's playground for later backends |
frontend | "dev" | No | Runs the journey only in a frontend: "dev" suite, for UI that only import.meta.env.DEV renders |
database | string | No | "shared" keeps the database of the previous test. By default the journey gets a fresh database with a backend of its own |
onboard | boolean | No | false skips the onboarded administrator. Defaults to true |
backend | "production" | "dev" | "watch" | No | How the backend of the fresh database runs: ajs project start on the build, ajs project dev, or ajs project dev -w. Not allowed with database: "shared" |
standby | boolean | No | false starts a backend for the journey instead of the one booted ahead, and boots none ahead while it runs. Not allowed with database: "shared" |
The journey context
The ctx argument of a journey's run, and the dms fixture of a spec. Its evidence goes to <run>/evidence/<feature>/<journey>/.
| Member | Description |
|---|---|
tab(account?, label?) | Opens a tab as an account of the run, or as anon, in that account's own browser context |
api(label, { method, path, body?, as?, token? }) | Calls the backend as as (admin by default, another account, or anon), or with token, and records the request and the answer |
concurrent(label, requests) | Sends anonymous requests at the same time, for races |
verify(label, checks, { critical? }) | Records a step and its checks, which may be promises. With critical: true, a failure ends the journey |
mail(accept, timeoutMs?) | Waits up to 15 seconds by default for a captured message that accept matches. Returns { folder, messages, match }, where match is the latest match |
email(name) | An address unique to the run and the journey, which the mail sink receives |
unique(prefix) | A string unique to the journey |
addAccount(name, credentials) | Adds an account that the journey created, so that tab and api can act as it |
onboard(options?) | Creates and signs in the administrator, for a journey with onboard: false |
restartBackend() | Restarts the backend on the same database |
stopDatabase(), startDatabase() | Stops and starts the run's mongod at the same URL with the same data |
withBaseBackend(action) | Runs action against the backend of the base version on the same database, then the run's backend again |
status(answer, expected) | A check that an answer has the HTTP status expected |
equal(name, actual, expected) | A check that two values are equal |
holds(name, pass, detail) | A check that a condition holds, with what was observed |
Tabs
ctx.tab() returns a Tab. A target is { role, name?, exact?, nth?, within? }, matched by ARIA role and accessible name.
| Method | Description |
|---|---|
signIn(account) | Signs an account of the journey in through the sign-in form |
goto(path), reload() | Opens a dashboard path, or reloads the page |
click(target), fill(target, value), select(target, value), check(target), press(key, target) | Act on a target |
visible(target, { hidden?, timeoutMs? }) | A check that a target becomes visible, or hidden with hidden: true |
enabled(target, { disabled? }) | A check that a target is enabled, or disabled with disabled: true |
shows(pattern, { not? }) | A check that the page shows text that matches pattern, or never shows it with not: true |
at(pattern) | A check that the path matches pattern |
count(target, expected) | A check that expected elements match a target |
value(target) | The value of a form field |
locator(target) | The Playwright locator of a target |
snapshot(label) | Records the page as it is now, with a screenshot |
close() | Closes the tab |
Fixtures
test from @antelopejs/dms/e2e adds these fixtures to Playwright's own.
| Fixture | Scope | Description |
|---|---|---|
run | Worker | The run that the global setup started for the worker: its webUrl, apiUrl, accounts and evidence folder |
baseURL | Test | The run's dashboard, so page.goto("/settings") opens it |
dms | Test | The journey context of the test, prepared as dmsOptions says. After the test, it closes the tabs, judges the verify steps and replays them into the report. A test whose preparation fails does not run |
adminPage | Test | A tab of dms that the administrator signed in on |
dmsOptions | Option | The database, onboard, backend, standby and knownFailures fields of a journey, set with test.use({ dmsOptions }) |
A failing step attaches its screenshot and ARIA snapshot to the report. A failed test attaches the backend log and names its evidence folder. Playwright's page uses the database of the previous test.
Order of the tests
registerJourneys() registers the journeys of the smoke feature first, then the other features in alphabetical order, then every journey marked last. With DMS_E2E_SHUFFLE, the journeys not marked last run in an order drawn from the seed.
Each worker runs its tests one at a time, and takes the next test in order. Spec files run in alphabetical order. A spec that runs after a last journey on the same worker cannot start its backend.
Workers and runs
The global setup starts one run for each worker. A run is a copy of the playground on free ports, with its own MongoDB, mail sink, backends and dashboard. The setup stops every run after the last test.
DMS_E2E_WORKERSand--workers=Nset the number of runs.--workersand aworkerskey in the config take precedence overDMS_E2E_WORKERS.- With
DMS_E2E_RUN, the suite runs on one worker against that run, and stops nothing. - A config with a
webServermust setworkers: 1. The global setup refuses more workers, because they would share the server. - Each test on a fresh database gets a backend that served nothing else. The run boots that backend while the previous test runs, so a test waits only when the previous test was shorter than a backend boot.
standby: falseandDMS_E2E_NO_STANDBY=1turn this off. - A backend counts as ready once it answers
/api/onboarding/informationsand itsdefaulttenant is provisioned, so a test never starts before the tenant's setup has run.
Retries
Playwright retries a failed test once, on every event: local runs, push, pull_request and merge_group. A test that passes on its retry is reported as flaky. Fix a flaky test: find what it waits on, and wait on that instead of on the retry.
Shards
--shard=i/N splits the suite across N machines. Each machine starts its own runs. Add --add-reporter=blob to keep the config's reporters and write a blob report, then merge the blob reports with playwright merge-reports.
The kit cuts the shards by recorded seconds, not by count. It reads test-weights.json beside the journeys config, a JSON object of seconds per test, and gives each shard a contiguous run of about equal seconds. Without that file every test counts as one second, so the shards have equal counts. A test missing from the file counts as the median of the others.
DMS_E2E_DURATIONSis a file path. The run writes there the seconds each of its tests took. Upload that file from each shard.node node_modules/@antelopejs/dms/e2e/weights.mjs <weights-out> <durations.json>...writes the mean of the durations files it is given to<weights-out>. Point it attest-weights.jsonafter a few runs.DMS_E2E_FIRST_SHARD_EXTRAis the seconds shard 1 spends on other work after the suite. Shard 1 takes fewer tests by that much on each worker.
Runs without Playwright
startRun(options?) starts one run, as the global setup does. It takes config and frontend as e2eConfig does, and prepare, which runs the config's prepare commands. prepare defaults to true, or false with DMS_E2E_PREBUILT=1. It returns { run, stop }. stop() stops every process that the run started, and keeps its evidence/ and logs/ folders. A SIGINT or SIGTERM to the test process also stops the run.
| Helper | Description |
|---|---|
onboard(run, { platformName? }) | Creates the administrator through POST /api/onboarding/register, then signs it in |
apiRequest(run, { method, path, body?, as }) | Calls the backend as admin, another account of run.accounts, or anon. Signs the account in again once if its token is refused. Records the request and the answer in the run's evidence/ folder. Returns { status, body, error, folder } |
runJourney(run, feature, journey) | Runs one journey without a browser and returns the judged result. A ctx.tab() call fails the journey |
freshDatabase(run, suffix, { backend?, standby? }) | Switches the run to a new database with a backend of its own |
restartBackend(run) | Restarts the backend on the same database |
capturedMail(run.mail) | The messages the mail sink captured, oldest first |
loadRun(dir), saveRun(run) | Read and write the state of a run in its folder |
Environment variables
| Variable | Description |
|---|---|
DMS_E2E_WORKERS | The number of workers, a positive integer. Defaults to 2. Any other value fails the config |
DMS_E2E_RUN | The folder of a running run, such as the dir of a run that startRun started. The suite runs on one worker against it and stops nothing. The setup refuses a run whose dashboard is not served as the suite asks |
DMS_E2E_PREBUILT | 1 skips the prepare commands, for a checkout that an earlier run prepared |
DMS_E2E_RUNS | The folder that holds the run folders. Defaults to dms-e2e in the system temporary folder. A run takes a few hundred megabytes, so prefer a folder on disk over a tmpfs |
DMS_E2E_NO_STANDBY | 1 starts the backend of each fresh database when the test needs it, instead of one booted ahead |
DMS_E2E_SHUFFLE | A seed. The journeys not marked last run in an order drawn from it, the same order for the same seed. A suite that passes under several seeds has no journey that depends on the state another one left |
DMS_E2E_DURATIONS | A file path. The run writes there the seconds each test took, for the weights.mjs command that rewrites test-weights.json |
DMS_E2E_FIRST_SHARD_EXTRA | Seconds of other work that shard 1 does after the suite. Shard 1 takes fewer tests by that much on each worker. Any other value fails the run |
DMS_E2E_MONGOD | The mongod binary that each run starts. Without it, the kit runs the mongod on PATH, else the one that mongodb-memory-server-core downloads |