[data-reveal]{opacity:1!important;transform:none!important}
AntelopeJS DMS
DocumentationTest your module end to end

Test your module end to end

Set up a Playwright suite on the DMS e2e kit, write journeys and specs against a real playground, and run the suite locally and in CI.

The e2e kit of @antelopejs/dms runs your playground for a Playwright suite. Before the tests, it starts one run per worker: a copy of the playground on free ports, its own MongoDB, a mail sink and the built dashboard. Each test gets a fresh database and an onboarded administrator. The E2E kit reference lists every option, fixture and environment variable this guide uses.

You need a module with a playground project. Each run starts a mongod: the one that DMS_E2E_MONGOD names, else the one on your PATH, else the one that mongodb-memory-server-core downloads when your project installs that package.

Install the kit

  1. Add @playwright/test as a devDependency, on the same line as the playwright-core that your @antelopejs/dms resolves. For @antelopejs/dms 0.25, that is ~1.65.0.
  2. Add the script that runs the suite to package.json:
    package.json json
    {
        "scripts": {
            "e2e": "playwright test -c e2e"
        }
    }
    
  3. Add e2e/tsconfig.json, so that your editor checks the specs and reads the journeys:
    e2e/tsconfig.json json
    {
        "compilerOptions": {
            "module": "nodenext",
            "moduleResolution": "nodenext",
            "allowJs": true,
            "noEmit": true
        },
        "include": ["*.ts", "**/*.mjs"]
    }
    

Declare the suite

  1. Declare the playground and the commands that build it in e2e/journeys.config.ts. Paths are relative to the repository root.
    e2e/journeys.config.ts ts
    import type { JourneysConfig } from "@antelopejs/dms/e2e";
    
    export default {
        playground: "playground",
        prepare: [
            ["pnpm", "install", "--frozen-lockfile", "--prefer-offline", "--ignore-scripts"],
            ["pnpm", "build"],
            ["pnpm", "--dir", "playground", "build"],
        ],
        smoke: "smoke",
    } satisfies JourneysConfig;
    
  2. Build the Playwright config from e2eConfig():
    e2e/playwright.config.ts ts
    import { e2eConfig } from "@antelopejs/dms/e2e";
    
    export default e2eConfig();
    
  3. Register the journeys in a spec file whose name sorts after every other spec:
    e2e/zz-journeys.spec.ts ts
    import { registerJourneys } from "@antelopejs/dms/e2e";
    
    await registerJourneys();
    

    A journey marked last changes the playground of its worker's run. A spec that runs after it on that worker cannot start its backend, so the journeys file must sort last.

Write a journey

A journey is an object that declares one test: its name, how to prepare the run, and a run function. Each *.mjs file in e2e/journeys/ is a feature named after the file, and it exports a journeys array. Put the helpers that journeys import in a subfolder of e2e/journeys/ or elsewhere in e2e/.

e2e/journeys/smoke.mjs js
/** @typedef {import("@antelopejs/dms/e2e").Ctx} Ctx */

export const journeys = [
    {
        id: "smoke",
        tag: "@smoke",
        title: "the administrator signs in and opens the members page",
        entryPoint: "the sign-in form, then Settings > Members",
        async run(/** @type {Ctx} */ ctx) {
            const tab = await ctx.tab("admin");
            await tab.signIn("admin");
            await tab.goto("/settings/workspace/members");
            await ctx.verify("the members page lists the administrator", [
                tab.visible({ role: "heading", name: "Members", exact: true }),
            ]);
            const answer = await ctx.api("read the onboarding state", {
                method: "GET",
                path: "/api/onboarding/informations",
            });
            await ctx.verify("the platform is onboarded", [
                ctx.status(answer, 200),
                ctx.equal("has_onboarded", answer.body?.has_onboarded, true),
            ]);
        },
    },
];

Each ctx.verify call records a step with its checks, a screenshot and the evidence of the failing checks. The journey runs on a fresh database with an onboarded administrator unless its fields say otherwise.

Write a spec

Write a plain Playwright spec when a journey does not fit. Import test and expect from the kit, not from @playwright/test.

e2e/members.spec.ts ts
import { expect, test } from "@antelopejs/dms/e2e";

test("the administrator opens the members page", async ({ adminPage }) => {
    await adminPage.goto("/settings/workspace/members");
    await expect(adminPage.getByRole("heading", { name: "Members", exact: true })).toBeVisible();
});

