Skip to content

Commit a64dbbc

Browse files
committed
CR
1 parent d57723d commit a64dbbc

File tree

7 files changed

+40
-26
lines changed

7 files changed

+40
-26
lines changed

lib/internal/test_runner/runner.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,14 @@ const { validateArray, validateBoolean } = require('internal/validators');
3636
const { getInspectPort, isUsingInspector, isInspectorMessage } = require('internal/util/inspector');
3737
const { kEmptyObject } = require('internal/util');
3838
const { createTestTree } = require('internal/test_runner/harness');
39-
const { kSubtestsFailed, kTestCodeFailure, kCancelledByParent, Test } = require('internal/test_runner/test');
39+
const {
40+
kAborted,
41+
kCancelledByParent,
42+
kSubtestsFailed,
43+
kTestCodeFailure,
44+
kTestTimeoutFailure,
45+
Test
46+
} = require('internal/test_runner/test');
4047
const { TapParser } = require('internal/test_runner/tap_parser');
4148
const { YAMLToJs } = require('internal/test_runner/yaml_to_js');
4249
const { TokenKind } = require('internal/test_runner/tap_lexer');
@@ -56,6 +63,9 @@ const kFilterArgs = ['--test', '--experimental-test-coverage', '--watch'];
5663
const kFilterArgValues = ['--test-reporter', '--test-reporter-destination'];
5764
const kDiagnosticsFilterArgs = ['tests', 'pass', 'fail', 'cancelled', 'skipped', 'todo', 'duration_ms'];
5865

