Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix suite signal #47800

Merged
merged 7 commits into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/internal/test_runner/test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';
const {
ArrayPrototypePush,
ArrayPrototypePushApply,
ArrayPrototypeReduce,
ArrayPrototypeShift,
ArrayPrototypeSlice,
Expand Down Expand Up @@ -760,8 +761,10 @@ class Suite extends Test {

try {
const { ctx, args } = this.getRunArgs();
const runArgs = [this.fn, ctx];
ArrayPrototypePushApply(runArgs, args);
this.buildSuite = PromisePrototypeThen(
PromiseResolve(this.runInAsyncScope(this.fn, ctx, args)),
PromiseResolve(ReflectApply(this.runInAsyncScope, this, runArgs)),
undefined,
(err) => {
this.fail(new ERR_TEST_FAILURE(err, kTestCodeFailure));
Expand Down
54 changes: 45 additions & 9 deletions test/fixtures/test-runner/output/abort_suite.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,61 @@ TAP version 13
not ok 7 - not ok 3
---
duration_ms: ZERO
failureType: 'cancelledByParent'
error: 'test did not finish before its parent and was cancelled'
code: 'ERR_TEST_FAILURE'
failureType: 'testAborted'
error: 'This operation was aborted'
code: 20
name: 'AbortError'
stack: |-
*
*
*
*
*
*
*
*
*
*
...
# Subtest: not ok 4
not ok 8 - not ok 4
---
duration_ms: ZERO
failureType: 'cancelledByParent'
error: 'test did not finish before its parent and was cancelled'
code: 'ERR_TEST_FAILURE'
failureType: 'testAborted'
error: 'This operation was aborted'
code: 20
name: 'AbortError'
stack: |-
*
*
*
*
*
*
*
*
*
*
...
# Subtest: not ok 5
not ok 9 - not ok 5
---
duration_ms: ZERO
failureType: 'cancelledByParent'
error: 'test did not finish before its parent and was cancelled'
code: 'ERR_TEST_FAILURE'
failureType: 'testAborted'
error: 'This operation was aborted'
code: 20
name: 'AbortError'
stack: |-
*
*
*
*
*
*
*
*
*
*
...
1..9
not ok 1 - describe timeout signal
Expand Down
10 changes: 9 additions & 1 deletion test/parallel/test-runner-misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,19 @@ if (process.argv[2] === 'child') {
})).finally(common.mustCall(() => {
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', () => {
assert.strictEqual(signal.aborted, false);
});
}));
} else assert.fail('unreachable');
} else {
const child = spawnSync(process.execPath, [__filename, 'child', 'abortSignal']);
const stdout = child.stdout.toString();
assert.match(stdout, /^# pass 1$/m);
assert.match(stdout, /^# pass 2$/m);
assert.match(stdout, /^# fail 0$/m);
assert.match(stdout, /^# cancelled 1$/m);
assert.strictEqual(child.status, 1);
Expand Down