Skip to content

Commit 6f16da8

Browse files
geeksilva97aduh95
authored andcommitted
test_runner: set non-zero exit code when suite errors occur
PR-URL: #62282 Reviewed-By: Aviv Keller <me@aviv.sh> Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
1 parent e489702 commit 6f16da8

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

lib/internal/test_runner/utils.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,9 @@ function countCompletedTest(test, harness = test.root.harness) {
384384
}
385385
if (test.reportedType === 'suite') {
386386
harness.counters.suites++;
387+
if (!test.passed) {
388+
harness.success = false;
389+
}
387390
return;
388391
}
389392
// Check SKIP and TODO tests first, as those should not be counted as
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'use strict';
2+
const { describe, it } = require('node:test');
3+
4+
describe('should fail', () => {
5+
throw new Error('error in describe');
6+
});
7+
8+
describe('should pass', () => {
9+
it('ok', () => {});
10+
});

test/parallel/test-runner-exit-code.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ if (process.argv[2] === 'child') {
7070
assert.strictEqual(child.status, 1);
7171
assert.strictEqual(child.signal, null);
7272

73+
// An error thrown inside describe() should cause a non-zero exit code.
74+
child = spawnSync(process.execPath, [
75+
'--test',
76+
fixtures.path('test-runner', 'describe_error.js'),
77+
]);
78+
assert.strictEqual(child.status, 1);
79+
assert.strictEqual(child.signal, null);
80+
7381
// With process isolation (default), the test name shown is the file path
7482
// because the parent runner only knows about file-level tests
7583
const neverEndingSync = fixtures.path('test-runner', 'never_ending_sync.js');

0 commit comments

Comments
 (0)