66+
const kCanceledTests = new SafeSet()
67+
.add(kCancelledByParent).add(kAborted).add(kTestTimeoutFailure);
68+
5969
// TODO(cjihrig): Replace this with recursive readdir once it lands.
6070
function processPath(path, testFiles, options) {
6171
const stats = statSync(path);
@@ -182,7 +192,7 @@ class FileTest extends Test {
182192
}
183193

184194
const diagnostics = YAMLToJs(node.diagnostics);
185-
const cancelled = diagnostics.error?.failureType === kCancelledByParent;
195+
const cancelled = kCanceledTests.has(diagnostics.error?.failureType);
186196
const testNumber = nesting === 0 ? (Number(node.id) + this.testNumber - 1) : node.id;
187197
const method = pass ? 'ok' : 'fail';
188198
this.reporter[method](nesting, this.name, testNumber, node.description, diagnostics, directive);

lib/internal/test_runner/test.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ const { availableParallelism } = require('os');
5757
const { bigint: hrtime } = process.hrtime;
5858
const kCallbackAndPromisePresent = 'callbackAndPromisePresent';
5959
const kCancelledByParent = 'cancelledByParent';
60+
const kAborted = 'testAborted';
6061
const kParentAlreadyFinished = 'parentAlreadyFinished';
6162
const kSubtestsFailed = 'subtestsFailed';
6263
const kTestCodeFailure = 'testCodeFailure';
@@ -390,10 +391,12 @@ class Test extends AsyncResource {
390391
}
391392

392393
#abortHandler = () => {
393-
this.cancel(this.#outerSignal?.reason || new AbortError('The test was aborted'));
394+
const error = this.#outerSignal?.reason || new AbortError('The test was aborted');
395+
error.failureType = kAborted;
396+
this.#cancel(error);
394397
};
395398

396-
cancel(error) {
399+
#cancel(error) {
397400
if (this.endTime !== null) {
398401
return;
399402
}
@@ -404,7 +407,6 @@ class Test extends AsyncResource {
404407
kCancelledByParent
405408
)
406409
);
407-
this.error.failureType = kCancelledByParent;
408410
this.startTime = this.startTime || this.endTime; // If a test was canceled before it was started, e.g inside a hook
409411
this.cancelled = true;
410412
this.#abortController.abort();
@@ -471,7 +473,7 @@ class Test extends AsyncResource {
471473
return true;
472474
}
473475
if (this.#outerSignal?.aborted) {
474-
this.cancel(this.#outerSignal.reason || new AbortError('The test was aborted'));
476+
this.#abortHandler();
475477
return true;
476478
}
477479
}
@@ -564,7 +566,7 @@ class Test extends AsyncResource {
564566
try { await afterEach(); } catch { /* test is already failing, let's the error */ }
565567
if (isTestFailureError(err)) {
566568
if (err.failureType === kTestTimeoutFailure) {
567-
this.cancel(err);
569+
this.#cancel(err);
568570
} else {
569571
this.fail(err);
570572
}
@@ -617,7 +619,7 @@ class Test extends AsyncResource {
617619
const subtest = this.subtests[i];
618620

619621
if (!subtest.finished) {
620-
subtest.cancel(pendingSubtestsError);
622+
subtest.#cancel(pendingSubtestsError);
621623
subtest.postRun(pendingSubtestsError);
622624
}
623625
subtest.countSubtest(counters);
@@ -831,6 +833,8 @@ module.exports = {
831833
kCancelledByParent,
832834
kSubtestsFailed,
833835
kTestCodeFailure,
836+
kTestTimeoutFailure,
837+
kAborted,
834838
kUnwrapErrors,
835839
Suite,
836840
Test,

test/message/test_runner_abort.out

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ TAP version 13
4040
not ok 7 - not ok 3
4141
---
4242
duration_ms: *
43-
failureType: 'cancelledByParent'
43+
failureType: 'testAborted'
4444
error: 'This operation was aborted'
4545
code: 20
4646
stack: |-
@@ -59,7 +59,7 @@ TAP version 13
5959
not ok 8 - not ok 4
6060
---
6161
duration_ms: *
62-
failureType: 'cancelledByParent'
62+
failureType: 'testAborted'
6363
error: 'This operation was aborted'
6464
code: 20
6565
stack: |-
@@ -78,7 +78,7 @@ TAP version 13
7878
not ok 9 - not ok 5
7979
---
8080
duration_ms: *
81-
failureType: 'cancelledByParent'
81+
failureType: 'testAborted'
8282
error: 'This operation was aborted'
8383
code: 20
8484
stack: |-
@@ -97,7 +97,7 @@ TAP version 13
9797
not ok 1 - promise timeout signal
9898
---
9999
duration_ms: *
100-
failureType: 'cancelledByParent'
100+
failureType: 'testAborted'
101101
error: 'The operation was aborted due to timeout'
102102
code: 23
103103
stack: |-
@@ -110,7 +110,7 @@ not ok 1 - promise timeout signal
110110
not ok 2 - promise abort signal
111111
---
112112
duration_ms: *
113-
failureType: 'cancelledByParent'
113+
failureType: 'testAborted'
114114
error: 'This operation was aborted'
115115
code: 20
116116
stack: |-
@@ -165,7 +165,7 @@ not ok 2 - promise abort signal
165165
not ok 7 - not ok 3
166166
---
167167
duration_ms: *
168-
failureType: 'cancelledByParent'
168+
failureType: 'testAborted'
169169
error: 'This operation was aborted'
170170
code: 20
171171
stack: |-
@@ -184,7 +184,7 @@ not ok 2 - promise abort signal
184184
not ok 8 - not ok 4
185185
---
186186
duration_ms: *
187-
failureType: 'cancelledByParent'
187+
failureType: 'testAborted'
188188
error: 'This operation was aborted'
189189
code: 20
190190
stack: |-
@@ -203,7 +203,7 @@ not ok 2 - promise abort signal
203203
not ok 9 - not ok 5
204204
---
205205
duration_ms: *
206-
failureType: 'cancelledByParent'
206+
failureType: 'testAborted'
207207
error: 'This operation was aborted'
208208
code: 20
209209
stack: |-
@@ -222,7 +222,7 @@ not ok 2 - promise abort signal
222222
not ok 3 - callback timeout signal
223223
---
224224
duration_ms: *
225-
failureType: 'cancelledByParent'
225+
failureType: 'testAborted'
226226
error: 'The operation was aborted due to timeout'
227227
code: 23
228228
stack: |-
@@ -235,7 +235,7 @@ not ok 3 - callback timeout signal
235235
not ok 4 - callback abort signal
236236
---
237237
duration_ms: *
238-
failureType: 'cancelledByParent'
238+
failureType: 'testAborted'
239239
error: 'This operation was aborted'
240240
code: 20
241241
stack: |-

test/message/test_runner_abort_suite.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ TAP version 13
6464
not ok 1 - describe timeout signal
6565
---
6666
duration_ms: *
67-
failureType: 'cancelledByParent'
67+
failureType: 'testAborted'
6868
error: 'The operation was aborted due to timeout'
6969
code: 23
7070
stack: |-
@@ -77,7 +77,7 @@ not ok 1 - describe timeout signal
7777
not ok 2 - describe abort signal
7878
---
7979
duration_ms: *
80-
failureType: 'cancelledByParent'
80+
failureType: 'testAborted'
8181
error: 'This operation was aborted'
8282
code: 20
8383
stack: |-

test/message/test_runner_describe_it.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ not ok 55 - describe async throw fails
548548
not ok 1 - timed out async test
549549
---
550550
duration_ms: *
551-
failureType: 'cancelledByParent'
551+
failureType: 'testTimeoutFailure'
552552
error: 'test timed out after 5ms'
553553
code: 'ERR_TEST_FAILURE'
554554
stack: |-
@@ -558,7 +558,7 @@ not ok 55 - describe async throw fails
558558
not ok 2 - timed out callback test
559559
---
560560
duration_ms: *
561-
failureType: 'cancelledByParent'
561+
failureType: 'testTimeoutFailure'
562562
error: 'test timed out after 5ms'
563563
code: 'ERR_TEST_FAILURE'
564564
...

test/message/test_runner_output.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -561,15 +561,15 @@ not ok 56 - subtest sync throw fails
561561
not ok 57 - timed out async test
562562
---
563563
duration_ms: *
564-
failureType: 'cancelledByParent'
564+
failureType: 'testTimeoutFailure'
565565
error: 'test timed out after 5ms'
566566
code: 'ERR_TEST_FAILURE'
567567
...
568568
# Subtest: timed out callback test
569569
not ok 58 - timed out callback test
570570
---
571571
duration_ms: *
572-
failureType: 'cancelledByParent'
572+
failureType: 'testTimeoutFailure'
573573
error: 'test timed out after 5ms'
574574
code: 'ERR_TEST_FAILURE'
575575
...

test/message/test_runner_output_cli.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -561,15 +561,15 @@ not ok 56 - subtest sync throw fails
561561
not ok 57 - timed out async test
562562
---
563563
duration_ms: *
564-
failureType: 'cancelledByParent'
564+
failureType: 'testTimeoutFailure'
565565
error: 'test timed out after 5ms'
566566
code: 'ERR_TEST_FAILURE'
567567
...
568568
# Subtest: timed out callback test
569569
not ok 58 - timed out callback test
570570
---
571571
duration_ms: *
572-
failureType: 'cancelledByParent'
572+
failureType: 'testTimeoutFailure'
573573
error: 'test timed out after 5ms'
574574
code: 'ERR_TEST_FAILURE'
575575
...

0 commit comments

Comments
 (0)