Skip to content

Commit 9fe9fb8

Browse files
committed
fix #172: tests processing should not stop when uncaught exception occurs
1 parent d9d9138 commit 9fe9fb8

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

test/index.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,10 @@ echo 'TESTCASE: unhandled rejections should not force subprocess to exit'
209209
test test/q-promises/index.js
210210
showTestResult $?
211211

212+
echo 'TESTCASE: uncaught exceptions should not force subprocess to exit'
213+
test test/uncaught-exception/index.js
214+
showTestResult $?
215+
212216
echo "Passes: $PASSES Failes: $FAILES"
213217

214218
if [ $FAILES -gt 0 ]; then

test/uncaught-exception/README

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Make sure that uncaught exceptions do not stop executing the tests

test/uncaught-exception/index.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env node
2+
3+
const assert = require('assert');
4+
const sinon = require('sinon');
5+
6+
const MochaParallelTests = require('../../dist/main/mocha').default;
7+
const { setProcessExitListeners } = require('../../dist/util');
8+
const SilentReporter = require('../util/silent-reporter');
9+
10+
setProcessExitListeners();
11+
12+
const onRunnerEnd = sinon.fake();
13+
const onTestEnd = sinon.fake();
14+
const mocha = new MochaParallelTests;
15+
mocha.reporter(SilentReporter);
16+
mocha.addFile(`${__dirname}/index.spec.js`);
17+
18+
mocha.run()
19+
.on('end', onRunnerEnd)
20+
.on('test end', onTestEnd);
21+
22+
process.on('exit', () => {
23+
assert.strictEqual(onRunnerEnd.callCount, 1, `runner "end" event occured wrong number of times: ${onRunnerEnd.callCount}`);
24+
assert.strictEqual(onTestEnd.callCount, 4, `runner "test end" event occured wrong number of times: ${onTestEnd.callCount}`);
25+
});
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
describe('suite', function () {
2+
it('case 1', function () {
3+
throw new Error('foo');
4+
});
5+
6+
// eslint-disable-next-line no-unused-vars
7+
it('case 2', function (done) {
8+
setTimeout(() => {
9+
throw new Error('foo');
10+
}, 100);
11+
});
12+
13+
it('case 3', () => {});
14+
15+
it('case 4', () => {
16+
return new Promise(() => {
17+
throw new Error('foo');
18+
});
19+
});
20+
});

0 commit comments

Comments
 (0)