Browser end-to-end kit
An application with a web/ single-page application tests it in a real browser against its real
backend: Playwright drives Chromium, the backend is the application itself on a real PostgreSQL and a
test sign-in provider, and the strict Content Security Policy is on. The kit is the part of that which
does not depend on the application. It has two halves:
| Half | Where | What it gives |
|---|---|---|
| Java | E2eLauncher in the framework-auth test-jar |
the test OIDC provider with your client registered, the standard control endpoints, the READY handshake, orderly shutdown |
| TypeScript | @flowcatalyst/ui/e2e (ui/packages/ui/src/e2e) |
defineE2eConfig, the CSP monitor (test), the control client, openPage, fetchJson, axeViolations |
The orders demo (ui/apps/orders, with OrdersE2e on the Java side) and the tickets service are the
two users and the proof; the component gallery uses the CSP monitor and the axe helper without a
backend. Nothing here touches a developer’s database or port 8080: the ports are the ones you choose,
the database is a container (or an embedded server in Go) and the platform is a fake.
The kit is not published. It lives in the framework repository and is consumed from a checkout with a
link: dependency like the rest of @flowcatalyst/ui.
Adding it to an application: five steps
Section titled “Adding it to an application: five steps”1. The package script (in the application’s package.json; the kit needs @playwright/test and
@axe-core/playwright as dev dependencies, the peer dependencies of @flowcatalyst/ui):
"e2e": "vite build && node node_modules/@flowcatalyst/ui/src/e2e/cli.ts playwright test"vite build writes the SPA into the module’s web/dist; Maven copies it into the classes, so the
backend serves the build you just made.
Run Playwright through the kit, not through your own playwright binary. The kit imports
@playwright/test; consumed with link: it resolves that import from the framework checkout, while the
application’s node_modules/.bin/playwright is the application’s own copy. Two copies in one process
fail with did not expect test.beforeEach() to be called here. The kit therefore ships a runner that
starts the Playwright CLI from the copy it resolves itself and passes every argument through. Any
Playwright subcommand works the same way (... cli.ts playwright test --headed -g "list",
... cli.ts playwright show-trace trace.zip); the exit code is the CLI’s. In code: playwrightCliPath()
and runPlaywright(args) from @flowcatalyst/ui/e2e.
2. The configuration (playwright.config.ts). The two ports are yours and must be free of 8080,
15432 and the other applications’ (the orders demo uses 4392 and 4393). The Go orders suite
(make e2e-orders) uses the same 4392 and 4393 as the Java one, so the two cannot run at the same time;
run one, then the other:
import { defineE2eConfig } from "@flowcatalyst/ui/e2e";
export default defineE2eConfig({ port: 4392, control: 4393, backend: { module: "examples/orders-demo", mainClass: "io.flowcatalyst.framework.examples.ordersdemo.OrdersE2e" },});It sets one worker (the tests share one database), a 30 s test timeout (timeout changes it),
Chromium, a trace kept on failure, and the web server: the kit’s command builds the module and what it
needs with ./mvnw test-compile (set MAVEN_ARGS=-o to build offline), writes the test classpath, runs
the launcher and waits for GET /control/ready on the control port for up to five minutes. It also puts
the control port in FC_E2E_CONTROL_PORT for the fixtures.
3. The launcher (a class with main in the application’s test sources, so the test-jars are on its
classpath). OrdersE2e is the model:
E2eLauncher e2e = E2eLauncher.start(args, "orders-web");PostgresFixture pg = e2e.own(PostgresFixture.start());FakePlatform platform = e2e.own(DemoPlatform.start());e2e.signInAs(E2eLauncher.person("orders-demo:clerk", "Ada Lovelace"));
Map<String, String> env = e2e.environment();env.put("DATABASE_INSTANCES_MAIN_URL", pg.jdbcUrl());// ... the application's own entriese2e.own(OrdersWeb.builder(...).configDirectory(Path.of("config")).environment(env).start());
e2e.endSessions(() -> pg.execute("DELETE FROM fw_session")) .control("/control/reset", q -> { pg.execute("TRUNCATE order_lines, orders, outbox_messages CASCADE"); return "ok"; }) .serve();start(args, clientId)reads<app-port> <control-port> [<public-origin>], starts the provider, registers the client with the redirect<origin>/auth/callback. The provider’s own end-session endpoint (on its origin, as the contract requires) answers302to thepost_logout_redirect_uriwhen it is on the registered client’s origin, so sign-out lands on the SPA’s/signed-out. A third argument is the origin the browser sees when something else fronts the backend (the Vite dev server).start(args, clientId, clock)makes the provider follow a clock your suite moves (the tickets suite does, and passes the same clock to itsApp).environment()returns a fresh map withAPP_ENV=test,HTTP_HOST,HTTP_PORT,AUTH_ISSUER,AUTH_CLIENT_ID,AUTH_CLIENT_SECRET(blank) andAUTH_PUBLIC_BASE_URL; add the database, platform and other entries. The blank secret keeps the run independent of the developer’s machine: the kit’s login client is public, butAPP_ENV=teststill readsconfig/secrets.local.yaml, and a realauth.client-secretthere would make it a confidential client and fail every sign-in (LOGIN_FAILED). An environment variable beats every file, and a blankauth.client-secretmeans a public client (Sessions and login), so the file’s secret never reaches the run. An application that builds its environment withoutenvironment()setsAUTH_CLIENT_SECRETto the empty string itself, as the Go launchers do.own(resource)hands over what must be closed on shutdown (the database fixture, fakes, theApp); they are closed last first, then the provider.control(path, handler)registers your endpoint under/control/. The handler gets the decoded query and returns the body of the200; an exception becomes a500whose body is its message, which the TypeScript client puts in its error. Any method is accepted.serve()starts the control server, printsREADYand waits; the JVM’s shutdown hook closes everything.
4. The fixtures (e2e/fixtures.ts): re-export what the specs use and add the application’s roles
and helpers.
import { control, expect, fetchJson, openPage, signInAs as signIn, test } from "@flowcatalyst/ui/e2e";
export { control, expect, fetchJson, openPage, test };export const CLERK = "orders-demo:clerk";
export async function signInAs(...roles: string[]): Promise<void> { await signIn({ roles });}
export async function freshData(): Promise<void> { await control("/control/reset"); await signInAs(CLERK);}5. A spec. Every test gets the CSP monitor automatically (the csp fixture); await csp.expectClean() asserts no violation, no console message about the policy, no request to another
origin and no uncaught page error. Strict axe is one call:
import { axeViolations } from "@flowcatalyst/ui/e2e";import { expect, freshData, openPage, test } from "./fixtures.ts";
test("the list is accessible", async ({ page, csp }) => { await freshData(); await openPage(page, "/orders", "Orders"); expect(await axeViolations(page)).toEqual([]); await csp.expectClean();});The standard control endpoints
Section titled “The standard control endpoints”Served by E2eLauncher for every application (the TypeScript names are in @flowcatalyst/ui/e2e):
| Endpoint | Effect | TypeScript |
|---|---|---|
/control/ready |
200 ready; the web server’s probe |
(used by defineE2eConfig) |
/control/sign-in-as?roles=a,b&name=&client=&sub= |
the next sign-in is that person; with neither client nor sub, a person of no client (E2eLauncher.person(roles, name)), otherwise one client’s user (person(roles, name, client, sub)) |
signInAs({ roles, name, client, sub }), switchTo(page, who) |
/control/provider-down?value=true |
the provider answers 503 | providerDown(true) |
/control/authorize-error?value=access_denied |
the provider refuses the next sign-ins (empty value: normal) | authorizeError(code) |
/control/end-sessions |
registered by endSessions(action): delete every session, as an expiry would |
endSessions() |
Everything else (truncate and seed, moving a clock, playing the platform’s part) is the application’s
own, registered with control(...) and called with control(path) (control(path, "GET") for a read).
The CSP monitor
Section titled “The CSP monitor”test is Playwright’s test with an automatic csp fixture, installed before any page script runs. A
request to another origin is a failure, except the top-level navigation to the loopback sign-in
provider, which the round trip needs. createTest() builds the strict variant for an application with
no backend (the gallery: no request may leave its origin at all). The pure part, isForeignRequest, is
unit-tested.
On the Go framework
Section titled “On the Go framework”The TypeScript half is the same; the backend half is a subcommand of the application. The Go orders
demo runs orders-demo e2e <app-port> <control-port> [--dist <dir>] [<public-origin>] (embedded
PostgreSQL, the Go test identity provider authtest.Provider, the standard control endpoints and the
orders’ own), and its Playwright configuration
(go/examples/orders-demo/e2e/playwright.config.ts) is defineE2eConfig with the web server replaced by
that command, which sets AUTH_CLIENT_SECRET to the empty string in its environment for the reason
given above. make -C go e2e-orders builds the SPA and the launcher and runs the shared orders suite
against it. See also Testing.
What is tested, and what is not
Section titled “What is tested, and what is not”The kit’s own tests are unit tests: E2eLauncherTest (the endpoints over a real socket, the claims,
closing order) and ui/packages/ui/test/e2e-kit.test.ts (the configuration, the control client, the
monitor’s classifier, the Maven and Java commands). The integration proof is the orders and tickets
suites, which run on the kit.
Not covered: browsers other than Chromium, a real platform, more than one worker, and publishing: the Java side is used by an application that builds in the framework repository (an application elsewhere needs the framework installed and its own copy of the launcher’s test-jar dependencies).