Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8f9aaad

Browse files
committedMay 13, 2018
move sourcemaps from jest-jasmine to jest-runner
1 parent 6b10f31 commit 8f9aaad

File tree

4 files changed

+44
-42
lines changed

4 files changed

+44
-42
lines changed
 

‎packages/jest-jasmine2/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
"jest-message-util": "^22.4.0",
1919
"jest-snapshot": "^22.4.0",
2020
"jest-util": "^22.4.1",
21-
"pretty-format": "^22.4.0",
22-
"source-map-support": "^0.5.6"
21+
"pretty-format": "^22.4.0"
2322
},
2423
"devDependencies": {
2524
"jest-runtime": "^22.4.2"

‎packages/jest-jasmine2/src/index.js

+4-39
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ 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';
2221
import JasmineReporter from './reporter';
2322
import {install as jasmineAsyncInstall} from './jasmine_async';
2423

@@ -120,36 +119,6 @@ async function jasmine2(
120119
runtime.requireModule(config.setupTestFrameworkScriptFile);
121120
}
122121

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
143-
runtime
144-
.requireInternalModule(
145-
require.resolve('source-map-support'),
146-
'source-map-support',
147-
)
148-
.install(sourcemapOptions);
149-
150-
// For runtime errors
151-
sourcemapSupport.install(sourcemapOptions);
152-
153122
if (globalConfig.enabledTestsMap) {
154123
env.specFilter = spec => {
155124
const suiteMap =
@@ -162,16 +131,12 @@ async function jasmine2(
162131
env.specFilter = spec => testNameRegex.test(spec.getFullName());
163132
}
164133

165-
try {
166-
runtime.requireModule(testPath);
167-
await env.execute();
134+
runtime.requireModule(testPath);
135+
await env.execute();
168136

169-
const results = await reporter.getResults();
137+
const results = await reporter.getResults();
170138

171-
return addSnapshotData(results, snapshotState);
172-
} finally {
173-
sourcemapSupport.resetRetrieveHandlers();
174-
}
139+
return addSnapshotData(results, snapshotState);
175140
}
176141

177142
const addSnapshotData = (results, snapshotState) => {

‎packages/jest-runner/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"jest-runtime": "^22.4.2",
1919
"jest-util": "^22.4.1",
2020
"jest-worker": "^22.2.2",
21+
"source-map-support": "^0.5.6",
2122
"throat": "^4.0.0"
2223
}
2324
}

‎packages/jest-runner/src/run_test.js

+38-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import jasmine2 from 'jest-jasmine2';
2626
import LeakDetector from 'jest-leak-detector';
2727
import {getTestEnvironment} from 'jest-config';
2828
import * as docblock from 'jest-docblock';
29+
import sourcemapSupport from 'source-map-support';
2930

3031
type RunTestInternalResult = {
3132
leakDetector: ?LeakDetector,
@@ -116,8 +117,42 @@ async function runTestInternal(
116117
});
117118

118119
const start = Date.now();
119-
await environment.setup();
120+
121+
122+
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
143+
runtime
144+
.requireInternalModule(
145+
require.resolve('source-map-support'),
146+
'source-map-support',
147+
)
148+
.install(sourcemapOptions);
149+
150+
// For runtime errors
151+
sourcemapSupport.install(sourcemapOptions);
152+
120153
try {
154+
await environment.setup();
155+
121156
const result: TestResult = await testFramework(
122157
globalConfig,
123158
config,
@@ -151,6 +186,8 @@ async function runTestInternal(
151186
});
152187
} finally {
153188
await environment.teardown();
189+
190+
sourcemapSupport.resetRetrieveHandlers();
154191
}
155192
}
156193

0 commit comments

Comments
 (0)
Please sign in to comment.