Skip to content

Commit a373d46

Browse files
committed
test: deflake test runner timeout coverage
Use a dedicated fixture with a pending promise and assertion plan instead of competing assertion timers. Keep both timeout failure assertions and clear the keepalive interval after the tests finish. Signed-off-by: Filip Skokan <panva.ip@gmail.com> Assisted-by: Codex
1 parent ef8437d commit a373d46

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import test, { after } from 'node:test';
2+
3+
// Keep the event loop alive until both tests time out.
4+
const interval = setInterval(() => {}, 1000);
5+
after(() => clearInterval(interval));
6+
7+
test('pending promise', () => new Promise(() => {}));
8+
9+
test('pending assertion plan', (t) => {
10+
t.plan(1, { wait: true });
11+
});

‎test/parallel/test-runner-run.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ describe('require(\'node:test\').run', { concurrency: true }, () => {
9090

9191
it('should support timeout', async () => {
9292
const stream = run({ timeout: 50, files: [
93-
fixtures.path('test-runner', 'plan', 'timeout-basic.mjs'),
93+
fixtures.path('test-runner', 'run-timeout.mjs'),
9494
] });
9595
stream.on('test:fail', common.mustCall((data) => {
9696
assert.strictEqual(data.details.error.failureType, 'testTimeoutFailure');

0 commit comments

Comments
 (0)