Skip to content

Commit

Permalink
test_runner: throw if harness is not bootstrapped
Browse files Browse the repository at this point in the history
This commit updates the test harness to re-throw uncaught errors
if bootstrapping has not completed. This updates the existing
logic which tried to detect a specific error code.

PR-URL: #46962
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
  • Loading branch information
cjihrig authored and danielleadams committed Apr 11, 2023
1 parent ab5b318 commit d60eef2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
5 changes: 2 additions & 3 deletions lib/internal/test_runner/harness.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const {
const { kEmptyObject } = require('internal/util');
const { kCancelledByParent, Test, Suite } = require('internal/test_runner/test');
const {
kAsyncBootstrapFailure,
parseCommandLine,
setupTestReporters,
} = require('internal/test_runner/utils');
Expand All @@ -30,11 +29,11 @@ function createTestTree(options = kEmptyObject) {

function createProcessEventHandler(eventName, rootTest) {
return (err) => {
if (err?.failureType === kAsyncBootstrapFailure) {
if (!rootTest.harness.bootstrapComplete) {
// Something went wrong during the asynchronous portion of bootstrapping
// the test runner. Since the test runner is not setup properly, we can't
// do anything but throw the error.
throw err.cause;
throw err;
}

// Check if this error is coming from a test. If it is, fail the test.
Expand Down
17 changes: 5 additions & 12 deletions lib/internal/test_runner/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const {
RegExp,
RegExpPrototypeExec,
SafeMap,
Symbol,
} = primordials;
const { basename } = require('path');
const { createWriteStream } = require('fs');
Expand All @@ -25,7 +24,6 @@ const {
} = require('internal/errors');
const { compose } = require('stream');

const kAsyncBootstrapFailure = Symbol('asyncBootstrapFailure');
const kMultipleCallbackInvocations = 'multipleCallbackInvocations';
const kRegExpPattern = /^\/(.*)\/([a-z]*)$/;
const kSupportedFileExtensions = /\.[cm]?js$/;
Expand Down Expand Up @@ -152,15 +150,11 @@ async function getReportersMap(reporters, destinations) {


async function setupTestReporters(rootTest) {
try {
const { reporters, destinations } = parseCommandLine();
const reportersMap = await getReportersMap(reporters, destinations);
for (let i = 0; i < reportersMap.length; i++) {
const { reporter, destination } = reportersMap[i];
compose(rootTest.reporter, reporter).pipe(destination);
}
} catch (err) {
throw new ERR_TEST_FAILURE(err, kAsyncBootstrapFailure);
const { reporters, destinations } = parseCommandLine();
const reportersMap = await getReportersMap(reporters, destinations);
for (let i = 0; i < reportersMap.length; i++) {
const { reporter, destination } = reportersMap[i];
compose(rootTest.reporter, reporter).pipe(destination);
}
}

Expand Down Expand Up @@ -226,7 +220,6 @@ module.exports = {
doesPathMatchFilter,
isSupportedFileType,
isTestFailureError,
kAsyncBootstrapFailure,
parseCommandLine,
setupTestReporters,
};

0 comments on commit d60eef2

Please sign in to comment.