Skip to content

Commit 6e44cbb

Browse files
9aoyCopilot
andauthored
chore: remove SIGTERM event handler (#680)
Co-authored-by: Copilot <[email protected]>
1 parent 8ac9a4d commit 6e44cbb

File tree

3 files changed

+27
-23
lines changed

3 files changed

+27
-23
lines changed
Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
import { join } from 'node:path';
2-
import { expect, it } from '@rstest/core';
2+
import { it } from '@rstest/core';
33
import { runRstestCli } from '../../scripts/';
44

5-
it('should exit correctly when signal listener exists', async () => {
6-
const { cli, expectExecSuccess } = await runRstestCli({
7-
command: 'rstest',
8-
args: ['run', 'signalListener.test.ts'],
9-
options: {
10-
nodeOptions: {
11-
cwd: join(__dirname, 'fixtures'),
5+
it.skipIf(process.platform === 'win32')(
6+
'should catch signal exit correctly when signal listener exists',
7+
async () => {
8+
const { expectExecFailed, expectLog } = await runRstestCli({
9+
command: 'rstest',
10+
args: ['run', 'signalListener.test.ts'],
11+
options: {
12+
nodeOptions: {
13+
cwd: join(__dirname, 'fixtures'),
14+
},
1215
},
13-
},
14-
});
15-
await expectExecSuccess();
16+
});
17+
await expectExecFailed();
1618

17-
const logs = cli.stdout.split('\n').filter(Boolean);
18-
19-
expect(logs.find((log) => log.includes('Test Files 1 passed'))).toBeDefined();
20-
});
19+
expectLog(/Rstest exited unexpectedly with code 0/);
20+
},
21+
);

packages/core/src/core/runTests.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,8 +448,19 @@ export async function runTests(context: Rstest): Promise<void> {
448448
afterTestsWatchRun();
449449
});
450450
} else {
451+
const unExpectedExit = (code?: number) => {
452+
logger.log(
453+
color.red(
454+
`Rstest exited unexpectedly with code ${code}, terminating test run.`,
455+
),
456+
);
457+
process.exitCode = 1;
458+
};
459+
process.on('exit', unExpectedExit);
460+
451461
await run();
452462
await pool.close();
453463
await closeServer();
464+
process.off('exit', unExpectedExit);
454465
}
455466
}

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,6 @@ const loadFiles = async ({
247247
});
248248
};
249249

250-
const onExit = () => {
251-
process.exit();
252-
};
253-
254250
const runInPool = async (
255251
options: RunWorkerOptions['options'],
256252
): Promise<
@@ -294,15 +290,11 @@ const runInPool = async (
294290
process.exit = exit;
295291
});
296292

297-
process.off('SIGTERM', onExit);
298-
299293
const teardown = async () => {
300294
await new Promise((resolve) => getRealTimers().setTimeout!(resolve));
301295

302296
await Promise.all(cleanups.map((fn) => fn()));
303297
isTeardown = true;
304-
// should exit correctly when user's signal listener exists
305-
process.once('SIGTERM', onExit);
306298
};
307299

308300
if (type === 'collect') {

0 commit comments

Comments
 (0)