diff --git a/CHANGELOG.md b/CHANGELOG.md index f0fa49a26b8a..7815285ada41 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -51,6 +51,8 @@ ### Fixes +* `[jest-jasmine2]` Install `sourcemap-support` into normal runtime to catch + runtime errors ([#5945](https://github.com/facebook/jest/pull/5945)) * `[jest-jasmine2]` Added assertion error handling inside `afterAll hook` ([#5884](https://github.com/facebook/jest/pull/5884)) * `[jest-cli]` Remove the notifier actions in case of failure when not in watch diff --git a/integration-tests/__tests__/stack_trace.test.js b/integration-tests/__tests__/stack_trace.test.js index c8ace9a23f50..ed79c757bc62 100644 --- a/integration-tests/__tests__/stack_trace.test.js +++ b/integration-tests/__tests__/stack_trace.test.js @@ -22,6 +22,7 @@ describe('Stack Trace', () => { expect(stderr).toMatch( /ReferenceError: thisIsARuntimeError is not defined/, ); + expect(stderr).toMatch(/> 10 \| thisIsARuntimeError\(\);/); expect(stderr).toMatch( /\s+at\s(?:.+?)\s\(__tests__\/runtime_error.test\.js/, ); diff --git a/packages/jest-jasmine2/src/index.js b/packages/jest-jasmine2/src/index.js index 3e822d1420c8..9f144d349a9f 100644 --- a/packages/jest-jasmine2/src/index.js +++ b/packages/jest-jasmine2/src/index.js @@ -17,6 +17,7 @@ import type Runtime from 'jest-runtime'; import path from 'path'; import fs from 'graceful-fs'; import {getCallsite} from 'jest-util'; +import sourcemapSupport from 'source-map-support'; import JasmineReporter from './reporter'; import {install as jasmineAsyncInstall} from './jasmine_async'; @@ -116,29 +117,35 @@ async function jasmine2( runtime.requireModule(config.setupTestFrameworkScriptFile); } + const sourcemapOptions = { + environment: 'node', + handleUncaughtExceptions: false, + retrieveSourceMap: source => { + const sourceMaps = runtime.getSourceMaps(); + const sourceMapSource = sourceMaps && sourceMaps[source]; + + if (sourceMapSource) { + try { + return { + map: JSON.parse(fs.readFileSync(sourceMapSource)), + url: source, + }; + } catch (e) {} + } + return null; + }, + }; + + // For tests runtime .requireInternalModule( require.resolve('source-map-support'), 'source-map-support', ) - .install({ - environment: 'node', - handleUncaughtExceptions: false, - retrieveSourceMap: source => { - const sourceMaps = runtime.getSourceMaps(); - const sourceMapSource = sourceMaps && sourceMaps[source]; - - if (sourceMapSource) { - try { - return { - map: JSON.parse(fs.readFileSync(sourceMapSource)), - url: source, - }; - } catch (e) {} - } - return null; - }, - }); + .install(sourcemapOptions); + + // For runtime errors + sourcemapSupport.install(sourcemapOptions); if (globalConfig.enabledTestsMap) { env.specFilter = spec => {