Global setup is a file where you can add logic that you want to run before your test starts running. I can be spinning up a database, connecting to external services and anything that absolutely must be running during the test.
import path from 'node:path'
import { execaCommand } from 'execa'
import fsExtra from 'fs-extra'
export const BASE_DATABASE_PATH = path.join(
process.cwd(),
'./tests/prisma/base.db',
)
export async function setup() {
const exists = await fsExtra.pathExists(BASE_DATABASE_PATH)
if (exists) return
await execaCommand(
'prisma migrate reset --force --skip-seed --skip-generate',
{
stdio: 'inherit',
env: { ...process.env, DATABASE_URL: `file:${BASE_DATABASE_PATH}` },
},
)
}