[data-reveal]{opacity:1!important;transform:none!important}
AntelopeJS DMS
DocumentationE2E kit

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

ImportExportWhat it is
@antelopejs/dms/e2ee2eConfig(options?)The Playwright config of a suite
@antelopejs/dms/e2eregisterJourneys()Registers one test per journey of the suite
@antelopejs/dms/e2etest, expectPlaywright's test with the kit's fixtures, and Playwright's expect
@antelopejs/dms/e2eJourneysConfig, Journey, Ctx, Tab, Check, SuiteOptionsTypes of the journeys config, a journey, the journey context, a tab, a check and the options of e2eConfig
@antelopejs/dms/e2e/runstartRun(options?)Starts a run without Playwright
@antelopejs/dms/e2e/runonboard, apiRequest, runJourney, freshDatabase, restartBackend, capturedMail, loadRun, saveRunDrive 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.

KeyTypeRequiredDescription
playgroundstringYesThe playground folder, relative to the repository root, or absolute for a playground in another checkout
preparestring[][]YesThe 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
smokestringYesThe feature whose journeys run first
rendererstringNoThe 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.

OptionTypeDefaultDescription
configstring"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"UnsetServes 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.

KeyValue
testDir".", the folder of the config
testMatchFiles that end in .spec.ts
outputDirtest-results, or test-results-dev with frontend: "dev"
fullyParalleltrue
workers1 with DMS_E2E_RUN, else DMS_E2E_WORKERS, else 2
retries1
forbidOnlytrue when CI is set
timeout15 minutes
globalSetupThe kit's global setup, which starts the runs
reporterlist. 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"
projectsOne project, chromium

Journey fields

A feature file exports journeys, an array of objects with these fields.

FieldTypeRequiredDescription
idstringYesThe test name, unique across the suite
titlestringYesWhat the journey proves, shown as an annotation
entryPointstringYesWhere the user starts, shown as an annotation
run(ctx: Ctx) => Promise<void>YesThe body of the journey
tagstring | string[]NoPlaywright tags in @kebab-case, such as @smoke
knownFailuresRecord<string, string>NoThe 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
lastbooleanNoRuns the journey after every other journey, for a journey that changes the run's playground for later backends
frontend"dev"NoRuns the journey only in a frontend: "dev" suite, for UI that only import.meta.env.DEV renders
databasestringNo"shared" keeps the database of the previous test. By default the journey gets a fresh database with a backend of its own
onboardbooleanNofalse skips the onboarded administrator. Defaults to true
backend"production" | "dev" | "watch"NoHow 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"
standbybooleanNofalse 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>/.

MemberDescription
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.

MethodDescription
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.

FixtureScopeDescription
runWorkerThe run that the global setup started for the worker: its webUrl, apiUrl, accounts and evidence folder
baseURLTestThe run's dashboard, so page.goto("/settings") opens it
dmsTestThe 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
adminPageTestA tab of dms that the administrator signed in on
dmsOptionsOptionThe 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_WORKERS and --workers=N set the number of runs. --workers and a workers key in the config take precedence over DMS_E2E_WORKERS.
  • With DMS_E2E_RUN, the suite runs on one worker against that run, and stops nothing.
  • A config with a webServer must set workers: 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: false and DMS_E2E_NO_STANDBY=1 turn this off.
  • A backend counts as ready once it answers /api/onboarding/informations and its default tenant 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_DURATIONS is 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 at test-weights.json after a few runs.
  • DMS_E2E_FIRST_SHARD_EXTRA is 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.

HelperDescription
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

VariableDescription
DMS_E2E_WORKERSThe number of workers, a positive integer. Defaults to 2. Any other value fails the config
DMS_E2E_RUNThe 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_PREBUILT1 skips the prepare commands, for a checkout that an earlier run prepared
DMS_E2E_RUNSThe 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_STANDBY1 starts the backend of each fresh database when the test needs it, instead of one booted ahead
DMS_E2E_SHUFFLEA 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_DURATIONSA 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_EXTRASeconds 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_MONGODThe mongod binary that each run starts. Without it, the kit runs the mongod on PATH, else the one that mongodb-memory-server-core downloads