Skip to content

Commit

Permalink
improve based on CR
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Aug 24, 2017
1 parent 8890ecf commit 885fdd8
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
6 changes: 6 additions & 0 deletions packages/jest-cli/src/reporters/coverage_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ function formatCoverageError(error, filename: Path): SerializableError {
};
}

// Make sure uncaught errors are logged before we exit.
process.on('uncaughtException', err => {
console.error(err.stack);
process.exit(1);
});

module.exports = (
{config, globalConfig, path}: CoverageWorkerData,
callback: WorkerCallback,
Expand Down
20 changes: 20 additions & 0 deletions packages/jest-jasmine2/src/jasmine/Env.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,17 @@ module.exports = function(j$) {
}
};

// Need to ensure we are the only ones handling these exceptions.
const oldListenersException = process
.listeners('uncaughtException')
.slice();
const oldListenersRejection = process
.listeners('unhandledRejection')
.slice();

process.removeAllListeners('uncaughtException');
process.removeAllListeners('unhandledRejection');

process.on('uncaughtException', uncaught);
process.on('unhandledRejection', uncaught);

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

process.removeListener('uncaughtException', uncaught);
process.removeListener('unhandledRejection', uncaught);

// restore previous exception handlers
oldListenersException.forEach(listener => {
process.on('uncaughtException', listener);
});

oldListenersRejection.forEach(listener => {
process.on('unhandledRejection', listener);
});
};

this.addReporter = function(reporterToAdd) {
Expand Down
6 changes: 3 additions & 3 deletions packages/jest-jasmine2/src/queue_runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ function queueRunner(options: Options) {
);
};

const res = options.queueableFns.reduce(
const result = options.queueableFns.reduce(
(promise, fn) => promise.then(() => mapper(fn)),
Promise.resolve(),
);

return {
cancel: token.cancel.bind(token),
catch: res.catch.bind(res),
then: res.then.bind(res),
catch: result.catch.bind(result),
then: result.then.bind(result),
};
}

Expand Down
6 changes: 6 additions & 0 deletions packages/jest-runner/src/test_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ import type {GlobalConfig, Path, ProjectConfig} from 'types/Config';
import type {SerializableError, TestResult} from 'types/TestResult';
import type {RawModuleMap} from 'types/HasteMap';

// Make sure uncaught errors are logged before we exit.
process.on('uncaughtException', err => {
console.error(err.stack);
process.exit(1);
});

import HasteMap from 'jest-haste-map';
import {separateMessageFromStack} from 'jest-message-util';
import Runtime from 'jest-runtime';
Expand Down

0 comments on commit 885fdd8

Please sign in to comment.