Skip to content

Commit 8168cb9

Browse files
fix: fix tests
1 parent cecdb57 commit 8168cb9

File tree

7 files changed

+12
-37
lines changed

7 files changed

+12
-37
lines changed

doc/api/test.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -609,10 +609,6 @@ added:
609609
- REPLACEME
610610
-->
611611

612-
```bash
613-
node --test-bail
614-
```
615-
616612
The `--test-bail` flag provides a way to stop the test execution
617613
as soon as a test fails.
618614
By enabling this flag, the test runner will exit the test suite early

lib/internal/test_runner/reporter/tap.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const {
1414
const { inspectWithNoCustomRetry } = require('internal/errors');
1515
const { isError, kEmptyObject } = require('internal/util');
1616
const { getCoverageReport } = require('internal/test_runner/utils');
17+
const { kBailedOut } = require('internal/test_runner/test');
1718
const kDefaultIndent = ' '; // 4 spaces
1819
const kFrameStartRegExp = /^ {4}at /;
1920
const kLineBreakRegExp = /\n|\r\n/;

lib/internal/test_runner/test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -981,6 +981,7 @@ module.exports = {
981981
kSubtestsFailed,
982982
kTestCodeFailure,
983983
kTestTimeoutFailure,
984+
kBailedOut,
984985
kAborted,
985986
kUnwrapErrors,
986987
Suite,

src/node_options.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -567,9 +567,6 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
567567
"profile generated with --heap-prof. (default: 512 * 1024)",
568568
&EnvironmentOptions::heap_prof_interval);
569569
#endif // HAVE_INSPECTOR
570-
AddOption("--test-bail",
571-
"stop test execution when a test has failed",
572-
&EnvironmentOptions::test_bail);
573570
AddOption("--max-http-header-size",
574571
"set the maximum size of HTTP headers (default: 16384 (16KB))",
575572
&EnvironmentOptions::max_http_header_size,
@@ -603,6 +600,9 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
603600
"run test at specific shard",
604601
&EnvironmentOptions::test_shard,
605602
kAllowedInEnvvar);
603+
AddOption("--test-bail",
604+
"stop test runner execution on the first test failure",
605+
&EnvironmentOptions::test_bail);
606606
AddOption("--test-udp-no-try-send", "", // For testing only.
607607
&EnvironmentOptions::test_udp_no_try_send);
608608
AddOption("--throw-deprecation",

test/fixtures/test-runner/bail/bail.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
'use strict';
12
const test = require('node:test');
23

34
test('nested', (t) => {
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
const assert = require('assert');
1+
'use strict';
22
const common = require('../../../common');
3-
3+
const assert = require('assert');
44
const test = require('node:test');
55

66
test('keep error', (t) => {
7-
assert.strictEqual(0, 1);
7+
assert.strictEqual(0, 1);
88
});
99

10-
test('dont show', common.mustNotCall( t => {
11-
assert.strictEqual(0, 2);
10+
test('dont show', common.mustNotCall((t) => {
11+
assert.strictEqual(0, 2);
1212
}));

test/parallel/test-runner-bail.js

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const errorTestFile = fixtures.path('test-runner/bail/error.js');
1313
tmpdir.refresh();
1414

1515
describe('maintain errors', () => {
16-
it('should exit at assertion failure', () => {
16+
it('should exit on first failure', () => {
1717
const child = spawnSync(process.execPath, ['--test', '--test-bail', errorTestFile]);
1818
assert.strictEqual(child.stderr.toString(), '');
1919
assert.match(child.stdout.toString(), /failureType: 'testCodeFailure'/);
@@ -35,20 +35,6 @@ describe('node:test bail tap', () => {
3535
assert.doesNotMatch(child.stdout.toString(), /# Subtest: top level/);
3636
assert.doesNotMatch(child.stdout.toString(), /ok 1 - ok forth/);
3737
assert.doesNotMatch(child.stdout.toString(), /not ok 2 - fifth/);
38-
39-
});
40-
41-
it('should exit not exit if bail isnt set', () => {
42-
const child = spawnSync(process.execPath, ['--test', testFile]);
43-
assert.strictEqual(child.stderr.toString(), '');
44-
assert.match(child.stdout.toString(), /ok 1 - first/);
45-
assert.match(child.stdout.toString(), /not ok 2 - second/);
46-
assert.match(child.stdout.toString(), /not ok 3 - third/);
47-
assert.match(child.stdout.toString(), /not ok 1 - nested/);
48-
assert.match(child.stdout.toString(), /# Subtest: top level/);
49-
assert.match(child.stdout.toString(), /ok 1 - forth/);
50-
assert.match(child.stdout.toString(), /not ok 2 - fifth/);
51-
assert.match(child.stdout.toString(), /not ok 2 - top level/);
5238
});
5339
});
5440

@@ -62,14 +48,4 @@ describe('node:test bail spec', () => {
6248
assert.doesNotMatch(child.stdout.toString(), / forth/);
6349
assert.doesNotMatch(child.stdout.toString(), / fifth/);
6450
});
65-
66-
it('should exit not exit if bail isnt set', () => {
67-
const child = spawnSync(process.execPath, ['--test', '--test-reporter=spec', testFile]);
68-
assert.strictEqual(child.stderr.toString(), '');
69-
assert.match(child.stdout.toString(), / first/);
70-
assert.match(child.stdout.toString(), / second/);
71-
assert.match(child.stdout.toString(), / third/);
72-
assert.match(child.stdout.toString(), / forth/);
73-
assert.match(child.stdout.toString(), / fifth/);
74-
});
7551
});

0 commit comments

Comments
 (0)