/engsys-web:frontend-testingfrom engsys-web
Frontend test discipline — Vitest 4, Testing Library (RTL / React Testing Library), and Playwright E2E for React / Next.js apps. Use when writing or reviewing Vitest specs, vi.mock factories, fake-timer tests, RTL component tests, Radix portal tests, or Playwright E2E specs and their CI matrix wiring.
Ships in engsys-web. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Applies to: unit/component specs (*.spec.{ts,tsx}) and Playwright E2E (e2e/**/*.spec.ts) in the repository's web frontends. Stack assumed: Vitest 4.x, @testing-library/react, testing-library + react-hooks eslint plugins, Radix UI, and Playwright E2E with @axe-core/playwright.
Naturalize: confirm the Vitest version, eslint test config, and Playwright CI workflow in
CLAUDE.md. Paths below (apps/web/...,.github/workflows/...) are illustrative.
vi.hoisted)vi.hoisted)vi.mock factories are hoisted above const/let. Wrap any spy referenced inside a vi.mock factory in vi.hoisted():
// Wrong — ReferenceError at runtime because vi.mock is hoisted above const
const mockCreateJob = vi.fn();
vi.mock("@/lib/api-client", () => ({ reportsExportApi: { createJob: mockCreateJob } }));
// Right — vi.hoisted runs before the factory
const { mockCreateJob } = vi.hoisted(() => ({ mockCreateJob: vi.fn() }));
vi.mock("@/lib/api-client", async (importOriginal) => {
const actual = await importOriginal<typeof import("@/lib/api-client")>();
return { ...actual, reportsExportApi: { createJob: mockCreateJob } };
});
When adding an export to a mocked module, update every vi.mock factory of that module in the same commit. Prefer importOriginal + ...actual so existing exports survive automatically:
grep -rl 'vi.mock("@/lib/permissions"' --include='*.spec.*' apps/web
poolOptions.forks.singleFork was removed in Vitest 4 — use top-level fileParallelism: false when specs must run sequentially:
export default defineConfig({
test: { pool: "forks", fileParallelism: false },
});
Separate configs for gated suites: When a suite requires external infrastructure (live DB, LLM API keys, Docker stack), isolate it in vitest.e2e.config.ts and guard the spec (if (!process.env.EXTERNAL_E2E) return) so default pnpm test stays fast and hermetic.
Import act from react (not @testing-library/react) and wrap only vi.advanceTimersByTime(ms) — never wrap render/rerender inside act:
import { act } from "react";
import { renderHook } from "@testing-library/react";
function advanceTimers(ms: number) {
act(() => { vi.advanceTimersByTime(ms); });
}
Use screen.getByRole, screen.queryByRole, screen.getByLabelText, or screen.getByTestId — never container.querySelector(...) (except when asserting that an XSS payload injected zero <script> tags, with an explicit per-line eslint-disable rationale comment).
render() twice in the same it() block without calling cleanup() in between.Select, DropdownMenu, Popover, Dialog) do not open via pointer events in JSDOM. In unit tests, assert the hook/props invariant directly and test the interactive portal flow in Playwright E2E:it("client-side sort parameter is not sent to useItemsQuery", () => {
renderTable({ sort: "recent" });
for (const call of mockUseItemsQuery.mock.calls) {
expect(call[0]).not.toHaveProperty("sort");
}
});
When a component accumulates pages across fetches ("Show more"), use React.useLayoutEffect + React.useReducer (with a prevIdRef guard for filter resets) so accumulated rows flush synchronously inside RTL's render() without flaky waitFor loops.
A new e2e/*.spec.ts file that isn't picked up by CI is test theater. Whenever adding an E2E spec, verify or update the CI workflow matrix in the same commit:
ls apps/web/e2e/*.spec.ts | xargs -n1 basename
grep -ni "playwright" .github/workflows/web-ci.yml
Apply pending local migrations before running Playwright locally so beforeAll seeds never abort on missing schema columns:
pnpm db:migrate:local
set -a && source apps/web/.env.local && set +a
cd apps/web && pnpm playwright test e2e/<spec>.spec.ts --project=chromium
When the CI E2E environment boots only the core web + API stack without optional upstream workers, assert the immediate container/skeleton state or provide a complete page.route() contract fixture:
await expect(page.getByTestId("items-grid")).toBeVisible();
const panel = page.getByTestId("settings-panel"), query child elements inside panel, not panel.getByTestId("settings-panel").waitUntil: "domcontentloaded" instead of networkidle on pages with background polling.beforeAll, not beforeEach.await expect(page).toHaveURL(/pattern/)./^confirm action$/i) after verifying the parent surface has mounted.Target table rows via page.getByRole("row", { name: /Acme Corp/i }) instead of page.getByText("Acme Corp") (which matches <tr>, <td>, and <p> simultaneously in strict mode). For Radix tooltips (which duplicate a hidden accessibility node), qualify with .first() or exact role/name.
Run @axe-core/playwright (wcag2a, wcag2aa) against rendered pages in Playwright to catch real CSS token contrast failures, focus-trap bugs, and broken ARIA IDs that JSDOM unit tests cannot observe. Fix violations in design tokens or component markup — never weaken contrast with opacity-* classes.
Whenever a PR modifies user-visible headings, button labels, or multi-step flows (such as adding a confirmation modal), grep all e2e/ directories and update affected Playwright specs in the same PR.
vi.mock factories use vi.hoisted() and importOriginalfileParallelism: false (never removed singleFork)vi.advanceTimersByTime in act from reactscreen.* accessible queries and avoid double render() callsgetByRole("row"); whole-document axe scan passese2e/ specs in the same PRWhat SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
3 skills in this plugin
/react-conventionsReact + Next.js client conventions (React 19 / Next.js 16+, TanStack Query, Radix UI, shadcn-style cards/dialogs). Use when writing or reviewing React components, hooks, optimistic cache patches, data-fetching code, dialogs, Radix Select usage, JSX, interactive cards/rows, or Next.js 16 proxy.ts / runtime boundary code./web-platform-conventionsWeb platform conventions for this repo — Content-Security-Policy discipline and (for Next.js 16+) the proxy.ts-not-middleware convention. Use when editing CSP headers, adding a third-party SDK / analytics / external API origin, touching request-edge code (middleware/proxy), or wiring auth/redirects/headers on a web frontend.npx claudepluginhub eric-sabe/engsys --plugin engsys-web