test: fix suite signal

PR-URL: https://github.com/nodejs/node/pull/47800
Fixes: https://github.com/nodejs/node/issues/47882
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
Benjamin Gruenbaum 2023-05-17 11:57:21 +03:00 committed by GitHub
parent 5cb5422b6f
commit 3cf05be50e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 58 additions and 11 deletions

View File

@ -1,6 +1,7 @@
'use strict'; 'use strict';
const { const {
ArrayPrototypePush, ArrayPrototypePush,
ArrayPrototypePushApply,
ArrayPrototypeReduce, ArrayPrototypeReduce,
ArrayPrototypeShift, ArrayPrototypeShift,
ArrayPrototypeSlice, ArrayPrototypeSlice,
@ -760,8 +761,10 @@ class Suite extends Test {
try { try {
const { ctx, args } = this.getRunArgs(); const { ctx, args } = this.getRunArgs();
const runArgs = [this.fn, ctx];
ArrayPrototypePushApply(runArgs, args);
this.buildSuite = PromisePrototypeThen( this.buildSuite = PromisePrototypeThen(
PromiseResolve(this.runInAsyncScope(this.fn, ctx, args)), PromiseResolve(ReflectApply(this.runInAsyncScope, this, runArgs)),
undefined, undefined,
(err) => { (err) => {
this.fail(new ERR_TEST_FAILURE(err, kTestCodeFailure)); this.fail(new ERR_TEST_FAILURE(err, kTestCodeFailure));

View File

@ -40,25 +40,61 @@ TAP version 13
not ok 7 - not ok 3 not ok 7 - not ok 3
--- ---
duration_ms: ZERO duration_ms: ZERO
failureType: 'cancelledByParent' failureType: 'testAborted'
error: 'test did not finish before its parent and was cancelled' error: 'This operation was aborted'
code: 'ERR_TEST_FAILURE' code: 20
name: 'AbortError'
stack: |-
*
*
*
*
*
*
*
*
*
*
... ...
# Subtest: not ok 4 # Subtest: not ok 4
not ok 8 - not ok 4 not ok 8 - not ok 4
--- ---
duration_ms: ZERO duration_ms: ZERO
failureType: 'cancelledByParent' failureType: 'testAborted'
error: 'test did not finish before its parent and was cancelled' error: 'This operation was aborted'
code: 'ERR_TEST_FAILURE' code: 20
name: 'AbortError'
stack: |-
*
*
*
*
*
*
*
*
*
*
... ...
# Subtest: not ok 5 # Subtest: not ok 5
not ok 9 - not ok 5 not ok 9 - not ok 5
--- ---
duration_ms: ZERO duration_ms: ZERO
failureType: 'cancelledByParent' failureType: 'testAborted'
error: 'test did not finish before its parent and was cancelled' error: 'This operation was aborted'
code: 'ERR_TEST_FAILURE' code: 20
name: 'AbortError'
stack: |-
*
*
*
*
*
*
*
*
*
*
... ...
1..9 1..9
not ok 1 - describe timeout signal not ok 1 - describe timeout signal

View File

@ -21,11 +21,19 @@ if (process.argv[2] === 'child') {
})).finally(common.mustCall(() => { })).finally(common.mustCall(() => {
test(() => assert.strictEqual(testSignal.aborted, true)); 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 assert.fail('unreachable');
} else { } else {
const child = spawnSync(process.execPath, [__filename, 'child', 'abortSignal']); const child = spawnSync(process.execPath, [__filename, 'child', 'abortSignal']);
const stdout = child.stdout.toString(); 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, /^# fail 0$/m);
assert.match(stdout, /^# cancelled 1$/m); assert.match(stdout, /^# cancelled 1$/m);
assert.strictEqual(child.status, 1); assert.strictEqual(child.status, 1);