$env
in Playwright tests for SvelteKit.The following is needed to mock the $env
module.
Add the following to tsconfig.json
// Everything below is required for Playwright tests to access path aliases
"baseUrl": ".",
"paths": {
"$lib": ["src/lib"],
"$lib/*": ["src/lib/*"],
"$env/*": ["tests/e2e/mocks/env/*"]
}
Set testDir
in playwright.config.ts to 'tests/e2e'
.
Mock $env/dynamic/private
by adding the file tests/e2e/mocks/env/dynamic/private.ts
and export a env
const.
E.g.
export const env = process.env
$env
in your testsnpm i
npm run build
HELLO=WORLD npm run test:integration