From 89a9914ccc596c609f59c699529a6d964e2bd585 Mon Sep 17 00:00:00 2001 From: sangwook Date: Sat, 7 Feb 2026 07:13:26 +0900 Subject: [PATCH] test: add describe abort signal tests Adds tests to verify AbortSignal behavior in describe blocks, including timeout aborts, nested signal propagation, and manual abort triggering. Removes the TODO comment in test-runner-misc.js. --- test/parallel/test-runner-misc.js | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/test/parallel/test-runner-misc.js b/test/parallel/test-runner-misc.js index 435118c2cbbcde..414a88ea303ac4 100644 --- a/test/parallel/test-runner-misc.js +++ b/test/parallel/test-runner-misc.js @@ -22,20 +22,43 @@ if (process.argv[2] === 'child') { test(() => assert.strictEqual(testSignal.aborted, true)); })); - // TODO(benjamingr) add more tests to describe + AbortSignal - // this just tests the parameter is passed test.describe('Abort Signal in describe', common.mustCall(({ signal }) => { test.it('Supports AbortSignal', common.mustCall(() => { assert.strictEqual(signal.aborted, false); })); })); + + let describeSignal; + test.describe('describe signal timeout', { timeout: 10 }, common.mustCall(async ({ signal }) => { + await test.it('nested it timeout', common.mustCall(async (t) => { + assert.strictEqual(t.signal.aborted, false); + describeSignal = t.signal; + await setTimeout(50); + })); + })); + + test(() => assert.strictEqual(describeSignal.aborted, true)); + + let manualAbortSignal; + test.describe('describe signal manual abort', common.mustCall((t) => { + const controller = new AbortController(); + t.signal.addEventListener('abort', () => controller.abort()); + + return test.it('nested manual abort', { signal: controller.signal }, common.mustCall(async (t) => { + assert.strictEqual(t.signal.aborted, false); + manualAbortSignal = t.signal; + controller.abort(); + await setTimeout(50); + })); + })); + test(() => assert.strictEqual(manualAbortSignal.aborted, true)); } else assert.fail('unreachable'); } else { const child = spawnSync(process.execPath, [__filename, 'child', 'abortSignal']); const stdout = child.stdout.toString(); - assert.match(stdout, /pass 2$/m); + assert.match(stdout, /pass 4$/m); assert.match(stdout, /fail 0$/m); - assert.match(stdout, /cancelled 1$/m); + assert.match(stdout, /cancelled 3$/m); assert.strictEqual(child.status, 1); assert.strictEqual(child.signal, null); }