Skip to content

Commit 1c4b14d

Browse files
author
vikrantsingh22
committed
Initialize-all-the-test-data-in-setup.js-using-spawn
1 parent 186eb66 commit 1c4b14d

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

test/config/setup.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,30 @@
1+
import { spawn } from "child_process";
12
import request from "supertest";
23
import app from "#app"; // Update this import based on your app"s structure
34
import connector from "#models/databaseUtil"; // Update this import
45

56
const server = app.listen(null, () => {
6-
connector.set("debug", false);
7+
connector.set("debug", false);
78
});
89
const agent = request.agent(server);
10+
11+
const child = spawn("node", ["./misc/initDB"]);
12+
child.stdout.on("data", (data) => {
13+
console.log(`stdout: ${data}`);
14+
});
15+
child.stderr.on("data", (data) => {
16+
console.log(`stderr: ${data}`);
17+
});
18+
child.stdout.on("error", (error) => {
19+
console.log(`error: ${error.message}`);
20+
});
21+
child.on("exit", (code, signal) => {
22+
if (code) console.log(`Process exit with code: ${code}`);
23+
if (signal) console.log(`Process killed with signal: ${signal}`);
24+
});
925
global.server = server;
1026
global.agent = agent;
1127
export default async () => {
12-
global.server = server;
13-
global.agent = agent;
14-
};
28+
global.server = server;
29+
global.agent = agent;
30+
};

0 commit comments

Comments
 (0)