Skip to content

Commit 89a9914

Browse files
committed
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.
1 parent 9bc369f commit 89a9914

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

test/parallel/test-runner-misc.js

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,43 @@ if (process.argv[2] === 'child') {
2222
test(() => assert.strictEqual(testSignal.aborted, true));
2323
}));
2424

25-
// TODO(benjamingr) add more tests to describe + AbortSignal
26-
// this just tests the parameter is passed
2725
test.describe('Abort Signal in describe', common.mustCall(({ signal }) => {
2826
test.it('Supports AbortSignal', common.mustCall(() => {
2927
assert.strictEqual(signal.aborted, false);
3028
}));
3129
}));
30+
31+
let describeSignal;
32+
test.describe('describe signal timeout', { timeout: 10 }, common.mustCall(async ({ signal }) => {
33+
await test.it('nested it timeout', common.mustCall(async (t) => {
34+
assert.strictEqual(t.signal.aborted, false);
35+
describeSignal = t.signal;
36+
await setTimeout(50);
37+
}));
38+
}));
39+
40+
test(() => assert.strictEqual(describeSignal.aborted, true));
41+
42+
let manualAbortSignal;
43+
test.describe('describe signal manual abort', common.mustCall((t) => {
44+
const controller = new AbortController();
45+
t.signal.addEventListener('abort', () => controller.abort());
46+
47+
return test.it('nested manual abort', { signal: controller.signal }, common.mustCall(async (t) => {
48+
assert.strictEqual(t.signal.aborted, false);
49+
manualAbortSignal = t.signal;
50+
controller.abort();
51+
await setTimeout(50);
52+
}));
53+
}));
54+
test(() => assert.strictEqual(manualAbortSignal.aborted, true));
3255
} else assert.fail('unreachable');
3356
} else {
3457
const child = spawnSync(process.execPath, [__filename, 'child', 'abortSignal']);
3558
const stdout = child.stdout.toString();
36-
assert.match(stdout, /pass 2$/m);
59+
assert.match(stdout, /pass 4$/m);
3760
assert.match(stdout, /fail 0$/m);
38-
assert.match(stdout, /cancelled 1$/m);
61+
assert.match(stdout, /cancelled 3$/m);
3962
assert.strictEqual(child.status, 1);
4063
assert.strictEqual(child.signal, null);
4164
}

0 commit comments

Comments
 (0)