Skip to content

Commit 873841f

Browse files
committed
unify mock db seeding approach
1 parent 014ccf4 commit 873841f

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

app/mocks/browser.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ import { handlers } from "./evolver";
33
import { seedDatabase } from "./db-data";
44

55
// Initialize the test database with seed data
6+
// Since the DB mock is a singleton, we can just call this once
67
if (process.env.NODE_ENV === "test") {
78
seedDatabase();
89
}
910

11+
// see app/entry.client.ts for the worker.start() call
1012
export const worker = setupWorker(...handlers);

app/mocks/db-data.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export const db = factory({
1818
});
1919

2020
// Seed the database with initial data
21+
2122
export function seedDatabase() {
2223
// Clear any existing data
2324
drop(db);
@@ -30,6 +31,3 @@ export function seedDatabase() {
3031
name: TEST_DEVICE_NAME,
3132
});
3233
}
33-
34-
// Initialize the database
35-
seedDatabase();

app/mocks/server.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import { setupServer } from "msw/node";
22
import { handlers } from "./evolver";
33

4+
import { seedDatabase } from "./db-data";
5+
6+
// Initialize the test database with seed data
7+
// Since the DB mock is a singleton, we can just call this once
8+
if (process.env.NODE_ENV === "test") {
9+
seedDatabase();
10+
}
411
// Note: not included here because it's not a HTTP mock - but to be aware of:
512
// the DB is mocked using the prisma mock, see app/utils/db.server.ts
613
export const server = setupServer(...handlers);

0 commit comments

Comments
 (0)