Skip to Content
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

ExportWhat 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, AcrossThemesOptionsTypes.

signInAs(page, userId, options)

OptionTypeDefault
urlstringpage's originApp origin. Required before the first goto.
sessionSessionOptionsnoneMints a signet-server stateless session with your cookie name and secret.
token + cookieNamestringnoneInstead of session: a token you minted (stored sessions, Better Auth) and its cookie name.

seed(page, data, options?)

OptionTypeDefault
pathstring"/__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.

OptionTypeDefault
themesreadonly string[]THEMESNarrow the set.
modesreadonly Mode[]MODESNarrow the set.
applyApplyThemeapplyThemeYour own theme switch.
screenshottoHaveScreenshot optionsnonefullPage, 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}`)
    },
  })
})