I'm trying to run playwright tests for my SvelteKit app where I create a new database for each test suite run. I set the environment variables in a test setup file like this:
import { exec as baseExec } from 'child_process';import util from 'util';import { test as setup } from '@playwright/test';import { uid } from 'uid';const exec = util.promisify(baseExec);setup('create new database', async ({}) => { // Vite replaces dot notation // https://github.com/vitejs/vite/issues/3176 // eslint-disable-next-line @typescript-eslint/dot-notation process.env['DATABASE_URL'] = `file:e2e/${uid()}.db`; await exec('npm run db:push -- --force');});
I am able to read process.env in the teardown file, but the tests themselves still use the database url set in my .env file. My database is setup like this:
import { createClient } from '@libsql/client';import { drizzle } from 'drizzle-orm/libsql';import { env } from '$env/dynamic/private';if (env.DATABASE_URL == null) { throw new Error('DATABASE_URL is not set');}const client = createClient({ url: env.DATABASE_URL });export const db = drizzle({ client, casing: 'snake_case' });
How do I get the tests to use the database created in the setup file?