Skip to content

Commit 57e05c8

Browse files
author
vikrantsingh22
committed
Fixed the error while closing the child process
1 parent 1c4b14d commit 57e05c8

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

test/config/setup.js

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,11 @@ const server = app.listen(null, () => {
99
const agent = request.agent(server);
1010

1111
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-
});
2512
global.server = server;
2613
global.agent = agent;
14+
global.child = child;
2715
export default async () => {
2816
global.server = server;
2917
global.agent = agent;
18+
global.child = child;
3019
};

test/config/teardown.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1+
const teardownProcess = () => {
2+
global.child.kill();
3+
};
4+
15
global.server.close();
26
global.agent.app.close();
3-
export default async () => {
4-
};
7+
global.child.stdin.end();
8+
global.child.stdout.destroy();
9+
global.child.stderr.destroy();
10+
setTimeout(teardownProcess, 500);
11+
export default async () => {};

0 commit comments

Comments
 (0)