Skip to content

E2E Playwright harness

The root e2e/ directory hosts the End-to-End test suite for PerfShop: a cluster-level Playwright harness that drives the four IHMs (admin, scripts-ui, jmeter-ui, monitoring) in real Chromium against the Docker cluster.

Shipped in brique B1.E2E (CHANGELOG [1.7.0]).

Why an E2E harness?

The "Strict commercial production" mandate closed in 1.6.0 locked the cluster source / lint / build quality with 461 green source-pins (static assertions over the code). Those pins do not catch runtime invariants:

  • Does Escape actually close admin modals?
  • Is focus actually restored to the trigger button after close?
  • Does the strict CSP raise zero violation during real navigation?
  • Is /config.js served with the correct Content-Type?
  • Does any cross-origin resource leak at runtime?

The E2E harness proves these invariants for real.

Quick start

cd e2e/
npm install                            # installs Playwright + axe-core
./scripts/install-browsers.sh          # Linux/macOS — downloads ~150 MB Chromium
.\scripts\install-browsers.ps1         # Windows — equivalent

License pre-requisite (fresh instance only) — without an active license the backend returns 402 on POST /api/auth/login and the admin / scripts-ui / jmeter-ui smoke tests fail immediately. Activation is a one-time step; the key persists in the database through restarts.

# Start the cluster manually and wait for Spring boot (~30 s):
docker compose -f docker-compose.desktop.yml up -d
# Verify the backend responds, then activate:
curl -s -X POST http://localhost:9080/api/license/activate \
  -H "Content-Type: application/json" \
  -d '{"licenseKey": "PFSH-XXXX-XXXX-XXXX"}'
# → {"success":true,...} expected.

# Run the suite (cluster already up — skip autostart):
E2E_SKIP_COMPOSE_UP=1 npm test

On an already-activated instance (or in a fast dev loop):

npm test   # global-setup starts the compose automatically

npm test executes global-setup.ts which automatically runs docker compose -f docker-compose.desktop.yml up -d on the 5 required services (perfshop-app Spring backend + 4 IHMs), then polls each IHM for up to 60 seconds. The first "cold" run takes an extra ~30-60 s (Spring boot).

Harness layout

e2e/
├── playwright.config.ts      Chromium-only, fullyParallel: false
├── playwright.parcours.config.ts  interface journeys: one at a time, no artefact
├── global-setup.ts           docker compose up + waitForService × 4
├── package.json              @playwright/test + @axe-core/playwright
├── tsconfig.json             TS strict isolated to e2e/
├── fixtures/
│   ├── services.ts           SSOT URLs + login selectors per IHM
│   ├── auth.ts               loginAs(service) test fixture
│   ├── api-context.ts        apiFor(service) APIRequestContext
│   └── i18n.ts               loadI18n(svc, lang) + i18nValue(...)
├── helpers/
│   ├── docker.ts             waitForService + dockerComposeUp
│   ├── csp.ts                console.error + CSP violation collectors
│   ├── focus.ts              getFocusedId + waitForFocusedId (rAF-aware)
│   └── origins.ts            stackHosts + staysInStack ("stays inside the stack" oracle)
├── smoke/                    4 specs: 4 IHMs login → main → 0 error
├── a11y/                     4 specs: modals Escape + focus + axe-core
├── csp/                      1 spec: 0 cluster-wide violation
├── api/                      3 specs: config.js + headers + delete mock
├── offline/                  1 spec: 0 request outside the stack
├── parcours/                 TP interface journeys (directory, login, fixtures)
├── scripts/                  install-browsers.{sh,ps1}
└── test/
    ├── harness-present.test.js   node:test source-pin (no Chromium needed)
    ├── origins.test.js           node:test pin of the oracle (no Chromium needed)
    ├── parcours-structure.test.js  journey writing rules, local-address guard (no Chromium needed)
    ├── types.test.js             tsc -p tsconfig.json: no type error (no Chromium needed)
    ├── parcours-sans-fuite.test.js  no-leak witness for the accounts (Chromium)
    └── parcours-temoin/          the witness page and journey

Environment variables

Variable Default Effect
E2E_COMPOSE_FILE docker-compose.desktop.yml Compose file.
E2E_SKIP_COMPOSE_UP 0 If 1: skip docker compose up.
E2E_ADMIN_URL http://localhost:3004 Override admin URL.
E2E_SCRIPTS_URL http://localhost:3008 Override scripts-ui URL.
E2E_JMETER_URL http://localhost:3005 Override jmeter-ui URL.
E2E_MONITORING_URL http://localhost:3001 Override monitoring URL.
E2E_ADMIN_EMAIL admin@perfshop.fr Test account email.
E2E_ADMIN_PASSWORD perfshop Test account password.
CI unset If set: retries=1, traces on-first-retry.

Stack installed by build.sh

A stack installed by build.sh is reached by the host address, never by localhost: the installer writes that address into .env, and the backend only accepts it as an origin — a login attempted from http://localhost:3004 returns 403 "Invalid CORS request". This is intended: the instructor installs the stack on their machine and students connect to it from theirs. Point the harness at that address:

H=<host address>     # the one the installer summary announces
E2E_SKIP_COMPOSE_UP=1 E2E_ADMIN_URL=http://$H:3004 E2E_SCRIPTS_URL=http://$H:3008 \
  E2E_JMETER_URL=http://$H:3005 E2E_MONITORING_URL=http://$H:3001 \
  E2E_TEST_AI_URL=http://$H:3006 npm test

