Skip to content

Commit eb3d77e

Browse files
committed
Revert "Revert jestjs#5945, as it introduces a memory leak (jestjs#6106)"
This reverts commit 45cd277.
1 parent 753ae9b commit eb3d77e

File tree

4 files changed

+30
-20
lines changed

4 files changed

+30
-20
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@
104104
([#5888](https://github.com/facebook/jest/pull/5888))
105105
* `[jest-mock]` [**BREAKING**] Replace timestamps with `invocationCallOrder`
106106
([#5867](https://github.com/facebook/jest/pull/5867))
107+
* `[jest-jasmine2]` Install `sourcemap-support` into normal runtime to catch
108+
runtime errors ([#5945](https://github.com/facebook/jest/pull/5945))
107109
* `[jest-jasmine2]` Added assertion error handling inside `afterAll hook`
108110
([#5884](https://github.com/facebook/jest/pull/5884))
109111
* `[jest-cli]` Remove the notifier actions in case of failure when not in watch

integration-tests/__tests__/__snapshots__/globals.test.js.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ exports[`cannot test with no implementation 1`] = `
2828
1 |
2929
2 | it('it', () => {});
3030
> 3 | it('it, no implementation');
31-
| ^
31+
| ^
3232
4 | test('test, no implementation');
3333
5 |
3434
@@ -56,7 +56,7 @@ exports[`cannot test with no implementation with expand arg 1`] = `
5656
1 |
5757
2 | it('it', () => {});
5858
> 3 | it('it, no implementation');
59-
| ^
59+
| ^
6060
4 | test('test, no implementation');
6161
5 |
6262

integration-tests/__tests__/stack_trace.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ describe('Stack Trace', () => {
2121
expect(stderr).toMatch(
2222
/ReferenceError: thisIsARuntimeError is not defined/,
2323
);
24+
expect(stderr).toMatch(/> 10 \| thisIsARuntimeError\(\);/);
2425
expect(stderr).toMatch(
2526
/\s+at\s(?:.+?)\s\(__tests__\/runtime_error.test\.js/,
2627
);

packages/jest-jasmine2/src/index.js

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import path from 'path';
1818
import fs from 'graceful-fs';
1919
import installEach from './each';
2020
import {getCallsite} from 'jest-util';
21+
import sourcemapSupport from 'source-map-support';
2122
import JasmineReporter from './reporter';
2223
import {install as jasmineAsyncInstall} from './jasmine_async';
2324

@@ -119,29 +120,35 @@ async function jasmine2(
119120
runtime.requireModule(config.setupTestFrameworkScriptFile);
120121
}
121122

123+
const sourcemapOptions = {
124+
environment: 'node',
125+
handleUncaughtExceptions: false,
126+
retrieveSourceMap: source => {
127+
const sourceMaps = runtime.getSourceMaps();
128+
const sourceMapSource = sourceMaps && sourceMaps[source];
129+
130+
if (sourceMapSource) {
131+
try {
132+
return {
133+
map: JSON.parse(fs.readFileSync(sourceMapSource)),
134+
url: source,
135+
};
136+
} catch (e) {}
137+
}
138+
return null;
139+
},
140+
};
141+
142+
// For tests
122143
runtime
123144
.requireInternalModule(
124145
require.resolve('source-map-support'),
125146
'source-map-support',
126147
)
127-
.install({
128-
environment: 'node',
129-
handleUncaughtExceptions: false,
130-
retrieveSourceMap: source => {
131-
const sourceMaps = runtime.getSourceMaps();
132-
const sourceMapSource = sourceMaps && sourceMaps[source];
133-
134-
if (sourceMapSource) {
135-
try {
136-
return {
137-
map: JSON.parse(fs.readFileSync(sourceMapSource)),
138-
url: source,
139-
};
140-
} catch (e) {}
141-
}
142-
return null;
143-
},
144-
});
148+
.install(sourcemapOptions);
149+
150+
// For runtime errors
151+
sourcemapSupport.install(sourcemapOptions);
145152

146153
if (globalConfig.enabledTestsMap) {
147154
env.specFilter = spec => {

0 commit comments

Comments
 (0)