import { SharedContext } from '@ava/cooperate'; import { PrismaClient } from '@prisma/client'; import { ExecutionContext } from 'ava'; import { Client } from 'pg'; import { database } from '../../database'; export type DBTestContext = { db: { client: PrismaClient, teardown: () => void, }, } const context = new SharedContext(__filename); // const client = new PrismaClient(); const lock = context.createLock('db-lock'); type DBContext = { client: PrismaClient, release: () => void; } export async function getDatabase(t: ExecutionContext) { const release = await lock.acquire(); t.context.db = { client: database, teardown: release, } }