Skip to content

Commit 885fdd8

Browse files
improve based on CR
1 parent 8890ecf commit 885fdd8

4 files changed

Lines changed: 35 additions & 3 deletions

File tree

packages/jest-cli/src/reporters/coverage_worker.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ function formatCoverageError(error, filename: Path): SerializableError {
3737
};
3838
}
3939

40+
// Make sure uncaught errors are logged before we exit.
41+
process.on('uncaughtException', err => {
42+
console.error(err.stack);
43+
process.exit(1);
44+
});
45+
4046
module.exports = (
4147
{config, globalConfig, path}: CoverageWorkerData,
4248
callback: WorkerCallback,

packages/jest-jasmine2/src/jasmine/Env.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,17 @@ module.exports = function(j$) {
197197
}
198198
};
199199

200+
// Need to ensure we are the only ones handling these exceptions.
201+
const oldListenersException = process
202+
.listeners('uncaughtException')
203+
.slice();
204+
const oldListenersRejection = process
205+
.listeners('unhandledRejection')
206+
.slice();
207+
208+
process.removeAllListeners('uncaughtException');
209+
process.removeAllListeners('unhandledRejection');
210+
200211
process.on('uncaughtException', uncaught);
201212
process.on('unhandledRejection', uncaught);
202213

@@ -229,6 +240,15 @@ module.exports = function(j$) {
229240

230241
process.removeListener('uncaughtException', uncaught);
231242
process.removeListener('unhandledRejection', uncaught);
243+
244+
// restore previous exception handlers
245+
oldListenersException.forEach(listener => {
246+
process.on('uncaughtException', listener);
247+
});
248+
249+
oldListenersRejection.forEach(listener => {
250+
process.on('unhandledRejection', listener);
251+
});
232252
};
233253

234254
this.addReporter = function(reporterToAdd) {

packages/jest-jasmine2/src/queue_runner.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,15 @@ function queueRunner(options: Options) {
7171
);
7272
};
7373

74-
const res = options.queueableFns.reduce(
74+
const result = options.queueableFns.reduce(
7575
(promise, fn) => promise.then(() => mapper(fn)),
7676
Promise.resolve(),
7777
);
7878

7979
return {
8080
cancel: token.cancel.bind(token),
81-
catch: res.catch.bind(res),
82-
then: res.then.bind(res),
81+
catch: result.catch.bind(result),
82+
then: result.then.bind(result),
8383
};
8484
}
8585

packages/jest-runner/src/test_worker.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ import type {GlobalConfig, Path, ProjectConfig} from 'types/Config';
1212
import type {SerializableError, TestResult} from 'types/TestResult';
1313
import type {RawModuleMap} from 'types/HasteMap';
1414

15+
// Make sure uncaught errors are logged before we exit.
16+
process.on('uncaughtException', err => {
17+
console.error(err.stack);
18+
process.exit(1);
19+
});
20+
1521
import HasteMap from 'jest-haste-map';
1622
import {separateMessageFromStack} from 'jest-message-util';
1723
import Runtime from 'jest-runtime';

0 commit comments

Comments
 (0)