| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -705,6 +705,9 @@ added: v18.9.0 | |||
| 705 | 705 | **Default:** `false`. | |
| 706 | 706 | * `files`: {Array} An array containing the list of files to run. | |
| 707 | 707 | **Default** matching files from [test runner execution model][]. | |
| 708 | + * `setup` {Function} A function that accepts the `TestsStream` instance | ||
| 709 | + and can be used to setup listeners before any tests are run. | ||
| 710 | + **Default:** `undefined`. | ||
| 708 | 711 | * `signal` {AbortSignal} Allows aborting an in-progress test execution. | |
| 709 | 712 | * `timeout` {number} A number of milliseconds the test execution will | |
| 710 | 713 | fail after. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,8 +22,7 @@ if (isUsingInspector()) { | |||
| 22 | 22 | inspectPort = process.debugPort; | |
| 23 | 23 | } | |
| 24 | 24 | ||
| 25 | - const testsStream = run({ concurrency, inspectPort, watch: getOptionValue('--watch') }); | ||
| 26 | - testsStream.once('test:fail', () => { | ||
| 25 | + run({ concurrency, inspectPort, watch: getOptionValue('--watch'), setup: setupTestReporters }) | ||
| 26 | + .once('test:fail', () => { | ||
| 27 | 27 | process.exitCode = kGenericUserError; | |
| 28 | 28 | }); | |
| 29 | - setupTestReporters(testsStream); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -170,29 +170,35 @@ function setup(root) { | |||
| 170 | 170 | } | |
| 171 | 171 | ||
| 172 | 172 | let globalRoot; | |
| 173 | + let reportersSetup; | ||
| 173 | 174 | function getGlobalRoot() { | |
| 174 | 175 | if (!globalRoot) { | |
| 175 | 176 | globalRoot = createTestTree(); | |
| 176 | 177 | globalRoot.reporter.once('test:fail', () => { | |
| 177 | 178 | process.exitCode = kGenericUserError; | |
| 178 | 179 | }); | |
| 179 | - setupTestReporters(globalRoot.reporter); | ||
| 180 | + reportersSetup = setupTestReporters(globalRoot.reporter); | ||
| 180 | 181 | } | |
| 181 | 182 | return globalRoot; | |
| 182 | 183 | } | |
| 183 | 184 | ||
| 185 | + async function startSubtest(subtest) { | ||
| 186 | + await reportersSetup; | ||
| 187 | + await subtest.start(); | ||
| 188 | + } | ||
| 189 | + | ||
| 184 | 190 | function test(name, options, fn) { | |
| 185 | 191 | const parent = testResources.get(executionAsyncId()) || getGlobalRoot(); | |
| 186 | 192 | const subtest = parent.createSubtest(Test, name, options, fn); | |
| 187 | - return subtest.start(); | ||
| 193 | + return startSubtest(subtest); | ||
| 188 | 194 | } | |
| 189 | 195 | ||
| 190 | 196 | function runInParentContext(Factory) { | |
| 191 | 197 | function run(name, options, fn, overrides) { | |
| 192 | 198 | const parent = testResources.get(executionAsyncId()) || getGlobalRoot(); | |
| 193 | 199 | const subtest = parent.createSubtest(Factory, name, options, fn, overrides); | |
| 194 | 200 | if (parent === getGlobalRoot()) { | |
| 195 | - subtest.start(); | ||
| 201 | + startSubtest(subtest); | ||
| 196 | 202 | } | |
| 197 | 203 | } | |
| 198 | 204 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,8 +13,10 @@ const { | |||
| 13 | 13 | ObjectAssign, | |
| 14 | 14 | ObjectKeys, | |
| 15 | 15 | PromisePrototypeThen, | |
| 16 | + SafePromiseAll, | ||
| 16 | 17 | SafePromiseAllReturnVoid, | |
| 17 | 18 | SafePromiseAllSettledReturnVoid, | |
| 19 | + PromiseResolve, | ||
| 18 | 20 | SafeMap, | |
| 19 | 21 | SafeSet, | |
| 20 | 22 | StringPrototypeIndexOf, | |
@@ -24,6 +26,7 @@ const { | |||
| 24 | 26 | ||
| 25 | 27 | const { spawn } = require('child_process'); | |
| 26 | 28 | const { readdirSync, statSync } = require('fs'); | |
| 29 | + const { finished } = require('internal/streams/end-of-stream'); | ||
| 27 | 30 | // TODO(aduh95): switch to internal/readline/interface when backporting to Node.js 16.x is no longer a concern. | |
| 28 | 31 | const { createInterface } = require('readline'); | |
| 29 | 32 | const { FilesWatcher } = require('internal/watch_mode/files_watcher'); | |
@@ -33,7 +36,7 @@ const { | |||
| 33 | 36 | ERR_TEST_FAILURE, | |
| 34 | 37 | }, | |
| 35 | 38 | } = require('internal/errors'); | |
| 36 | - const { validateArray, validateBoolean } = require('internal/validators'); | ||
| 39 | + const { validateArray, validateBoolean, validateFunction } = require('internal/validators'); | ||
| 37 | 40 | const { getInspectPort, isUsingInspector, isInspectorMessage } = require('internal/util/inspector'); | |
| 38 | 41 | const { kEmptyObject } = require('internal/util'); | |
| 39 | 42 | const { createTestTree } = require('internal/test_runner/harness'); | |
@@ -299,7 +302,10 @@ function runTestFile(path, root, inspectPort, filesWatcher) { | |||
| 299 | 302 | subtest.addToReport(ast); | |
| 300 | 303 | }); | |
| 301 | 304 | ||
| 302 | - const { 0: code, 1: signal } = await once(child, 'exit', { signal: t.signal }); | ||
| 305 | + const { 0: { 0: code, 1: signal } } = await SafePromiseAll([ | ||
| 306 | + once(child, 'exit', { signal: t.signal }), | ||
| 307 | + finished(parser, { signal: t.signal }), | ||
| 308 | + ]); | ||
| 303 | 309 | ||
| 304 | 310 | runningProcesses.delete(path); | |
| 305 | 311 | runningSubtests.delete(path); | |
@@ -348,14 +354,17 @@ function run(options) { | |||
| 348 | 354 | if (options === null || typeof options !== 'object') { | |
| 349 | 355 | options = kEmptyObject; | |
| 350 | 356 | } | |
| 351 | - const { concurrency, timeout, signal, files, inspectPort, watch } = options; | ||
| 357 | + const { concurrency, timeout, signal, files, inspectPort, watch, setup } = options; | ||
| 352 | 358 | ||
| 353 | 359 | if (files != null) { | |
| 354 | 360 | validateArray(files, 'options.files'); | |
| 355 | 361 | } | |
| 356 | 362 | if (watch != null) { | |
| 357 | 363 | validateBoolean(watch, 'options.watch'); | |
| 358 | 364 | } | |
| 365 | + if (setup != null) { | ||
| 366 | + validateFunction(setup, 'options.setup'); | ||
| 367 | + } | ||
| 359 | 368 | ||
| 360 | 369 | const root = createTestTree({ concurrency, timeout, signal }); | |
| 361 | 370 | const testFiles = files ?? createTestFileList(); | |
@@ -366,13 +375,13 @@ function run(options) { | |||
| 366 | 375 | filesWatcher = watchFiles(testFiles, root, inspectPort); | |
| 367 | 376 | postRun = undefined; | |
| 368 | 377 | } | |
| 369 | - | ||
| 370 | - PromisePrototypeThen(SafePromiseAllSettledReturnVoid(testFiles, (path) => { | ||
| 378 | + const runFiles = () => SafePromiseAllSettledReturnVoid(testFiles, (path) => { | ||
| 371 | 379 | const subtest = runTestFile(path, root, inspectPort, filesWatcher); | |
| 372 | 380 | runningSubtests.set(path, subtest); | |
| 373 | 381 | return subtest; | |
| 374 | - }), postRun); | ||
| 382 | + }); | ||
| 375 | 383 | ||
| 384 | + PromisePrototypeThen(PromisePrototypeThen(PromiseResolve(setup?.(root.reporter)), runFiles), postRun); | ||
| 376 | 385 | ||
| 377 | 386 | return root.reporter; | |
| 378 | 387 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments