Set up testing environment and CI
2 minutes read
Vitest ^4.0.18 is installed but completely unconfigured. This
task sets up the foundation so that subsequent test-writing tasks can just
add .test.js files and they work.
Part of Add tests and CI integration (sub-task 1 of 4).
Vitest config
Create vitest.config.js (or extend vite.config.js ):
- Resolve
$libalias tosrc/lib - Resolve
$stylesalias tosrc/styles - Mock or stub
$app/*imports (paths, environment, stores, navigation) - Set
environment: 'node'as default (override per-file for DOM tests) - Configure
includepattern:src/**/*.test.{js,ts}
Package scripts
Add to package.json:
"test": "vitest",
"test:ci": "vitest run" test runs in watch mode for development. test:ci runs once and exits for CI.
CI integration
Update .github/workflows/ci.yml to add test step before build:
- run: pnpm install --frozen-lockfile
- run: pnpm lint
- run: pnpm check
- run: pnpm test:ci
- run: pnpm build Smoke test
Create one minimal test file (src/lib/__tests__/smoke.test.js)
to verify the setup works end-to-end before writing real tests.
Dependencies to consider
@testing-library/svelte-- for component tests (can be added later in the component tests task)jsdomorhappy-dom-- for tests that need DOM APIs (scroll-to.js, component tests)
Read next