Skip to content

Commit

Permalink
move sourcemaps from jest-jasmine to jest-runner
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed May 13, 2018
1 parent 6b10f31 commit 8f9aaad
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 42 deletions.
3 changes: 1 addition & 2 deletions packages/jest-jasmine2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
43 changes: 4 additions & 39 deletions packages/jest-jasmine2/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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 =
Expand All @@ -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) => {
Expand Down
1 change: 1 addition & 0 deletions packages/jest-runner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
39 changes: 38 additions & 1 deletion packages/jest-runner/src/run_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -151,6 +186,8 @@ async function runTestInternal(
});
} finally {
await environment.teardown();

sourcemapSupport.resetRetrieveHandlers();
}
}

Expand Down

0 comments on commit 8f9aaad

Please sign in to comment.