The offline/ oracle — "no request leaves the stack" — follows these addresses: the allowed hosts are those of the E2E_*_URL values (helpers/origins.ts), compared by name, never by prefix.

TP interface journeys

A second suite, e2e/parcours/, replays in a real browser the gestures the TPs ask of a student — from ANOTHER machine, through the host address (or its domain names). It starts from a single address, the welcome page, and reads there, as a student does, the address of each service and its accounts : none of this is written in the repository, and localhost is refused — like the loopback in any of its spellings (127.1, [::ffff:127.0.0.1], localhost., app.localhost) and Docker internal names.

cd e2e
E2E_WELCOME_URL=http://<host address>:3011 npm run test:parcours
File What it plays
00-accueil the directory : reachable addresses, services that answer, one account per service with a login
01-boutique catalogue, student login, cart, order (one order is created)
02-chaos student page : six tabs, scenario N1-01 switched on then off
03-scripts-ui "Runner ✓", "Pull Forgejo", a delivered Robot case run against the shop
04-jmeter-ui delivered plan, "External" default target (the public address of the API), short run, stop, report (deleted afterwards)
05-test-ai the system context announces the shop at the platform address
06-observabilite Grafana without an account ; Prometheus and Pyroscope, at the addresses of the welcome page
07-outils-qa Squash TM, Forgejo, Selenium grid desktop, documentation
08-partage-forgejo Forgejo package registry read without an account; a witness file uploaded with the "CI" account, downloaded without an account, then removed (heap dump TP)

Without logging in (a platform published on the Internet) : --grep-invert @connexion. Accounts read at run time never reach the screen nor a file — witness : npm run test:parcours:temoin. Full instructions, effects on the platform and limits : e2e/parcours/README.md (in French).

Architectural decisions

# Decision Choice
1 Layout e2e/ cluster-level (one harness for 4 IHMs)
2 Lang TypeScript isolated to e2e/ (runtime stays JS+JSDoc)
3 globalSetup docker compose up -d + 60 s healthcheck poll
4 Test account Pedagogical common admin admin@perfshop.fr / perfshop
5 Browsers Chromium-only at J0 (Firefox / WebKit → B1.E2E.bis)
6 Install Initial install with internet, runtime offline-ready

Spec conventions

  • i18n-safe selectors: [data-i18n=...], [role=dialog], [aria-label=...], [id=...]. Never text="..." (breaks in EN/FR).
  • No page.waitForTimeout(N) with an arbitrary value — use page.waitForResponse(...), locator.waitFor({ state: 'visible' }), or page.waitForFunction(...).
  • fullyParallel: false mandatory — Spring chaos-admin backend (1.5 GB heap, 1 cpu) saturates under parallel sessions.
  • Explicit error messages on every expect() — the 2-arg form expect(value, "custom explanation").toEqual(...) makes CI reports readable without seeing the page.

Extending the harness for a new IHM (B2, B3, B5, B8)

  1. fixtures/services.ts — add the ServiceDescriptor (URL + login selectors + mainReady). The type is a discriminated union on hasLogin: true | false, so TypeScript enforces completeness; it also enforces the service's entry in fixtures/i18n.ts (I18N_PATHS), and npm run test:harness runs tsc.
  2. global-setup.ts — add perfshop-<name> to COMPOSE_SERVICES and one waitForService(...) to the Promise.all.
  3. test/harness-present.test.js — extend the SPECS list and the service assertions.
  4. Create e2e/<brick>/<name>.spec.ts with the brick-specific specs reusing loginAs, apiFor, attachConsoleErrorCollector, etc.

Source-pin without Chromium

The four guards of test:harness run under plain node --test (no Chromium install required) — useful as a lite CI gate before the full Playwright run:

cd e2e/
npm run test:harness     # harness-present, origins, parcours-structure, types

origins.test.js judges the offline/ oracle by importing the production module helpers/origins.ts (Node strips the types by itself from versions 22.18 and 23.6 on, the floor of engines in e2e/package.json). parcours-structure.test.js judges the journeys' writing rules and the local-address guard, by importing parcours/annuaire.ts. types.test.js runs tsc -p tsconfig.json: Playwright and Node strip the types without checking them, so a type error stops no run; it only reports file(line,column) TSxxxx. The no-leak witness for the accounts opens Chromium: npm run test:parcours:temoin.

harness-present.test.js asserts: config + setup present, 4 fixtures + 4 helpers + 2 install scripts, 13 expected spec files, package.json declares Playwright + axe-core, Chromium-only, fullyParallel: false, global-setup references the 5 services + polls the 4 IHMs, services.ts declares the two login conventions (admin kebab-case vs scripts/jmeter camelCase).

Explicit backlog

  • Firefox + WebKit cross-browser: separate brique B1.E2E.bis if a specific need arises (rendering edge bug, Safari validation).
  • Express route supertest (former D.1.bis backlog): superseded by this runtime brique. Adding supertest is out of scope unless a specific need emerges.

References

  • Code: e2e/ at the repo root.
  • README: e2e/README.md.
  • Acquired patterns: memory/reference/pattern_node_ihm.md #27-30 (to copy) + #54-57 (NOT to reproduce).
  • CHANGELOG: entry [1.7.0].