Test an App with Fakes and Playwright
Fake payment and notification providers, screenshots across every theme, a dev overlay and a no-network demo mode.
Install
npm i -D @dapplelight/signet-test @playwright/testTest payments against a fake gateway
import { createPayments, memoryStore } from "@dapplelight/signet-payments"
import { fakeGateway } from "@dapplelight/signet-test/payments"
const gw = fakeGateway("razorpay")
const payments = createPayments({ gateways: [gw], db: memoryStore() })
const c = await payments.checkout({ amount: 49900, currency: "INR", idempotencyKey: "k1", userId: "u1" })
await payments.handleWebhook("razorpay", await gw.complete(c.gatewayId))
console.log(gw.calls.map((x) => x.method)) // ["createCheckout", "verifyWebhook"]Test notifications against fake senders
import { z } from "zod"
import { createNotifier, defineTemplates } from "@dapplelight/signet-server/notify/notifier"
import { fakeNotifyStore, fakeSenders } from "@dapplelight/signet-test"
const { outbox, senders } = fakeSenders()
const store = fakeNotifyStore()
const notifier = createNotifier({
channels: senders,
store,
recipients: async () => ({ email: "[email protected]" }),
templates: defineTemplates({
welcome: {
category: "account",
data: z.object({ name: z.string() }),
en: { email: { subject: (d) => `Welcome, ${d.name}`, html: (d) => `<p>Hi ${d.name}</p>` } },
},
}),
})
await notifier.notify("u1", "welcome", { name: "Asha" })
console.log(outbox.last("email")?.rendered.subject) // "Welcome, Asha"Check every theme with Playwright
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")
})npx playwright test --update-snapshotsWrite baselines on the machine or CI image that checks them: they differ by OS and browser.
Add the dev overlay
import { DevOverlay } from "@dapplelight/signet-test/overlay"
import { THEMES } from "@dapplelight/signet-test/playwright"
export const Dev = ({ theme, setTheme }: { theme: string; setTheme: (t: string) => void }) => (
<DevOverlay themes={THEMES} theme={theme} onThemeChange={setTheme} />
)It renders nothing in production builds.
Run the app in demo mode
import { createDemo, isDemo } from "@dapplelight/signet-test/demo"
import { env } from "./env"
const SEED = { users: [{ id: "user_1", name: "Test User" }], invoices: [] }
export const demo = isDemo(env)
? await createDemo({ seed: SEED, user: SEED.users[0], plan: "pro", appEnv: env.APP_ENV })
: null
// In your router: (await demo?.handle(request)) ?? next()SIGNET_DEMO=1 turns it on. It refuses appEnv: "production" unless allowProduction is set.