This application includes three test suites:
- Unit Tests: for testing individual components (except
+pagecomponents) and library functions / classes in isolation. - Integration Tests: for testing
+pagecomponents (which require a full browser context and a node server); uses a mock API server to provide deterministic test data. - End-to-end Tests: for smoke-tests to validate the full application stack against live production data.
See below to run each suite separately, or run all test suites sequentially with:
pnpm run test # runs unit, integration (with test build), and e2e (with production build)
pnpm run test:no-build # runs unit + integration only (skips e2e, requires prior test build)Run once:
pnpm run test:unit --runWatch for file changes:
pnpm run test:unitPass additional options to vitest after -- – e.g.,
pnpm run test:unit -- Searchto only run tests that match "Search"pnpm run test:unit -- --helpto see additionalvitestoptions
See Unit test frameworks below for additional info.
# Build first if source files have changed since last build
pnpm run build --mode=test
# Run all integration tests
pnpm run test:integration- prefix with
CI=1to skip some flaky tests that we skip in CI - pass additional options to
playwrightafter--– e.g.,pnpm run test:integration -- trading-viewto only run tests that match "trading-view"pnpm run test:integration -- --helpto see additionalplaywrightoptions
- runs tests in
tests/integrationfolder (headlessly) and reports results - automatically runs
pnpm preview --mode=testto start a node preview server - uses mock API data found in
tests/mocks - loads
.env.testfor deterministic test configuration
For normal development, keep checked-in defaults in .env and place local-only secrets in
.env.local. Vite/SvelteKit loads .env.local automatically and it overrides .env.
The regular integration suite intentionally stays deterministic and uses .env.test plus mock
APIs. This means secret-backed features should not be added to the default pnpm run test:integration
flow unless they can be mocked reliably.
For checks that should use your local private secrets, use the dedicated private Playwright config:
pnpm exec playwright test --config tests/integration/private.playwright.config.tsThis private harness overlays the relevant private values from .env.local on top of the normal
test-mode configuration. Tests in this harness should skip when the required secrets are absent.
See Integration and e2e test frameworks below for additional info.
Test builds (--mode=test) use separate output directories so they don't interfere with the dev server:
- SvelteKit output:
.svelte-kit-test/instead of.svelte-kit/ - Vite cache:
node_modules/.vite-test/instead ofnode_modules/.vite/
This is configured in vite.config.ts (sets cacheDir and an env var) and svelte.config.js (reads the env var to set outDir). The env var __SVELTEKIT_TEST_MODE is used instead of process.argv because SvelteKit's postbuild analysis runs in a Worker thread that inherits process.env but not process.argv.
You can safely run the dev server and test builds concurrently without cache corruption.
E2e tests are smoke tests that run against the live production API. They require a production
build (not a test build), because the preview server runs with --mode=production and expects the
output in .svelte-kit/ (the default output directory).
# Production build is required (not build:test)
pnpm run build
# Run all e2e tests
pnpm run test:e2e- see
test:integrationoptions above (supports the same options)
- runs tests in
tests/e2efolder (headlessly) and reports results - automatically runs
pnpm preview --mode=productionto start a node preview server - uses real production backend API (not mock data)
E2e tests run in a separate CI job (test-e2e) from unit/integration tests because they need a
different build:
- Unit + integration (
testjob): usespnpm run build:test(test mode, output in.svelte-kit-test/) - E2e (
test-e2ejob): usespnpm run build(production mode, output in.svelte-kit/)
The test:no-build script only runs unit and integration tests. E2e tests are not included because
they require the production build.
See Integration and e2e test frameworks below for additional info.
- Vitest – overall testing framework; see guide, API and config docs for additional info.
- Testing Library – provides interface for inspecting and interacting with the DOM, using the Svelte Testing Library adapter.
- jest-dom – extends Jest with DOM-specific matchers.
- Playwright – overall testing framework; see docs and API reference for additional info.
- vite-plugin-mock-dev-server
– used when running
integrationtests to serve mock API data found intests/mocks.