From a64dbbcec702983c36d1e88594ba6cfd5e450df1 Mon Sep 17 00:00:00 2001 From: Moshe Atlow Date: Tue, 14 Feb 2023 11:26:32 +0200 Subject: [PATCH] CR --- lib/internal/test_runner/runner.js | 14 ++++++++++++-- lib/internal/test_runner/test.js | 16 ++++++++++------ test/message/test_runner_abort.out | 20 ++++++++++---------- test/message/test_runner_abort_suite.out | 4 ++-- test/message/test_runner_describe_it.out | 4 ++-- test/message/test_runner_output.out | 4 ++-- test/message/test_runner_output_cli.out | 4 ++-- 7 files changed, 40 insertions(+), 26 deletions(-) diff --git a/lib/internal/test_runner/runner.js b/lib/internal/test_runner/runner.js index 0227500dc67fb8..ab423cad6ba6ac 100644 --- a/lib/internal/test_runner/runner.js +++ b/lib/internal/test_runner/runner.js @@ -36,7 +36,14 @@ const { validateArray, validateBoolean } = require('internal/validators'); const { getInspectPort, isUsingInspector, isInspectorMessage } = require('internal/util/inspector'); const { kEmptyObject } = require('internal/util'); const { createTestTree } = require('internal/test_runner/harness'); -const { kSubtestsFailed, kTestCodeFailure, kCancelledByParent, Test } = require('internal/test_runner/test'); +const { + kAborted, + kCancelledByParent, + kSubtestsFailed, + kTestCodeFailure, + kTestTimeoutFailure, + Test +} = require('internal/test_runner/test'); const { TapParser } = require('internal/test_runner/tap_parser'); const { YAMLToJs } = require('internal/test_runner/yaml_to_js'); const { TokenKind } = require('internal/test_runner/tap_lexer'); @@ -56,6 +63,9 @@ const kFilterArgs = ['--test', '--experimental-test-coverage', '--watch']; const kFilterArgValues = ['--test-reporter', '--test-reporter-destination']; const kDiagnosticsFilterArgs = ['tests', 'pass', 'fail', 'cancelled', 'skipped', 'todo', 'duration_ms']; +const kCanceledTests = new SafeSet() + .add(kCancelledByParent).add(kAborted).add(kTestTimeoutFailure); + // TODO(cjihrig): Replace this with recursive readdir once it lands. function processPath(path, testFiles, options) { const stats = statSync(path); @@ -182,7 +192,7 @@ class FileTest extends Test { } const diagnostics = YAMLToJs(node.diagnostics); - const cancelled = diagnostics.error?.failureType === kCancelledByParent; + const cancelled = kCanceledTests.has(diagnostics.error?.failureType); const testNumber = nesting === 0 ? (Number(node.id) + this.testNumber - 1) : node.id; const method = pass ? 'ok' : 'fail'; this.reporter[method](nesting, this.name, testNumber, node.description, diagnostics, directive); diff --git a/lib/internal/test_runner/test.js b/lib/internal/test_runner/test.js index a8b29742528351..35b40e277180ad 100644 --- a/lib/internal/test_runner/test.js +++ b/lib/internal/test_runner/test.js @@ -57,6 +57,7 @@ const { availableParallelism } = require('os'); const { bigint: hrtime } = process.hrtime; const kCallbackAndPromisePresent = 'callbackAndPromisePresent'; const kCancelledByParent = 'cancelledByParent'; +const kAborted = 'testAborted'; const kParentAlreadyFinished = 'parentAlreadyFinished'; const kSubtestsFailed = 'subtestsFailed'; const kTestCodeFailure = 'testCodeFailure'; @@ -390,10 +391,12 @@ class Test extends AsyncResource { } #abortHandler = () => { - this.cancel(this.#outerSignal?.reason || new AbortError('The test was aborted')); + const error = this.#outerSignal?.reason || new AbortError('The test was aborted'); + error.failureType = kAborted; + this.#cancel(error); }; - cancel(error) { + #cancel(error) { if (this.endTime !== null) { return; } @@ -404,7 +407,6 @@ class Test extends AsyncResource { kCancelledByParent ) ); - this.error.failureType = kCancelledByParent; this.startTime = this.startTime || this.endTime; // If a test was canceled before it was started, e.g inside a hook this.cancelled = true; this.#abortController.abort(); @@ -471,7 +473,7 @@ class Test extends AsyncResource { return true; } if (this.#outerSignal?.aborted) { - this.cancel(this.#outerSignal.reason || new AbortError('The test was aborted')); + this.#abortHandler(); return true; } } @@ -564,7 +566,7 @@ class Test extends AsyncResource { try { await afterEach(); } catch { /* test is already failing, let's the error */ } if (isTestFailureError(err)) { if (err.failureType === kTestTimeoutFailure) { - this.cancel(err); + this.#cancel(err); } else { this.fail(err); } @@ -617,7 +619,7 @@ class Test extends AsyncResource { const subtest = this.subtests[i]; if (!subtest.finished) { - subtest.cancel(pendingSubtestsError); + subtest.#cancel(pendingSubtestsError); subtest.postRun(pendingSubtestsError); } subtest.countSubtest(counters); @@ -831,6 +833,8 @@ module.exports = { kCancelledByParent, kSubtestsFailed, kTestCodeFailure, + kTestTimeoutFailure, + kAborted, kUnwrapErrors, Suite, Test, diff --git a/test/message/test_runner_abort.out b/test/message/test_runner_abort.out index 2cb245d7d2d9d9..3f1a3c2b7703f1 100644 --- a/test/message/test_runner_abort.out +++ b/test/message/test_runner_abort.out @@ -40,7 +40,7 @@ TAP version 13 not ok 7 - not ok 3 --- duration_ms: * - failureType: 'cancelledByParent' + failureType: 'testAborted' error: 'This operation was aborted' code: 20 stack: |- @@ -59,7 +59,7 @@ TAP version 13 not ok 8 - not ok 4 --- duration_ms: * - failureType: 'cancelledByParent' + failureType: 'testAborted' error: 'This operation was aborted' code: 20 stack: |- @@ -78,7 +78,7 @@ TAP version 13 not ok 9 - not ok 5 --- duration_ms: * - failureType: 'cancelledByParent' + failureType: 'testAborted' error: 'This operation was aborted' code: 20 stack: |- @@ -97,7 +97,7 @@ TAP version 13 not ok 1 - promise timeout signal --- duration_ms: * - failureType: 'cancelledByParent' + failureType: 'testAborted' error: 'The operation was aborted due to timeout' code: 23 stack: |- @@ -110,7 +110,7 @@ not ok 1 - promise timeout signal not ok 2 - promise abort signal --- duration_ms: * - failureType: 'cancelledByParent' + failureType: 'testAborted' error: 'This operation was aborted' code: 20 stack: |- @@ -165,7 +165,7 @@ not ok 2 - promise abort signal not ok 7 - not ok 3 --- duration_ms: * - failureType: 'cancelledByParent' + failureType: 'testAborted' error: 'This operation was aborted' code: 20 stack: |- @@ -184,7 +184,7 @@ not ok 2 - promise abort signal not ok 8 - not ok 4 --- duration_ms: * - failureType: 'cancelledByParent' + failureType: 'testAborted' error: 'This operation was aborted' code: 20 stack: |- @@ -203,7 +203,7 @@ not ok 2 - promise abort signal not ok 9 - not ok 5 --- duration_ms: * - failureType: 'cancelledByParent' + failureType: 'testAborted' error: 'This operation was aborted' code: 20 stack: |- @@ -222,7 +222,7 @@ not ok 2 - promise abort signal not ok 3 - callback timeout signal --- duration_ms: * - failureType: 'cancelledByParent' + failureType: 'testAborted' error: 'The operation was aborted due to timeout' code: 23 stack: |- @@ -235,7 +235,7 @@ not ok 3 - callback timeout signal not ok 4 - callback abort signal --- duration_ms: * - failureType: 'cancelledByParent' + failureType: 'testAborted' error: 'This operation was aborted' code: 20 stack: |- diff --git a/test/message/test_runner_abort_suite.out b/test/message/test_runner_abort_suite.out index 10bb8488432c9a..4dc71da99a766f 100644 --- a/test/message/test_runner_abort_suite.out +++ b/test/message/test_runner_abort_suite.out @@ -64,7 +64,7 @@ TAP version 13 not ok 1 - describe timeout signal --- duration_ms: * - failureType: 'cancelledByParent' + failureType: 'testAborted' error: 'The operation was aborted due to timeout' code: 23 stack: |- @@ -77,7 +77,7 @@ not ok 1 - describe timeout signal not ok 2 - describe abort signal --- duration_ms: * - failureType: 'cancelledByParent' + failureType: 'testAborted' error: 'This operation was aborted' code: 20 stack: |- diff --git a/test/message/test_runner_describe_it.out b/test/message/test_runner_describe_it.out index c9aa2a7da2dc25..87207aca71fafa 100644 --- a/test/message/test_runner_describe_it.out +++ b/test/message/test_runner_describe_it.out @@ -548,7 +548,7 @@ not ok 55 - describe async throw fails not ok 1 - timed out async test --- duration_ms: * - failureType: 'cancelledByParent' + failureType: 'testTimeoutFailure' error: 'test timed out after 5ms' code: 'ERR_TEST_FAILURE' stack: |- @@ -558,7 +558,7 @@ not ok 55 - describe async throw fails not ok 2 - timed out callback test --- duration_ms: * - failureType: 'cancelledByParent' + failureType: 'testTimeoutFailure' error: 'test timed out after 5ms' code: 'ERR_TEST_FAILURE' ... diff --git a/test/message/test_runner_output.out b/test/message/test_runner_output.out index 31c866c9931209..15d2009816a961 100644 --- a/test/message/test_runner_output.out +++ b/test/message/test_runner_output.out @@ -561,7 +561,7 @@ not ok 56 - subtest sync throw fails not ok 57 - timed out async test --- duration_ms: * - failureType: 'cancelledByParent' + failureType: 'testTimeoutFailure' error: 'test timed out after 5ms' code: 'ERR_TEST_FAILURE' ... @@ -569,7 +569,7 @@ not ok 57 - timed out async test not ok 58 - timed out callback test --- duration_ms: * - failureType: 'cancelledByParent' + failureType: 'testTimeoutFailure' error: 'test timed out after 5ms' code: 'ERR_TEST_FAILURE' ... diff --git a/test/message/test_runner_output_cli.out b/test/message/test_runner_output_cli.out index e713788f75a022..a76b37a77ce187 100644 --- a/test/message/test_runner_output_cli.out +++ b/test/message/test_runner_output_cli.out @@ -561,7 +561,7 @@ not ok 56 - subtest sync throw fails not ok 57 - timed out async test --- duration_ms: * - failureType: 'cancelledByParent' + failureType: 'testTimeoutFailure' error: 'test timed out after 5ms' code: 'ERR_TEST_FAILURE' ... @@ -569,7 +569,7 @@ not ok 57 - timed out async test not ok 58 - timed out callback test --- duration_ms: * - failureType: 'cancelledByParent' + failureType: 'testTimeoutFailure' error: 'test timed out after 5ms' code: 'ERR_TEST_FAILURE' ...