Files
romm/frontend/e2e/auth.setup.ts
Georges-Antoine Assi 9e5582230d Sign in once per role instead of per test
Every spec drove the login form, which is 15 UI logins to test something
login.spec.ts can cover on its own.

auth.setup.ts now runs first as its own project, logs each fixture user in
once and saves the session (cookies plus localStorage) to playwright/.auth/.
Specs pick an identity with `test.use({ storageState })` and start signed in.
That is preferred over building a context by hand, which would silently drop
the project's options -- baseURL, the blocked service worker, viewport.

login.spec.ts is the one place the form is exercised, on a deliberately
unauthenticated page, and it gained cover the suite never had: a rejected
password and the redirect for an anonymous visitor.

Suite: 33s -> ~19s, with 18 tests instead of 15. Verified three times against
the build and once against the dev server.
2026-07-26 14:08:37 -04:00

20 lines
944 B
TypeScript

import { test as setup } from "@playwright/test";
import { login, seedUiState, STORAGE_STATE, USERS } from "./fixtures/auth";
// Runs once per role before the suite, as its own Playwright project (see
// `dependencies` in playwright.config.ts). Each saves the authenticated session
// -- cookies plus localStorage -- so the specs can start already logged in
// instead of driving the form 15 times over.
//
// The login FLOW itself is covered by login.spec.ts, which deliberately uses a
// fresh unauthenticated page. This file is plumbing: if it breaks, that spec is
// where the real diagnosis lives.
for (const role of Object.keys(USERS) as (keyof typeof USERS)[]) {
setup(`authenticate as ${role}`, async ({ page }) => {
// Bake the v2 flag into the saved state so every spec inherits it.
await seedUiState(page, "dark");
await login(page, role);
await page.context().storageState({ path: STORAGE_STATE[role] });
});
}