Skip to content

Commit 3341d16

Browse files
SimenBcpojer
authored andcommitted
install sourcecmap-support into normal runtime as well (#5945)
Fixes #5925
1 parent e393469 commit 3341d16

File tree

3 files changed

+28
-18
lines changed

3 files changed

+28
-18
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@
6161

6262
### Fixes
6363

64+
* `[jest-jasmine2]` Install `sourcemap-support` into normal runtime to catch
65+
runtime errors ([#5945](https://github.com/facebook/jest/pull/5945))
6466
* `[jest-jasmine2]` Added assertion error handling inside `afterAll hook`
6567
([#5884](https://github.com/facebook/jest/pull/5884))
6668
* `[jest-cli]` Remove the notifier actions in case of failure when not in watch

integration-tests/__tests__/stack_trace.test.js

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ describe('Stack Trace', () => {
2222
expect(stderr).toMatch(
2323
/ReferenceError: thisIsARuntimeError is not defined/,
2424
);
25+
expect(stderr).toMatch(/> 10 \| thisIsARuntimeError\(\);/);
2526
expect(stderr).toMatch(
2627
/\s+at\s(?:.+?)\s\(__tests__\/runtime_error.test\.js/,
2728
);

packages/jest-jasmine2/src/index.js

+25-18
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import type Runtime from 'jest-runtime';
1717
import path from 'path';
1818
import fs from 'graceful-fs';
1919
import {getCallsite} from 'jest-util';
20+
import sourcemapSupport from 'source-map-support';
2021
import JasmineReporter from './reporter';
2122
import {install as jasmineAsyncInstall} from './jasmine_async';
2223

@@ -116,29 +117,35 @@ async function jasmine2(
116117
runtime.requireModule(config.setupTestFrameworkScriptFile);
117118
}
118119

120+
const sourcemapOptions = {
121+
environment: 'node',
122+
handleUncaughtExceptions: false,
123+
retrieveSourceMap: source => {
124+
const sourceMaps = runtime.getSourceMaps();
125+
const sourceMapSource = sourceMaps && sourceMaps[source];
126+
127+
if (sourceMapSource) {
128+
try {
129+
return {
130+
map: JSON.parse(fs.readFileSync(sourceMapSource)),
131+
url: source,
132+
};
133+
} catch (e) {}
134+
}
135+
return null;
136+
},
137+
};
138+
139+
// For tests
119140
runtime
120141
.requireInternalModule(
121142
require.resolve('source-map-support'),
122143
'source-map-support',
123144
)
124-
.install({
125-
environment: 'node',
126-
handleUncaughtExceptions: false,
127-
retrieveSourceMap: source => {
128-
const sourceMaps = runtime.getSourceMaps();
129-
const sourceMapSource = sourceMaps && sourceMaps[source];
130-
131-
if (sourceMapSource) {
132-
try {
133-
return {
134-
map: JSON.parse(fs.readFileSync(sourceMapSource)),
135-
url: source,
136-
};
137-
} catch (e) {}
138-
}
139-
return null;
140-
},
141-
});
145+
.install(sourcemapOptions);
146+
147+
// For runtime errors
148+
sourcemapSupport.install(sourcemapOptions);
142149

143150
if (globalConfig.enabledTestsMap) {
144151
env.specFilter = spec => {

0 commit comments

Comments
 (0)