Use adminPage or dms when the test needs a fresh database. Playwright's own page opens the dashboard on the database that the previous test left.

To prepare a spec as a journey's fields would, set dmsOptions:

e2e/members.spec.ts ts
test.use({ dmsOptions: { onboard: false } });

Run the suite

Run the whole suite:

terminal
pnpm e2e

Run only the smoke journeys:

terminal
pnpm e2e --grep @smoke

The first run installs and builds the playground with the prepare commands. To skip them on a checkout that an earlier run prepared, set DMS_E2E_PREBUILT=1.

The suite runs on two workers. Each worker gets its own run, so each extra worker costs a playground copy, a MongoDB and a dashboard. On a machine with more cores and memory, set DMS_E2E_WORKERS:

terminal
DMS_E2E_WORKERS=4 pnpm e2e

After a failure, open the evidence folder that the test report names. It holds the screenshot and ARIA snapshot of each step, and the backend log.

Test the development dashboard

Some UI renders only under import.meta.env.DEV. To test it, run a second suite on the development dashboard.

  1. Give each journey that needs the development dashboard frontend: "dev". The default suite leaves these journeys out.
  2. Add a second Playwright config:
    e2e/playwright.dev.config.ts ts
    import { e2eConfig } from "@antelopejs/dms/e2e";
    
    export default e2eConfig({ frontend: "dev" });
    
  3. Run it:
    terminal
    pnpm exec playwright test -c e2e/playwright.dev.config.ts
    

Keep a failing check visible

If a journey fails today because of a known product bug, do not skip it. Map the name of each failing check to the bug in knownFailures:

e2e/journeys/members.mjs js
knownFailures: {
    "the invitation is listed": "https://github.com/acme/my-module/issues/42",
},

The journey passes while the check fails. Once the check passes, the journey fails until you remove the entry.

If a journey changes the playground for the backends that start after it, set last: true.

Mock an outside API

If your module calls an outside API, start a mock of it with Playwright's webServer. Every worker shares that one server, so run the suite on one worker:

e2e/playwright.config.ts ts
import { defineConfig } from "@playwright/test";
import { e2eConfig } from "@antelopejs/dms/e2e";

export default defineConfig(e2eConfig(), {
    workers: 1,
    webServer: { command: "node e2e/mock-api.mjs", port: 4010 },
});

Test without Playwright

To test a CLI or an HTTP client with node:test, start the same run with startRun from @antelopejs/dms/e2e/run. It does not load Playwright.

test/cli.test.mjs js
import assert from "node:assert/strict";
import { after, before, test } from "node:test";
import { apiRequest, onboard, startRun } from "@antelopejs/dms/e2e/run";

/** @type {Awaited<ReturnType<typeof startRun>>} */
let started;
before(async () => {
    started = await startRun();
    await onboard(started.run, {});
});
after(() => started?.stop());

test("the administrator reads the onboarding state", async () => {
    const answer = await apiRequest(started.run, {
        method: "GET",
        path: "/api/onboarding/informations",
        as: "admin",
    });
    assert.deepEqual(answer.body, { has_onboarded: true });
});

Point your CLI or client at started.run.apiUrl for the backend, or at started.run.webUrl for the dashboard.

Run the suite in CI

Start from the e2e.yml workflow of the DMS repository and the e2e job of its ci.yml, which calls it.

  1. On a pull request, run pnpm e2e --grep @smoke. Tag about five fast journeys @smoke, the smoke feature's journey first. Leave out journeys that need frontend: "dev", standby: false, backend: "watch" or ctx.withBaseBackend.
  2. In the merge queue and on a schedule, run the whole suite in shards: pnpm e2e --shard=i/N --add-reporter=blob. Choose N so that one shard finishes in about 30 minutes.
  3. Merge the shards' blob reports into one HTML report in a final job.
  4. Run the development config in the same job, after the default config.

Move a suite off verify.config.ts

The kit reads only e2e/journeys.config.ts, or the file that the config option names. e2eConfig refuses the old skill option. If your suite still reads a verify skill's verify.config.ts, move it before you upgrade:

  1. Copy its playground, renderer, prepare and smoke keys into e2e/journeys.config.ts.
  2. Move its journeys to e2e/journeys/.
  3. If the playground lives in the skill folder, move it to e2e/.
  4. Remove skill from the e2eConfig call.