sveltejs/svelte
Testing
Active contributors: Rich Harris, Simon H, Dominic Gannaway
Test runner
Vitest configured in vitest.config.js and vitest-xhtml-environment.ts. The top-level pnpm test runs vitest run against everything; per-suite filters are how most contributors operate.
Where tests live
All Svelte tests are under packages/svelte/tests/. The directory is organised by what the test exercises rather than by the source layout:
| Directory | What it covers |
|---|---|
tests/runtime-runes/ |
Component runtime tests in runes mode (Svelte 5) |
tests/runtime-legacy/ |
Component runtime tests in legacy mode (Svelte 4 compatibility) |
tests/runtime-browser/ |
Browser-only runtime tests (run via Playwright Chromium) |
tests/runtime-production/ |
Tests asserting production-mode behaviour (no DEV-only code paths) |
tests/runtime-xhtml/ |
XHTML quirks |
tests/server-side-rendering/ |
SSR output tests against the server runtime |
tests/hydration/ |
Hydration correctness on top of SSR'd HTML |
tests/parser-modern/, tests/parser-legacy/ |
Parser snapshot tests (compare against .expected JSON) |
tests/validator/ |
Compile-time error and warning emission tests |
tests/css/, tests/css-parse.test.ts |
CSS pruning, encapsulation, parser |
tests/snapshot/ |
Code-generation snapshots (compiler output diffed against .expected.js files) |
tests/sourcemaps/ |
Source-map correctness |
tests/preprocess/ |
svelte/compiler#preprocess |
tests/migrate/ |
The Svelte 4 → 5 codemod |
tests/types/ |
TypeScript-level checks (tsc is run against this dir as part of pnpm check) |
tests/store/, tests/motion/, tests/signals/ |
Standalone unit tests for those modules |
tests/manual/ |
Manual-only repros |
tests/print/ |
svelte/compiler#print round-tripping |
tests/compiler-errors/ |
Compiler errors via the public compile() entry point |
The shared harness lives in tests/suite.ts and tests/helpers.js. tests/animation-helpers.js provides timer/transition stubs for runtime tests.
Running a focused test
# Whole suite
pnpm test runtime-runes
# Single test name (matches via vitest's -t)
pnpm test validator -t a11y-alt-text
# Faster iteration: drop the other tests entirely
FILTER=a11y-alt-text pnpm test validatorSnapshot updating
Snapshot-based suites (parser, snapshot, hydration, ssr) write the expected output to disk and compare. To regenerate after an intentional change:
UPDATE_SNAPSHOTS=true pnpm testInspect the resulting diff carefully — overly broad updates are a common review nit.
Browser tests
tests/runtime-browser/ uses Playwright (@playwright/test) running headless Chromium. Install with pnpm playwright install chromium (CI does this every run).
Async-mode coverage
Async-aware effects live behind a runtime flag in packages/svelte/src/internal/flags/async.js. CI runs runtime-runes twice — once with async mode on (default) and once with SVELTE_NO_ASYNC=true (the TestNoAsync job). When you add a runtime test that doesn't depend on async features, both jobs should pass.
Benchmarks
Benchmarks (benchmarking/) are not part of the test suite, but CI runs pnpm bench to detect catastrophic regressions. Use pnpm bench:compare locally to compare your branch against another commit.
Writing a test
Most test files are .test.ts next to their helpers, or _config.js + main.svelte pairs under a sample folder. Look at neighbouring tests in the suite you're modifying — they're highly regular.
See also
- Debugging — when a test fails mysteriously.
- Patterns and conventions — for assertion style.
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.