Skip to content

Commit

Permalink
fix: drop database after each test
Browse files Browse the repository at this point in the history
  • Loading branch information
danielpza committed Sep 7, 2024
1 parent bf75cb9 commit b886a67
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/setupFile.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Db, MongoClient } from "mongodb";
import { afterAll, beforeAll, beforeEach, inject } from "vitest";
import { afterAll, afterEach, beforeAll, beforeEach, inject } from "vitest";
// hack to keep imported vitest types
export type { TestContext } from "vitest";
// hack to fix pnpm build issue
Expand Down Expand Up @@ -29,5 +29,10 @@ afterAll(async () => {

beforeEach(async (context) => {
const db = mongoClient.db(randomUUID());
Object.assign(context, { mongoClient, db });
context.db = db;
context.mongoClient = mongoClient;
});

afterEach(async (context) => {
await context.db.dropDatabase();
});

0 comments on commit b886a67

Please sign in to comment.