Testing standard
Tests protect behavior and public contracts so internal implementation can evolve without rewriting assertions that mirror private structure.
Test levels
- Vitest unit tests: framework-neutral logic, composables where browser layout is irrelevant, and regression cases.
- Vue Test Utils: component props, emitted events, slots, model contracts, and Vue lifecycle behavior.
- Playwright: keyboard/focus behavior, browser integration, layout-dependent behavior, hydration where relevant, and end-to-end accessibility smoke checks.
- Automated accessibility: axe is configured with Playwright. It detects only a subset of failures and never replaces semantic, keyboard, focus, or assistive-technology reasoning.
SSR and hydration (Vitest)
Shared SSR hydration utilities live in tests/support/ssr-hydration.ts. Use expectSsrHydration to render a root component with renderToString, mount the HTML in jsdom, hydrate with createSSRApp, and fail when:
- Vue logs a warning or error during SSR or hydration (including hydration mismatch messages), or
- any
idattribute in the hydrated DOM differs from the SSR HTML.
Pass a root Component (for example from defineComponent) or ssrHydrationRoot for a single child rendered with h. Optional assertServerHtml runs extra assertions on the server string before hydration. Covered examples live in tests/integration/ssr-hydration.test.ts (GhostButton, closed and defaultOpen GhostCollapsible).
import { defineComponent, h } from 'vue'
import { expectSsrHydration } from '../support/ssr-hydration'
await expectSsrHydration(
defineComponent({
setup: () => () => h(MyComponent, { value: 'a' }),
}),
{
assertServerHtml(html) {
expect(html).toContain('data-part="root"')
},
},
)These tests run under the default Vitest jsdom environment and are included in pnpm test, pnpm test:coverage, and pnpm verify.
E2E support helpers
Shared Playwright utilities live under tests/support/ (documented in tests/support/README.md at the repo root):
playgroundTest/playgroundUrl— static server lifecycle forapps/playground/dist.expectFocus,pressSequence— keyboard and focus assertions.axeScan,expectNoAxeViolations— axe scans for example previews and the current page.
measureFocusChange in tests/e2e/focus-appearance.ts is a screenshot-based focus indicator check: the area that changes by 3:1 between focused and unfocused renderings, per-edge coverage (catches clipped rings), and layout shift. Use it where the ring may be painted on a pseudo-element or child part, inside a portal, or in forced colors, where computed styles cannot prove visibility. tests/e2e/docs-showcase-focus.spec.ts runs it over every Tab stop and overlay item of the redesigned docs showcases, together with reduced-motion and 200% text checks.
tests/e2e/examples.spec.ts checks the boundary/paint contract and axe-scans every registered example in both light and dark mode in a single navigation per example under the non-visual Playwright project. Visual example snapshots stay in examples-visual.spec.ts (@visual).
- Type tests: compile-time consumer fixtures under
packages/vue/type-tests/exercise public props, v-model controlled and uncontrolled modes, typed emits, and scoped slot props. They are included inpnpm verifythrough@ghostvue/vue'stypecheckscript (vue-tsconpackages/vue/tsconfig.json). Invalid contracts use// @ts-expect-error; if a regression makes the assignment typecheck, vue-tsc fails on an unused directive. A separate negative project (packages/vue/tsconfig.type-tests-negative.json) holds fixtures that must not compile;scripts/vue-type-tests-negative.mjsruns after the positive vue-tsc pass and fails when those diagnostics disappear. Add or extend a*Consumer.ts/*Consumer.vuepair when a component's public inference contract changes. - strictTemplates:
packages/themes/type-tests-strict/holds ordinary consumer templates and a whole-API type test compiled withvueCompilerOptions.strictTemplates(tsconfig.strict-templates.json).pnpm types:strict-templates --checkruns inpnpm verify:staticand fails on any diagnostic outside the recorded known gaps. See strictTemplates.
Name tests after observable behavior. Avoid reaching into component internals or asserting exact implementation markup unless that markup is itself a semantic contract. Keep fixtures narrow. Bug fixes require regression tests whenever practical.
Run pnpm test for focused unit/integration checks and pnpm test:coverage for standalone coverage. Coverage enforces the 80% global and per-package (packages/*/src/**) line gates. In pnpm verify, the coverage pass keeps the heavy integration tests and reuses CI's build-covered exclusions. The packed smoke checks run in verify:build. Use pnpm --filter @ghostvue/vue typecheck for Vue consumer type fixtures and pnpm test:e2e for browser checks. Follow the local checks policy when preparing a pull request. CI runs the browser job inside the pinned Playwright container image (mcr.microsoft.com/playwright:<version>-noble, matching @playwright/test in package.json) with its bundled browsers and --update-snapshots=none so missing or drifted baselines always fail.
Local Vitest runs
Local runs and watch sessions use half the available logical CPUs, rounded down to between one and eight workers. Each test file runs in an isolated fork. Watch mode skips the workspace's reports/, coverage/, and playwright-report/ output directories.
Pass --maxWorkers=2 to pnpm test or pnpm test:watch to lower the limit for a run. Set VITEST_MAX_WORKERS to apply a worker limit to commands that invoke Vitest indirectly, such as pnpm verify.
Keyboard evidence in manifests
A manifest that records accessibility.verification.automatedKeyboard maps each declared key to the chromium-e2e tests that press it. Renaming or removing such a test fails pnpm keyboard-evidence; the CI browser job also fails when a mapped test did not run or did not pass. Update the manifest reference in the same change. See accessibility verification.
Cross-browser functional matrix
Keyboard, focus, inert, scroll locking, native radio Tab order, and RTL layout differ between engines, so a representative set of functional specs also runs in Firefox and WebKit. The full suite stays Chromium-only to keep CI cost flat.
| Project | Browser | Runs |
|---|---|---|
chromium | Desktop Chrome | @visual snapshot suites only |
chromium-e2e | Desktop Chrome | every non-visual spec |
firefox-e2e | Desktop Firefox (Gecko) | non-visual specs tagged @cross-browser |
webkit-e2e | Desktop Safari (WebKit) | non-visual specs tagged @cross-browser |
Tag a describe block with { tag: '@cross-browser' }, or append @cross-browser to a test title when adding an options object would only re-indent an existing test. Tag a flow when it depends on engine behavior: real focus movement, focus traps and nested overlays, inert, root or body scroll lock, native form controls, pointer-to-value mapping, or RTL geometry. Assert real focus (toBeFocused()), ARIA state, or bounding boxes, never tabindex alone. The tagged set currently covers focus primitives (focus.spec.ts), modal primitives, dialog trap/restore, nested dialogs and popovers, root scroll lock, the drawer RTL edge flip, RTL roving for tabs, toggle group, toolbar, menubar, segmented control, calendar, and native radios (rtl-roving.spec.ts), and Slider geometry and pointer mapping in both orientations and directions, Select's opening keys moving real focus into the list, and the docs theme switcher's single Tab stop and arrow keys.
CI runs Chromium in three duration-balanced browser-shard jobs (see browser shard balancing) and Firefox and WebKit together in the single browser-cross job from the same pinned Playwright image, which already contains all three browsers and their system libraries (skipped on PRs whose diff cannot affect cross-browser component behavior). The browser check merges every report and fails if any leg fails. Locally, pnpm test:e2e runs all four projects; select one with --project, for example pnpm exec playwright test --project=webkit-e2e. On a host without Firefox or WebKit installed, run them inside the Playwright image used by pnpm test:visual:docker.
Visual baselines are Chromium-only and still come only from pnpm test:visual:docker. Functional browser coverage never adds Firefox or WebKit baselines.
Known engine differences
Each difference is asserted explicitly in the spec that covers it, with a comment. A difference is documented here only when it is engine behavior the component intentionally leaves alone, or a workaround the component ships.
| Area | Chromium | Firefox | WebKit |
|---|---|---|---|
| Headless scrollbars | 15px classic with hideScrollbars=false | 0px overlay | 0px overlay (and rejects --blink-settings) |
Scroll-lock padding-right | equals the removed scrollbar width | left untouched | left untouched |
| Native radio RTL ArrowLeft/ArrowRight | mirrored | mirrored | not mirrored: ArrowRight is next in DOM order |
| Shift+Tab into an all-unchecked radio group | first radio | first radio | last radio |
| Mouse event coordinates | exact edge targets land on the edge | integers; overshoot track edges | exact edge targets land on the edge |
Modal close on overlay pointerdown | compatibility mousedown cancelled by GhostVue | same as Chromium | no mousedown, focus dropped to <body>; GhostVue reapplies the restored focus (see the dialog spec) |
tests/support/scrollbars.ts holds the per-engine launch options and the scroll-lock assertions. Per-component notes live in the dialog, drawer, radio group, and slider specifications.
Visual regression
Visual snapshot suites are tagged @visual and assert deterministic rendering with animations: 'disabled' and a default maxDiffPixelRatio of 0.03 (unless a suite documents a justified override):
- Playground visual suites:
GhostButtonstate matrices (light, dark, and forced-colors across densities), flagship theme matrices (calm,vibrant,mono), density and roundness matrix, visual reference recipes (elevation, materials, gradients), and the frozen ambient spotlight opt-in snapshot. - Public example baselines:
tests/e2e/examples-visual.spec.tssnapshots every registered example inexamples/registry.tsinlightanddarkmode on the docs token host (default, density unset), and every themed example again with thedefaulttheme atcomfortabledensity (*-default-comfortable-*). The/examples.htmlroute picks the token host from?theme=,?density=, and?mode=. It never adds.ghost-themeto<html>, so headless examples stay unthemed as in the docs, and the test never resizes controls or pads the canvas: the screenshot captures the route's real canvas inset.tests/e2e/examples.spec.tsasserts the same boundary and that no track, thumb, indicator, slider, switch, separator, progress bar, or spinner paints an empty box. - Forced-colors baselines:
tests/e2e/forced-colors-visual.spec.tssnapshots one themed example per interactive family beyondGhostButton(fields, checkbox/radio/switch, an open dialog, an open select listbox, tabs, accordion, progress, slider, calendar, and pagination) withforcedColors: 'active'on thedefaulttheme in light mode atcomfortabledensity. One screenshot per example; add a family only when it introduces a new forced-colors treatment. - Docs site baselines:
tests/e2e/docs-visual.spec.tssnapshots the docs nav, a themedGhostInputpreview, and a headless checkbox preview at 390px inlightanddarkmode (requiresapps/docsbuild; included inpnpm test:visual). - Docs hero showcase baselines:
tests/e2e/docs-showcase-visual.spec.tssnapshots the ten redesigned hero showcases (each component page's first example) in the built docs on the first-paint host (default, density unset). Every hero is captured with source closed at 390px and 1280px browser widths inlightanddark. Overlay heroes (Dialog, Dropdown Menu, Select, Combobox, Popover) are also captured open from the keyboard, clipped to the trigger and panel, at the same widths and modes. A source-open capture at 320px (Button) and 768px (Tabs) covers the toolbar and fence, and a 480px preview-width capture of Table at a 1280px browser width covers container resizing separately from browser widths. Every capture first asserts no horizontal page overflow. Keep this matrix proportionate: add a hero only when a component page gains a redesigned showcase.
Run only the visual snapshot suites locally with:
pnpm test:visualThe chromium project runs only @visual tests with zero retries, including in CI, so a flaky screenshot fails the job. The chromium-e2e project runs all non-visual browser tests and retains two retries in CI (zero locally). pnpm test:e2e runs these and the Firefox/WebKit functional projects (see the cross-browser matrix); existing Chromium snapshot names are preserved.
Committed baselines (*-chromium-linux.png) are generated inside the pinned Playwright Linux container so host OS font rendering cannot introduce drift. When a visual change is intentional or a new example is added, regenerate Linux baselines locally inside that image:
pnpm test:visual:dockerThe Docker command masks the host's root, app, and package node_modules with anonymous volumes, including packages/shared/node_modules, so container installs cannot follow workspace links into host dependencies. Keep this list aligned with the workspace directories when adding packages or apps.
To check repeatability without updating baselines, run the following inside the same pinned image after pnpm install --frozen-lockfile:
pnpm test:visual --repeat-each=5 --retries=0Commit regenerated baseline PNGs in a dedicated commit when updating existing snapshots so pixel churn is easy to review. Use pnpm test:visual:update only when already running inside the pinned Linux environment.
Visual review evidence
For a showcase change, include before and after captures at matched widths, appearance, and interaction state. Record the commit and theme for each capture. If the approved change replaces a palette or default, name that change in the comparison. Link to the clean consumer rendering and the canonical source. For overlays, include open and closed states and test keyboard entry, focus movement, dismissal, and return where the component supports them.
Review light and dark at narrow and wide widths. Check the resized preview, larger text, reduced motion, and forced colors when the change can affect them. Include composed contrast and focus evidence with the focused Playwright results, the Linux snapshot diff or comparison, and the repository verification results. If a gate reproduces a baseline failure, record the matching test and baseline revision. Keep gate thresholds and assertions in place.
Use the showcase criteria to record the review decision. A passing screenshot comparison establishes repeatability. The reviewer still checks design intent and accessibility in the rendered example.
Example preview evidence
The pull request template has an optional Preview evidence block for changes to a docs page, example, or showcase. Use it to name exactly what you reviewed. Skip it for unrelated changes. It does not require new screenshot tooling or a full matrix. List the states you actually checked, and leave baseline captures to the Linux baseline process.
The example below shows the format, using the Dialog hero. The Observed line records what the author judged by eye, such as design intent; here it is illustrative, so write your own from the states you actually reviewed. The Asserted line names what a test checks on every run, and the Result line comes from a real replay of the focused command:
- Page: `/components/dialog` (first example on the page)
- Example: `dialog/edit-profile` (`examples/dialog/edit-profile.vue`)
- Hosts: docs page, and standalone `/examples.html?id=dialog/edit-profile`
- Appearance and width: light and dark at 390px and 1280px
- Key interaction: Enter opens the dialog with focus in Full name, Tab
wraps inside it, and Escape discards edits and returns focus to Edit profile
- Observed: in both hosts, the profile card, field labels, and Save and
Cancel actions read clearly in light and dark, and the open dialog fits
the 390px width without clipped labels.
- Asserted: `tests/e2e/docs-dialog-showcase.spec.ts` checks the focus trap,
Escape discard, focus return, save validation, short-screen scrolling, RTL
centering, portaled surface tokens, and axe with the dialog open and closed.
`docs-showcase-visual.spec.ts` compares `dialog-hero-*` Linux baselines.
- Focused command: `pnpm docs:build`, then
`pnpm exec playwright test tests/e2e/docs-dialog-showcase.spec.ts --project=chromium-e2e`
- Result: 7 passed (pinned `mcr.microsoft.com/playwright:v1.65.1-noble` image)
- Rubric: [showcase criteria](../contributing/examples.md#review-a-showcase);
no baselines changedRecord observations only for the states you checked. A test name does not count as a manual check, and a manual check does not replace a failing or missing test. If the change updates baselines, cite the pnpm test:visual:docker run or the update-baselines workflow commit.
Regenerating baselines in CI
Contributors without Docker can ask CI to regenerate baselines instead. Add the update-baselines label to the pull request to run the Update visual baselines workflow (.github/workflows/update-baselines.yml). The label only counts when the account that adds it has write access. The workflow never runs automatically when CI fails, and it has no manual (workflow_dispatch) trigger. When snapshots changed, the Publish visual baselines workflow (.github/workflows/publish-baselines.yml) pushes them once the first run completes. No approval step is needed.
The workflow runs in the same pinned Playwright image as CI and pnpm test:visual:docker, using scripts/update-visual-baselines.mjs:
- Run every
@visualtest without updating snapshots. If all pass, it comments and pushes nothing. - If any visual test fails for a reason other than a screenshot mismatch or a missing baseline (a timeout or functional assertion), it comments and pushes nothing.
- Rerun only the failing tests with
--update-snapshots=changed, then rerun them again without updating to confirm they pass. - Check that the only changed paths are
tests/e2e/*.spec.ts-snapshots/*-chromium-linux.png, then push one commit,test(visual): regenerate baselines (#123), to the PR branch. Untilscripts/lib/visual-baselines.jsis updated, the workflow still resolves a legacyGHO-ntoken from the PR title or branch (agent/gho-<n>-*), and falls back to the PR number (#123) when none is found. Preferissue-<n>-<slug>branches andFixes #nin the PR body for new work.
Any failure, including a test that still fails after its update, produces a PR comment and no push. The workflow removes the label when it finishes, so add it again to retry. Review the image diffs in the pushed commit before merging.
It refuses fork PRs, because it only runs for branches in this repository. It also only runs on a PR that GitHub can merge (no conflicts with master).
The job that installs dependencies and runs Playwright has a read-only token, no secrets, and no dependency cache. The job that pushes runs no code from the PR: it runs scripts/update-visual-baselines.mjs from a separate checkout of the default branch, checks out the PR head without persisted credentials, disables git hooks, and passes BASELINES_PUSH_TOKEN only to the final git push step. A change to the script therefore takes effect only after it merges to master.
A labelled run uses the workflow file from the PR branch, so a branch could change the regenerate workflow itself. That is why the push is a separate workflow: GitHub runs workflow_run workflows from the default branch only, and the push token is a secret of the baseline-push environment, which only master may deploy to. A job from a PR branch cannot read the secret, whatever its workflow file says. Before pushing, the publish workflow re-reads the PR and checks that it is open, comes from this repository, is still at the regenerated commit, and that the account that started the run has write access. It treats the uploaded snapshots as data, copies only snapshot PNG paths, and refuses to write through a symlink committed in the PR checkout. A PR branch that predates the publish workflow still carries the old regenerate workflow; merge master into it before adding the label.
Maintainer setup:
- Create the
update-baselineslabel. - Create an environment named
baseline-push(Settings → Environments). Under Deployment branches and tags, choose Selected branches and tags and add onlymaster. Leave Required reviewers off: the branch rule is the protection, and a reviewer would only add a wait. - Add an environment secret named
BASELINES_PUSH_TOKENtobaseline-push, not a repository secret. Use a fine-grained personal access token or a GitHub App token with Contents: read and write on this repository only. Pushes made with the defaultGITHUB_TOKENdo not start new workflow runs, so CI would never check the new baselines. If the secret is missing, the push job stops before committing and the workflow comments. It never falls back toGITHUB_TOKEN.
When the CI browser job fails, Playwright's HTML report and diff outputs (playwright-report/ and test-results/, including expected, actual, and diff PNGs) are uploaded as the playwright-report workflow artifact (retained for 14 days) on the failed GitHub Actions run.
Bundle size and tree-shaking
After pnpm build, run pnpm size. It checks gzip budgets for every package entry and every single-component import, and confirms that Vue stays external. pnpm verify runs it after pnpm exports:check. Budgets, fixture rules, and the update workflow are in the performance standard.
Benchmarks
*.bench.ts files under tests/bench/ run with vitest bench. They are informational: timings depend on the host, so they are not part of pnpm test, pnpm verify, or CI. Compare a change against master on the same machine.
| Script | File | Measures |
|---|---|---|
pnpm bench:registry | tests/bench/select-combobox-registry.bench.ts | Select and Combobox option-registry churn |
pnpm bench:data-table | tests/bench/data-table-processing.bench.ts | DataTable sort, filter, and page processing at 1k-10k rows |
A guarantee that must never regress belongs in a unit test, not a bench. For example, the DataTable rule that a page change never re-sorts is a counter test in packages/vue/src/use-ghost-data-table.counters.test.ts.
Coverage reporting
*.test.ts files run in Vitest as unit and integration tests and count toward coverage. *.spec.ts files run in Playwright e2e tests in CI's browser job and do not count toward Vitest coverage.
apps/docs and apps/playground are development hosts. They are intentionally outside the Vitest include list and the coverage gate.
After Vitest runs, find the coverage table in the CI verify job summary and download the coverage-report artifact for the HTML, JSON summary, and LCOV reports (retained for 14 days). Reports are generated even when tests fail; failures before Vitest starts cannot produce coverage. Locally, run pnpm test:coverage and open coverage/index.html.
Packed export integrity
After pnpm build, pnpm published-exports also reads the file list that npm pack --dry-run reports for each publishable package. It fails when a tarball has no root README, contains a test file (*.test.*, *.spec.*, or __tests__/), or contains a source map whose sources it neither ships nor embeds. Publish builds emit no source maps, so the last case means the build config changed or dist/ is stale; rebuild from a clean dist/.
Then run pnpm exports:check. It packs every package marked publishable: true in scripts/workspace-packages.mjs into a temporary directory and checks the actual tarballs with publint and Are the Types Wrong (attw --pack). Temporary artifacts are removed even on failure. pnpm verify runs this immediately after pnpm published-exports; publint errors, attw problems, and the packed @ghostvue/themes/define consumer smoke (see scripts/themes-define-packed-smoke.mjs) fail the gate.
pnpm verify then runs pnpm mcp:packed (scripts/mcp-packed-smoke.mjs). It packs @ghostvue/mcp, fails if the tarball holds anything outside dist/ (other than package.json, the README, and the license), installs it with pnpm install --prod into a scratch project, and fails when that production node_modules, excluding dist/assets/, is over 18 MiB. It then starts the installed ghostvue-mcp over stdio, lists the five tools, and calls each one offline. See the MCP server guide.
pnpm consumer:packed (scripts/consumer-packed-smoke.mjs) follows. It installs the packed publishable tarballs with npm into Vite + Vue, Nuxt, and ESLint consumer projects from tests/fixtures/consumer-packed/, checks that a production Vite build of the documented themed setup keeps the base stylesheet imported by the @ghostvue/themes entry, mounts themed Field, Input, Select, Dialog, Drawer, and Toast from the production bundle in jsdom, builds and server-renders the Nuxt auto-imports, and lints a valid and an invalid SFC. See releases.
pnpm verify then runs pnpm agents-guide (scripts/check-ai-agents-guide.mjs). It reads every MCP host snippet in the AI agents guide, fails when one names a package, bin, or path that @ghostvue/mcp does not ship, and starts the built bin over stdio as those snippets do. The server must list exactly the tools the guide mentions and answer a call to each. tests/integration/ai-agents-guide.test.ts checks the same snippets, the ESLint rule and config names, and the parser without a build.
Only attw's cjs-resolves-to-esm rule is ignored: these packages are ESM-only, so CommonJS consumers must use dynamic import. CSS and JSON asset subpaths are checked by publint but excluded from attw's JavaScript/type entrypoint analysis. The normal Node10, Node16, and bundler type-resolution checks remain enabled.
Vue and theme builds finalize emitted declarations with explicit relative ESM extensions (including Vue declaration paths). CSS side-effect imports remain in JavaScript only. Their declaration maps are disabled because finalization changes the emitted text. Top-level types and the theme define type mapping also support consumers using legacy TypeScript resolution.