Skip to content

Commit 2097ea7

Browse files
committed
fix: should catch process.kill error correctly
1 parent f83c7ef commit 2097ea7

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { dirname, join } from 'node:path';
22
import { fileURLToPath } from 'node:url';
3-
import { expect, it } from '@rstest/core';
3+
import { it } from '@rstest/core';
44
import { runRstestCli } from '../../scripts/';
55

66
const __filename = fileURLToPath(import.meta.url);
77

88
const __dirname = dirname(__filename);
9-
it('should catch `Worker exited unexpectedly` error correctly', async () => {
10-
const { cli } = await runRstestCli({
9+
it('should catch `process.kill` error correctly', async () => {
10+
const { cli, expectExecFailed, expectLog } = await runRstestCli({
1111
command: 'rstest',
1212
args: ['run', 'processKill.test.ts', '--disableConsoleIntercept'],
1313
options: {
@@ -16,10 +16,12 @@ it('should catch `Worker exited unexpectedly` error correctly', async () => {
1616
},
1717
},
1818
});
19-
await cli.exec;
20-
expect(cli.exec.process?.exitCode).toBe(1);
19+
await expectExecFailed();
2120

2221
const logs = cli.stdout.split('\n').filter(Boolean);
2322

24-
expect(logs.find((log) => log.includes('Test Files 1 failed'))).toBeDefined();
23+
expectLog('Test Files 1 failed', logs);
24+
25+
expectLog('FAIL processKill.test.ts > process.kill', logs);
26+
expectLog(/process.kill unexpectedly called/, logs);
2527
});

packages/core/src/runtime/worker/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,18 @@ const runInPool = async (
275275
throw new Error(`process.exit unexpectedly called with "${code}"`);
276276
};
277277

278+
const kill = process.kill.bind(process);
279+
process.kill = (pid, signal) => {
280+
if (pid === process.pid) {
281+
throw new Error(
282+
`process.kill unexpectedly called with "${pid}" and "${signal}"`,
283+
);
284+
}
285+
return kill(pid, signal);
286+
};
287+
278288
cleanups.push(() => {
289+
process.kill = kill;
279290
process.exit = exit;
280291
});
281292

0 commit comments

Comments
 (0)