Test
Playwright
Sign in without UI, seed data, and screenshot every theme in light and dark.
Usage
import { test } from "@playwright/test"
import { expectAcrossThemes, seed, signInAs } from "@dapplelight/signet-test/playwright"
const BASE = "http://localhost:5173"
const secret = process.env.SESSION_SECRET as string
test("dashboard", async ({ page }) => {
await signInAs(page, "user_1", { session: { cookieName: "app_session", secret }, url: BASE })
await seed(page, { invoices: [{ id: "inv_1" }] })
await page.goto("/dashboard")
await expectAcrossThemes(page, "dashboard")
})API
| Export | What it does |
|---|---|
signInAs(page, userId, options) | Set a session cookie directly, skipping the sign-in UI. |
seed(page, data, options?) | POST test data to the app's seed endpoint. |
expectAcrossThemes(page, name, options?) | Screenshot in every theme and mode and compare to baselines. |
applyTheme(page, theme, mode) | The default theme switch. |
THEMES | ["editorial", "cinematic", "finance"]. |
MODES | ["light", "dark"]. |
Mode, ApplyTheme, AcrossThemesOptions | Types. |
signInAs(page, userId, options)
| Option | Type | Default | |
|---|---|---|---|
url | string | page's origin | App origin. Required before the first goto. |
session | SessionOptions | none | Mints a signet-server stateless session with your cookie name and secret. |
token + cookieName | string | none | Instead of session: a token you minted (stored sessions, Better Auth) and its cookie name. |
seed(page, data, options?)
| Option | Type | Default | |
|---|---|---|---|
path | string | "/__signet/seed" | Demo mode's seed route. Throws on a non-2xx answer; returns the JSON. |
expectAcrossThemes(page, name, options?)
Compares each screenshot with <name>-<theme>-<mode>.png. All six are checked before the test fails.
| Option | Type | Default | |
|---|---|---|---|
themes | readonly string[] | THEMES | Narrow the set. |
modes | readonly Mode[] | MODES | Narrow the set. |
apply | ApplyTheme | applyTheme | Your own theme switch. |
screenshot | toHaveScreenshot options | none | fullPage, mask, maxDiffPixelRatio and so on. Animations are disabled and the caret hidden. |
The default applyTheme sets signet-theme in localStorage, reloads with ?theme=<name>&dark=<0|1>, then makes the .dark class match.
Baselines differ by OS and browser build. Write them with --update-snapshots on the machine or CI image that checks them.
Examples
Only the dark editorial theme
import { test } from "@playwright/test"
import { expectAcrossThemes } from "@dapplelight/signet-test/playwright"
test("invoice list", async ({ page }) => {
await expectAcrossThemes(page, "invoice-list", {
themes: ["editorial"],
modes: ["dark"],
screenshot: { fullPage: true },
})
})An app that switches themes its own way
import { test } from "@playwright/test"
import { expectAcrossThemes } from "@dapplelight/signet-test/playwright"
test("settings", async ({ page }) => {
await expectAcrossThemes(page, "settings", {
apply: async (page, theme, mode) => {
await page.goto(`/settings?skin=${theme}&mode=${mode}`)
},
})
})