Skip to content

Commit b52fccb

Browse files
committed
CR
1 parent b7fab50 commit b52fccb

File tree

6 files changed

+23
-11
lines changed

6 files changed

+23
-11
lines changed

doc/api/test.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ Otherwise, the test is considered to be a failure. Test files must be
316316
executable by Node.js, but are not required to use the `node:test` module
317317
internally.
318318

319-
## `runFiles([options])`
319+
## `run([options])`
320320

321321
<!-- YAML
322322
added: REPLACEME
@@ -338,6 +338,8 @@ added: REPLACEME
338338
If unspecified, subtests inherit this value from their parent.
339339
**Default:** `Infinity`.
340340
* Returns: {Promise} Resolved with `undefined` once all test files complete.
341+
If one of the test files fails, `run()` will return a rejected `Promise`
342+
with an [`ERR_TEST_FAILURE`][] error
341343

342344
## `test([name][, options][, fn])`
343345

@@ -870,6 +872,7 @@ added:
870872
[TAP]: https://testanything.org/
871873
[`--test-only`]: cli.md#--test-only
872874
[`--test`]: cli.md#--test
875+
[`ERR_TEST_FAILURE`]: errors.md#err_test_failure
873876
[`SuiteContext`]: #class-suitecontext
874877
[`TestContext`]: #class-testcontext
875878
[`test()`]: #testname-options-fn

lib/internal/main/test_runner.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ const {
33
prepareMainThreadExecution,
44
markBootstrapComplete
55
} = require('internal/process/pre_execution');
6-
const { runFiles } = require('internal/test_runner/runner');
6+
const { run } = require('internal/test_runner/runner');
77

88
prepareMainThreadExecution(false);
99
markBootstrapComplete();
1010

11-
runFiles();
11+
run();

lib/internal/test_runner/harness.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const {
1414
ERR_TEST_FAILURE,
1515
},
1616
} = require('internal/errors');
17+
const { kEmptyObject } = require('internal/util');
1718
const { getOptionValue } = require('internal/options');
1819
const { kCancelledByParent, Test, ItTest, Suite } = require('internal/test_runner/test');
1920

@@ -22,7 +23,7 @@ const testResources = new SafeMap();
2223
const root = new Test({ __proto__: null, name: '<root>' });
2324
const wasRootSetup = new SafeWeakMap();
2425

25-
function createTestTree(options = {}) {
26+
function createTestTree(options = kEmptyObject) {
2627
return setup(new Test({ __proto__: null, ...options, name: '<root>' }));
2728
}
2829

lib/internal/test_runner/runner.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const {
2222
} = require('internal/errors');
2323
const { validateArray } = require('internal/validators');
2424
const { kEmptyObject } = require('internal/util');
25+
const { getOptionValue } = require('internal/options');
2526
const { createTestTree } = require('internal/test_runner/harness');
2627
const { kSubtestsFailed, Test } = require('internal/test_runner/test');
2728
const {
@@ -31,6 +32,7 @@ const {
3132
const { basename, join, resolve } = require('path');
3233
const { once } = require('events');
3334

35+
const isTestRunnerCli = getOptionValue('--test');
3436
const kFilterArgs = ['--test'];
3537

3638
// TODO(cjihrig): Replace this with recursive readdir once it lands.
@@ -137,18 +139,24 @@ function runTestFile(path, root) {
137139
return subtest.start();
138140
}
139141

140-
async function runFiles(options) {
142+
async function run(options) {
141143
if (options === null || typeof options !== 'object') {
142144
options = kEmptyObject;
143145
}
144146
const { concurrency, timeout, signal, files } = options;
147+
// TODO(MoLow): Allow piping report to a writable other than stdout.
145148
const root = createTestTree({ concurrency, timeout, signal });
146149

147150
if (files !== undefined) {
148-
validateArray(options, 'options.files');
151+
validateArray(options.files, 'options.files');
149152
}
150153

151-
await ArrayPrototypeMap(files ?? createTestFileList(), (path) => runTestFile(path, root));
154+
await SafePromiseAll(ArrayPrototypeMap(files ?? createTestFileList(), (path) => runTestFile(path, root)));
155+
await root.postRun();
156+
157+
if (root.error && !isTestRunnerCli) {
158+
throw root.error;
159+
}
152160
}
153161

154-
module.exports = { runFiles };
162+
module.exports = { run };

lib/internal/test_runner/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ class Test extends AsyncResource {
537537
}
538538
}
539539

540-
if (this.passed && failedSubtests > 0) {
540+
if ((this.passed || this.parent === null) && failedSubtests > 0) {
541541
const subtestString = `subtest${failedSubtests > 1 ? 's' : ''}`;
542542
const msg = `${failedSubtests} ${subtestString} failed`;
543543

lib/test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
'use strict';
22
const { ObjectAssign } = primordials;
33
const { test, describe, it, before, after, beforeEach, afterEach } = require('internal/test_runner/harness');
4-
const { runFiles } = require('internal/test_runner/runner');
4+
const { run } = require('internal/test_runner/runner');
55
const { emitExperimentalWarning } = require('internal/util');
66

77
emitExperimentalWarning('The test runner');
88

99
module.exports = test;
10-
ObjectAssign(module.exports, { test, describe, it, before, after, beforeEach, afterEach, runFiles });
10+
ObjectAssign(module.exports, { test, describe, it, before, after, beforeEach, afterEach, run });

0 commit comments

Comments
 (0)