From fb3d90a986f2863fa89c329bfe23219c2317cb20 Mon Sep 17 00:00:00 2001 From: Filip Skokan Date: Thu, 24 Sep 2026 09:39:15 +0200 Subject: [PATCH] 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 Assisted-by: Codex PR-URL: https://github.com/nodejs/node/pull/66255 Reviewed-By: Aviv Keller Reviewed-By: Antoine du Hamel --- test/fixtures/test-runner/run-timeout.mjs | 11 +++++++++++ test/parallel/test-runner-run.mjs | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/test-runner/run-timeout.mjs diff --git a/test/fixtures/test-runner/run-timeout.mjs b/test/fixtures/test-runner/run-timeout.mjs new file mode 100644 index 00000000000..8367bd22b4c --- /dev/null +++ b/test/fixtures/test-runner/run-timeout.mjs @@ -0,0 +1,11 @@ +import test, { after } from 'node:test'; + +// Keep the event loop alive until both tests time out. +const interval = setInterval(() => {}, 1000); +after(() => clearInterval(interval)); + +test('pending promise', () => new Promise(() => {})); + +test('pending assertion plan', (t) => { + t.plan(1, { wait: true }); +}); diff --git a/test/parallel/test-runner-run.mjs b/test/parallel/test-runner-run.mjs index d1d384a522e..a973ecb7cb7 100644 --- a/test/parallel/test-runner-run.mjs +++ b/test/parallel/test-runner-run.mjs @@ -90,7 +90,7 @@ describe('require(\'node:test\').run', { concurrency: true }, () => { it('should support timeout', async () => { const stream = run({ timeout: 50, files: [ - fixtures.path('test-runner', 'plan', 'timeout-basic.mjs'), + fixtures.path('test-runner', 'run-timeout.mjs'), ] }); stream.on('test:fail', common.mustCall((data) => { assert.strictEqual(data.details.error.failureType, 'testTimeoutFailure');