From 0bafcf7c96087b5a95af5fcf8f3b35b54d855344 Mon Sep 17 00:00:00 2001 From: Benjamin Gruenbaum Date: Mon, 1 May 2023 15:10:32 +0300 Subject: [PATCH 1/7] test: fix suite signal --- lib/internal/test_runner/test.js | 2 +- test/parallel/test-runner-misc.js | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/internal/test_runner/test.js b/lib/internal/test_runner/test.js index 1f888bc6277e27..70a19ba6b86486 100644 --- a/lib/internal/test_runner/test.js +++ b/lib/internal/test_runner/test.js @@ -761,7 +761,7 @@ class Suite extends Test { try { const { ctx, args } = this.getRunArgs(); this.buildSuite = PromisePrototypeThen( - PromiseResolve(this.runInAsyncScope(this.fn, ctx, args)), + PromiseResolve(this.runInAsyncScope(this.fn, ctx, ...args)), undefined, (err) => { this.fail(new ERR_TEST_FAILURE(err, kTestCodeFailure)); diff --git a/test/parallel/test-runner-misc.js b/test/parallel/test-runner-misc.js index 34abaf5c120be3..542da7afb5ad60 100644 --- a/test/parallel/test-runner-misc.js +++ b/test/parallel/test-runner-misc.js @@ -21,6 +21,14 @@ 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 + describe('Abort Signal in describe', common.mustCall(({ signal }) => { + it('Supports AbortSignal', () => { + assert.strictEqual(signal.aborted, false); + }); + })); } else assert.fail('unreachable'); } else { const child = spawnSync(process.execPath, [__filename, 'child', 'abortSignal']); From 10b3a0eb78652c891a0d22499a4c470497c2bf8b Mon Sep 17 00:00:00 2001 From: Benjamin Gruenbaum Date: Mon, 1 May 2023 15:49:27 +0300 Subject: [PATCH 2/7] fixup! --- lib/internal/test_runner/test.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/internal/test_runner/test.js b/lib/internal/test_runner/test.js index 70a19ba6b86486..53ce4386344b33 100644 --- a/lib/internal/test_runner/test.js +++ b/lib/internal/test_runner/test.js @@ -760,8 +760,10 @@ class Suite extends Test { try { const { ctx, args } = this.getRunArgs(); + const runArgs = ArrayPrototypeSlice(args); + ArrayPrototypeShift(runArgs, ctx); this.buildSuite = PromisePrototypeThen( - PromiseResolve(this.runInAsyncScope(this.fn, ctx, ...args)), + PromiseResolve(ReflectApply(this.runInAsyncScope, this.fn, runArgs)), undefined, (err) => { this.fail(new ERR_TEST_FAILURE(err, kTestCodeFailure)); From f7bb03315f49cdb0cfaf509b944afc61715728f5 Mon Sep 17 00:00:00 2001 From: Benjamin Gruenbaum Date: Mon, 1 May 2023 17:35:19 +0300 Subject: [PATCH 3/7] fixup! lint --- test/parallel/test-runner-misc.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/parallel/test-runner-misc.js b/test/parallel/test-runner-misc.js index 542da7afb5ad60..3b1de1fd725662 100644 --- a/test/parallel/test-runner-misc.js +++ b/test/parallel/test-runner-misc.js @@ -16,15 +16,16 @@ if (process.argv[2] === 'child') { let testSignal; test({ timeout: 10 }, common.mustCall(async ({ signal }) => { assert.strictEqual(signal.aborted, false); - testSignal = signal; + + Signal = signal; await setTimeout(50); })).finally(common.mustCall(() => { test(() => assert.strictEqual(testSignal.aborted, true)); })); - + //TODO(benjamingr) add more tests to describe + AbortSignal // this just tests the parameter is passed - describe('Abort Signal in describe', common.mustCall(({ signal }) => { + test.describe('Abort Signal in describe', common.mustCall(({ signal }) => { it('Supports AbortSignal', () => { assert.strictEqual(signal.aborted, false); }); From 6412f51f71e571edb3d061671af3e2470da864ab Mon Sep 17 00:00:00 2001 From: Benjamin Gruenbaum Date: Mon, 1 May 2023 18:03:14 +0300 Subject: [PATCH 4/7] fixup! lint --- test/parallel/test-runner-misc.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/parallel/test-runner-misc.js b/test/parallel/test-runner-misc.js index 3b1de1fd725662..70ca8954979305 100644 --- a/test/parallel/test-runner-misc.js +++ b/test/parallel/test-runner-misc.js @@ -16,17 +16,17 @@ if (process.argv[2] === 'child') { let testSignal; test({ timeout: 10 }, common.mustCall(async ({ signal }) => { assert.strictEqual(signal.aborted, false); - + testSignal = signal; Signal = signal; await setTimeout(50); })).finally(common.mustCall(() => { test(() => assert.strictEqual(testSignal.aborted, true)); })); - //TODO(benjamingr) add more tests to describe + AbortSignal + // TODO(benjamingr) add more tests to describe + AbortSignal // this just tests the parameter is passed test.describe('Abort Signal in describe', common.mustCall(({ signal }) => { - it('Supports AbortSignal', () => { + test.it('Supports AbortSignal', () => { assert.strictEqual(signal.aborted, false); }); })); From 57298d8ca4f058ba66cd2fc084c80ac862ba8fed Mon Sep 17 00:00:00 2001 From: Benjamin Gruenbaum Date: Mon, 1 May 2023 18:05:46 +0300 Subject: [PATCH 5/7] fixup! ai --- test/parallel/test-runner-misc.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/parallel/test-runner-misc.js b/test/parallel/test-runner-misc.js index 70ca8954979305..39424f814bce46 100644 --- a/test/parallel/test-runner-misc.js +++ b/test/parallel/test-runner-misc.js @@ -17,7 +17,6 @@ if (process.argv[2] === 'child') { test({ timeout: 10 }, common.mustCall(async ({ signal }) => { assert.strictEqual(signal.aborted, false); testSignal = signal; - Signal = signal; await setTimeout(50); })).finally(common.mustCall(() => { test(() => assert.strictEqual(testSignal.aborted, true)); From 9f38158f297e41ceb9eef1222171b44fd5567b61 Mon Sep 17 00:00:00 2001 From: Benjamin Gruenbaum Date: Tue, 2 May 2023 17:04:18 +0300 Subject: [PATCH 6/7] Update lib/internal/test_runner/test.js Co-authored-by: Antoine du Hamel --- lib/internal/test_runner/test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/internal/test_runner/test.js b/lib/internal/test_runner/test.js index 53ce4386344b33..b673a6831d530e 100644 --- a/lib/internal/test_runner/test.js +++ b/lib/internal/test_runner/test.js @@ -760,8 +760,8 @@ class Suite extends Test { try { const { ctx, args } = this.getRunArgs(); - const runArgs = ArrayPrototypeSlice(args); - ArrayPrototypeShift(runArgs, ctx); + const runArgs = [this.fn, ctx]; + ArrayPrototypePushApply(runArgs, args); this.buildSuite = PromisePrototypeThen( PromiseResolve(ReflectApply(this.runInAsyncScope, this.fn, runArgs)), undefined, From 0a0dc6e6606b046d86b0a59fd47ade90ebd8914e Mon Sep 17 00:00:00 2001 From: Moshe Atlow Date: Tue, 16 May 2023 23:28:52 +0300 Subject: [PATCH 7/7] fix --- lib/internal/test_runner/test.js | 3 +- .../test-runner/output/abort_suite.snapshot | 54 +++++++++++++++---- test/parallel/test-runner-misc.js | 2 +- 3 files changed, 48 insertions(+), 11 deletions(-) diff --git a/lib/internal/test_runner/test.js b/lib/internal/test_runner/test.js index b673a6831d530e..9c683d23976994 100644 --- a/lib/internal/test_runner/test.js +++ b/lib/internal/test_runner/test.js @@ -1,6 +1,7 @@ 'use strict'; const { ArrayPrototypePush, + ArrayPrototypePushApply, ArrayPrototypeReduce, ArrayPrototypeShift, ArrayPrototypeSlice, @@ -763,7 +764,7 @@ class Suite extends Test { const runArgs = [this.fn, ctx]; ArrayPrototypePushApply(runArgs, args); this.buildSuite = PromisePrototypeThen( - PromiseResolve(ReflectApply(this.runInAsyncScope, this.fn, runArgs)), + PromiseResolve(ReflectApply(this.runInAsyncScope, this, runArgs)), undefined, (err) => { this.fail(new ERR_TEST_FAILURE(err, kTestCodeFailure)); diff --git a/test/fixtures/test-runner/output/abort_suite.snapshot b/test/fixtures/test-runner/output/abort_suite.snapshot index 995e8512218bdb..e2abdadaf5a4b7 100644 --- a/test/fixtures/test-runner/output/abort_suite.snapshot +++ b/test/fixtures/test-runner/output/abort_suite.snapshot @@ -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 diff --git a/test/parallel/test-runner-misc.js b/test/parallel/test-runner-misc.js index 39424f814bce46..abc2715dcfba48 100644 --- a/test/parallel/test-runner-misc.js +++ b/test/parallel/test-runner-misc.js @@ -33,7 +33,7 @@ if (process.argv[2] === 'child') { } 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);