diff --git a/packages/jest-jasmine2/package.json b/packages/jest-jasmine2/package.json index 26a66b128f71..4294b52e67de 100644 --- a/packages/jest-jasmine2/package.json +++ b/packages/jest-jasmine2/package.json @@ -18,8 +18,7 @@ "jest-message-util": "^22.4.0", "jest-snapshot": "^22.4.0", "jest-util": "^22.4.1", - "pretty-format": "^22.4.0", - "source-map-support": "^0.5.6" + "pretty-format": "^22.4.0" }, "devDependencies": { "jest-runtime": "^22.4.2" diff --git a/packages/jest-jasmine2/src/index.js b/packages/jest-jasmine2/src/index.js index e29172a4a8fe..d91995855159 100644 --- a/packages/jest-jasmine2/src/index.js +++ b/packages/jest-jasmine2/src/index.js @@ -18,7 +18,6 @@ import path from 'path'; import fs from 'graceful-fs'; import installEach from './each'; import {getCallsite} from 'jest-util'; -import sourcemapSupport from 'source-map-support'; import JasmineReporter from './reporter'; import {install as jasmineAsyncInstall} from './jasmine_async'; @@ -120,36 +119,6 @@ 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(sourcemapOptions); - - // For runtime errors - sourcemapSupport.install(sourcemapOptions); - if (globalConfig.enabledTestsMap) { env.specFilter = spec => { const suiteMap = @@ -162,16 +131,12 @@ async function jasmine2( env.specFilter = spec => testNameRegex.test(spec.getFullName()); } - try { - runtime.requireModule(testPath); - await env.execute(); + runtime.requireModule(testPath); + await env.execute(); - const results = await reporter.getResults(); + const results = await reporter.getResults(); - return addSnapshotData(results, snapshotState); - } finally { - sourcemapSupport.resetRetrieveHandlers(); - } + return addSnapshotData(results, snapshotState); } const addSnapshotData = (results, snapshotState) => { diff --git a/packages/jest-runner/package.json b/packages/jest-runner/package.json index a086ba78223f..2cf2addca4c3 100644 --- a/packages/jest-runner/package.json +++ b/packages/jest-runner/package.json @@ -18,6 +18,7 @@ "jest-runtime": "^22.4.2", "jest-util": "^22.4.1", "jest-worker": "^22.2.2", + "source-map-support": "^0.5.6", "throat": "^4.0.0" } } diff --git a/packages/jest-runner/src/run_test.js b/packages/jest-runner/src/run_test.js index a209ffca7c51..517e6704a76d 100644 --- a/packages/jest-runner/src/run_test.js +++ b/packages/jest-runner/src/run_test.js @@ -26,6 +26,7 @@ import jasmine2 from 'jest-jasmine2'; import LeakDetector from 'jest-leak-detector'; import {getTestEnvironment} from 'jest-config'; import * as docblock from 'jest-docblock'; +import sourcemapSupport from 'source-map-support'; type RunTestInternalResult = { leakDetector: ?LeakDetector, @@ -116,8 +117,42 @@ async function runTestInternal( }); const start = Date.now(); - await environment.setup(); + + + + 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(sourcemapOptions); + + // For runtime errors + sourcemapSupport.install(sourcemapOptions); + try { + await environment.setup(); + const result: TestResult = await testFramework( globalConfig, config, @@ -151,6 +186,8 @@ async function runTestInternal( }); } finally { await environment.teardown(); + + sourcemapSupport.resetRetrieveHandlers(); } }