UNPKG

vitest-mms

Version:

mongodb-memory-server integration for vitest

22 lines (19 loc) 503 B
import { randomUUID } from 'node:crypto'; import { afterAll, test, inject } from 'vitest'; import { createConnection } from 'mongoose'; let connection; afterAll(async () => { if (connection) { await connection.close(); } }); const mmsTest = test.extend({ connection: async ({}, use) => { if (!connection) { const uri = inject("MONGO_URI"); connection = await createConnection(uri).asPromise(); } await use(connection.useDb(randomUUID())); } }); export { mmsTest };