| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 0a690ef commit 1ef3c53
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1604,8 +1604,8 @@ E('ERR_TAP_VALIDATION_ERROR', function(errorMsg) { | |||
| 1604 | 1604 | }, Error); | |
| 1605 | 1605 | E('ERR_TEST_FAILURE', function(error, failureType) { | |
| 1606 | 1606 | hideInternalStackFrames(this); | |
| 1607 | - assert(typeof failureType === 'string', | ||
| 1608 | - "The 'failureType' argument must be of type string."); | ||
| 1607 | + assert(typeof failureType === 'string' || typeof failureType === 'symbol', | ||
| 1608 | + "The 'failureType' argument must be of type string or symbol."); | ||
| 1609 | 1609 | ||
| 1610 | 1610 | let msg = error?.message ?? error; | |
| 1611 | 1611 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,6 +16,7 @@ const { | |||
| 16 | 16 | const { kEmptyObject } = require('internal/util'); | |
| 17 | 17 | const { kCancelledByParent, Test, ItTest, Suite } = require('internal/test_runner/test'); | |
| 18 | 18 | const { | |
| 19 | + kAsyncBootstrapFailure, | ||
| 19 | 20 | parseCommandLine, | |
| 20 | 21 | setupTestReporters, | |
| 21 | 22 | } = require('internal/test_runner/utils'); | |
@@ -30,6 +31,13 @@ function createTestTree(options = kEmptyObject) { | |||
| 30 | 31 | ||
| 31 | 32 | function createProcessEventHandler(eventName, rootTest) { | |
| 32 | 33 | return (err) => { | |
| 34 | + if (err?.failureType === kAsyncBootstrapFailure) { | ||
| 35 | + // Something went wrong during the asynchronous portion of bootstrapping | ||
| 36 | + // the test runner. Since the test runner is not setup properly, we can't | ||
| 37 | + // do anything but throw the error. | ||
| 38 | + throw err.cause; | ||
| 39 | + } | ||
| 40 | + | ||
| 33 | 41 | // Check if this error is coming from a test. If it is, fail the test. | |
| 34 | 42 | const test = testResources.get(executionAsyncId()); | |
| 35 | 43 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,6 +8,7 @@ const { | |||
| 8 | 8 | RegExp, | |
| 9 | 9 | RegExpPrototypeExec, | |
| 10 | 10 | SafeMap, | |
| 11 | + Symbol, | ||
| 11 | 12 | } = primordials; | |
| 12 | 13 | const { basename } = require('path'); | |
| 13 | 14 | const { createWriteStream } = require('fs'); | |
@@ -24,6 +25,7 @@ const { | |||
| 24 | 25 | } = require('internal/errors'); | |
| 25 | 26 | const { compose } = require('stream'); | |
| 26 | 27 | ||
| 28 | + const kAsyncBootstrapFailure = Symbol('asyncBootstrapFailure'); | ||
| 27 | 29 | const kMultipleCallbackInvocations = 'multipleCallbackInvocations'; | |
| 28 | 30 | const kRegExpPattern = /^\/(.*)\/([a-z]*)$/; | |
| 29 | 31 | const kSupportedFileExtensions = /\.[cm]?js$/; | |
@@ -150,11 +152,15 @@ async function getReportersMap(reporters, destinations) { | |||
| 150 | 152 | ||
| 151 | 153 | ||
| 152 | 154 | async function setupTestReporters(testsStream) { | |
| 153 | - const { reporters, destinations } = parseCommandLine(); | ||
| 154 | - const reportersMap = await getReportersMap(reporters, destinations); | ||
| 155 | - for (let i = 0; i < reportersMap.length; i++) { | ||
| 156 | - const { reporter, destination } = reportersMap[i]; | ||
| 157 | - compose(testsStream, reporter).pipe(destination); | ||
| 155 | + try { | ||
| 156 | + const { reporters, destinations } = parseCommandLine(); | ||
| 157 | + const reportersMap = await getReportersMap(reporters, destinations); | ||
| 158 | + for (let i = 0; i < reportersMap.length; i++) { | ||
| 159 | + const { reporter, destination } = reportersMap[i]; | ||
| 160 | + compose(testsStream, reporter).pipe(destination); | ||
| 161 | + } | ||
| 162 | + } catch (err) { | ||
| 163 | + throw new ERR_TEST_FAILURE(err, kAsyncBootstrapFailure); | ||
| 158 | 164 | } | |
| 159 | 165 | } | |
| 160 | 166 | ||
@@ -220,6 +226,7 @@ module.exports = { | |||
| 220 | 226 | doesPathMatchFilter, | |
| 221 | 227 | isSupportedFileType, | |
| 222 | 228 | isTestFailureError, | |
| 229 | + kAsyncBootstrapFailure, | ||
| 223 | 230 | parseCommandLine, | |
| 224 | 231 | setupTestReporters, | |
| 225 | 232 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -116,4 +116,16 @@ describe('node:test reporters', { concurrency: true }, () => { | |||
| 116 | 116 | /^package: reporter-esm{"test:start":4,"test:pass":2,"test:fail":2,"test:plan":2,"test:diagnostic":\d+}$/, | |
| 117 | 117 | ); | |
| 118 | 118 | }); | |
| 119 | + | ||
| 120 | + it('should throw when reporter setup throws asynchronously', async () => { | ||
| 121 | + const child = spawnSync( | ||
| 122 | + process.execPath, | ||
| 123 | + ['--test', '--test-reporter', fixtures.fileURL('empty.js'), 'reporters.js'], | ||
| 124 | + { cwd: fixtures.path('test-runner') } | ||
| 125 | + ); | ||
| 126 | + assert.strictEqual(child.status, 7); | ||
| 127 | + assert.strictEqual(child.signal, null); | ||
| 128 | + assert.strictEqual(child.stdout.toString(), ''); | ||
| 129 | + assert.match(child.stderr.toString(), /ERR_INVALID_ARG_TYPE/); | ||
| 130 | + }); | ||
| 119 | 131 | }); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments