Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions e2e/runner/test/processKill.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { expect, it } from '@rstest/core';
import { it } from '@rstest/core';
import { runRstestCli } from '../../scripts/';

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

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

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

expect(logs.find((log) => log.includes('Test Files 1 failed'))).toBeDefined();
expectLog('Test Files 1 failed', logs);

expectLog('FAIL processKill.test.ts > process.kill', logs);
expectLog(/process.kill unexpectedly called/, logs);
});
11 changes: 11 additions & 0 deletions packages/core/src/runtime/worker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,18 @@ const runInPool = async (
throw new Error(`process.exit unexpectedly called with "${code}"`);
};

const kill = process.kill.bind(process);
process.kill = (pid: number, signal?: NodeJS.Signals) => {
if (pid === -1 || Math.abs(pid) === process.pid) {
throw new Error(
`process.kill unexpectedly called with "${pid}" and "${signal}"`,
);
}
return kill(pid, signal);
};

cleanups.push(() => {
process.kill = kill;
process.exit = exit;
});

Expand Down
Loading