Skip to content

Commit 7b816b4

Browse files
benjamingrMoLow
authored andcommitted
test: fix suite signal
PR-URL: #47800 Fixes: #47882 Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
1 parent ca4a0e3 commit 7b816b4

File tree

3 files changed

+58
-11
lines changed

3 files changed

+58
-11
lines changed

lib/internal/test_runner/test.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22
const {
33
ArrayPrototypePush,
4+
ArrayPrototypePushApply,
45
ArrayPrototypeReduce,
56
ArrayPrototypeShift,
67
ArrayPrototypeSlice,
@@ -760,8 +761,10 @@ class Suite extends Test {
760761

761762
try {
762763
const { ctx, args } = this.getRunArgs();
764+
const runArgs = [this.fn, ctx];
765+
ArrayPrototypePushApply(runArgs, args);
763766
this.buildSuite = PromisePrototypeThen(
764-
PromiseResolve(this.runInAsyncScope(this.fn, ctx, args)),
767+
PromiseResolve(ReflectApply(this.runInAsyncScope, this, runArgs)),
765768
undefined,
766769
(err) => {
767770
this.fail(new ERR_TEST_FAILURE(err, kTestCodeFailure));

test/fixtures/test-runner/output/abort_suite.snapshot

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,25 +40,61 @@ TAP version 13
4040
not ok 7 - not ok 3
4141
---
4242
duration_ms: ZERO
43-
failureType: 'cancelledByParent'
44-
error: 'test did not finish before its parent and was cancelled'
45-
code: 'ERR_TEST_FAILURE'
43+
failureType: 'testAborted'
44+
error: 'This operation was aborted'
45+
code: 20
46+
name: 'AbortError'
47+
stack: |-
48+
*
49+
*
50+
*
51+
*
52+
*
53+
*
54+
*
55+
*
56+
*
57+
*
4658
...
4759
# Subtest: not ok 4
4860
not ok 8 - not ok 4
4961
---
5062
duration_ms: ZERO
51-
failureType: 'cancelledByParent'
52-
error: 'test did not finish before its parent and was cancelled'
53-
code: 'ERR_TEST_FAILURE'
63+
failureType: 'testAborted'
64+
error: 'This operation was aborted'
65+
code: 20
66+
name: 'AbortError'
67+
stack: |-
68+
*
69+
*
70+
*
71+
*
72+
*
73+
*
74+
*
75+
*
76+
*
77+
*
5478
...
5579
# Subtest: not ok 5
5680
not ok 9 - not ok 5
5781
---
5882
duration_ms: ZERO
59-
failureType: 'cancelledByParent'
60-
error: 'test did not finish before its parent and was cancelled'
61-
code: 'ERR_TEST_FAILURE'
83+
failureType: 'testAborted'
84+
error: 'This operation was aborted'
85+
code: 20
86+
name: 'AbortError'
87+
stack: |-
88+
*
89+
*
90+
*
91+
*
92+
*
93+
*
94+
*
95+
*
96+
*
97+
*
6298
...
6399
1..9
64100
not ok 1 - describe timeout signal

test/parallel/test-runner-misc.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,19 @@ if (process.argv[2] === 'child') {
2121
})).finally(common.mustCall(() => {
2222
test(() => assert.strictEqual(testSignal.aborted, true));
2323
}));
24+
25+
// TODO(benjamingr) add more tests to describe + AbortSignal
26+
// this just tests the parameter is passed
27+
test.describe('Abort Signal in describe', common.mustCall(({ signal }) => {
28+
test.it('Supports AbortSignal', () => {
29+
assert.strictEqual(signal.aborted, false);
30+
});
31+
}));
2432
} else assert.fail('unreachable');
2533
} else {
2634
const child = spawnSync(process.execPath, [__filename, 'child', 'abortSignal']);
2735
const stdout = child.stdout.toString();
28-
assert.match(stdout, /^# pass 1$/m);
36+
assert.match(stdout, /^# pass 2$/m);
2937
assert.match(stdout, /^# fail 0$/m);
3038
assert.match(stdout, /^# cancelled 1$/m);
3139
assert.strictEqual(child.status, 1);

0 commit comments

Comments
 (0)