Skip to content

Commit 48fbb00

Browse files
test: fix stability
1 parent cdcabb2 commit 48fbb00

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

test/server/setupExitSignals-option.test.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const port = require("../ports-map")["setup-exit-signals-option"];
77

88
describe("setupExitSignals option", () => {
99
let server;
10+
let doExit;
1011
let exitSpy;
1112
let stopCallbackSpy;
1213
let stdinResumeSpy;
@@ -26,7 +27,11 @@ describe("setupExitSignals option", () => {
2627

2728
await server.start();
2829

29-
exitSpy = jest.spyOn(process, "exit").mockImplementation(() => {});
30+
doExit = false;
31+
32+
exitSpy = jest.spyOn(process, "exit").mockImplementation(() => {
33+
doExit = true;
34+
});
3035
stdinResumeSpy = jest
3136
.spyOn(process.stdin, "resume")
3237
.mockImplementation(() => {});
@@ -44,14 +49,19 @@ describe("setupExitSignals option", () => {
4449
await server.stop();
4550
});
4651

47-
it.each(signals)("should close and exit on %s", (signal, done) => {
52+
it.each(signals)("should close and exit on %s", async (signal) => {
4853
process.emit(signal);
4954

50-
setTimeout(() => {
51-
expect(stopCallbackSpy.mock.calls.length).toEqual(1);
52-
expect(exitSpy.mock.calls.length).toEqual(1);
55+
await new Promise((resolve) => {
56+
const interval = setInterval(() => {
57+
if (doExit) {
58+
expect(stopCallbackSpy.mock.calls.length).toEqual(1);
5359

54-
done();
55-
}, 1000);
60+
clearInterval(interval);
61+
62+
resolve();
63+
}
64+
}, 100);
65+
});
5666
});
5767
});

0 commit comments

Comments
 (0)