ShiftFast Docs

Testing

Vitest for billing logic, Playwright for critical flows.

pnpm test         # unit tests, once
pnpm test:watch   # unit tests, watch mode
pnpm test:e2e     # end-to-end tests, headless
pnpm test:e2e:ui  # end-to-end tests, interactive (2 workers)

No CI pipeline ships with the kit — run these locally before you push, or wire them into whatever CI you add.

Unit tests

Vitest tests live in tests/unit/, mirroring src/. They cover the riskiest logic, which is almost all billing: the plan config, plan resolution, access checks, checkout, trials, and webhook handling.

To add one, create a *.test.ts file at the mirrored path — for example src/lib/billing/access.ts → tests/unit/lib/billing/access.test.ts.

The tests don't need real credentials: vitest.config.ts supplies dummy environment variables, and tests that touch the database or Stripe mock those clients. Copy the mocking pattern from the existing billing tests, and reuse tests/unit/fixtures/billing-plans.ts, which has one sample plan of every kind.

End-to-end tests

Playwright tests live in tests/e2e/ and run in Chromium against a production build, which Playwright builds and starts itself (pnpm build && pnpm start). They need the local database running (pnpm local:up).

The interactive mode runs 2 tests at a time, since it traces every step. If headless tests time out on a slower machine, run fewer at once, such as pnpm test:e2e --workers=2. The tests skip the animated background on the sign-in pages, which would otherwise slow every browser down.

SpecCovers
marketing.spec.tsThe home page and /pricing render.
auth.spec.tsSigned-out visitors to /app pages, in any locale, are sent to the app's own /sign-in.
sign-up.spec.tsA new user signs up, verifies their email, creates an organization, and lands on the dashboard.
sign-in.spec.tsSigning in through the form, with an email code, returns to the page that required it. Skipped if the Clerk instance doesn't allow email-code sign-in.
sign-out.spec.tsSigning out returns to /sign-in, and the app is locked again.
organization-roles.spec.tsAdmins reach billing; members don't see it, are redirected away from it, and can't start checkout.
billing.spec.tsThe billing page for each plan state (free, active, trial, past due, one-time), the upgrade gate when there's no free plan, the member-limit lock, no second checkout for a subscribed organization, trial eligibility, and real Stripe calls: starting Checkout from the billing page and from /pricing, starting a trial, and opening the customer portal.
pricing.spec.tsA contact plan links to its contact page, and a new customer goes from /pricing through sign-up to Stripe Checkout.

Signed-in tests

The signed-in tests use Clerk's @clerk/testing and your existing Clerk keys from .env — no extra setup. Before the run, they create three test users in your Clerk development instance and reuse them on later runs: an admin and a member of "E2E Test Org", and an admin of a separate "E2E Billing Org", whose plan the billing tests change. The sign-up test creates its own user and deletes it afterwards.

They only run against a Clerk development instance (pk_test_/sk_test_ keys) and are skipped otherwise. Test users use +clerk_test email addresses, which Clerk verifies with the code 424242, so no email is sent.

Billing tests

The billing tests set each plan state by writing the organization's org_subscriptions row directly, then check what the app shows. How Stripe events become those rows is covered by the unit tests. Plans and labels come from src/config/billing.ts and en.json, so the tests follow your own plans; a test for a kind of plan you don't offer, such as a one-time plan, is skipped.

The Stripe tests, including the new-customer test in pricing.spec.ts, need a Stripe test secret key and your plans' price IDs in .env, and the portal test needs the customer portal set up in test mode (see Stripe Setup). Otherwise they're skipped. The portal test creates a Stripe test customer and deletes it afterwards.

Adding a signed-in test

Start from one of the saved sessions:

import { TEST_USERS } from './support/clerk'

test.use({ storageState: TEST_USERS.admin.storageState })

On this page