Skip to content

Commit

Permalink
Test the new source map behavior
Browse files Browse the repository at this point in the history
Under the new transformer rules, if the transformer provides us a
sourcemap, we'll take it, regardless of the coverage settings. This
means source maps are cached alongside the originals, and `Runtime`
will populate its `_sourceMapRegistry`
  • Loading branch information
felipeochoa committed May 3, 2017
1 parent 12c788a commit abc1508
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion packages/jest-runtime/src/__tests__/ScriptTransformer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ describe('ScriptTransformer', () => {
);
});

it('does not write source map if mapCoverage option is false', () => {
it('writes source maps if given by the transformer', () => {
config = Object.assign(config, {
transform: [['^.+\\.js$', 'preprocessor-with-sourcemaps']],
});
Expand All @@ -292,6 +292,29 @@ describe('ScriptTransformer', () => {
map,
});

const result = scriptTransformer.transform('/fruits/banana.js', {
collectCoverage: true,
mapCoverage: false,
});
expect(result.sourceMapPath).toEqual(expect.any(String));
expect(fs.writeFileSync).toBeCalledWith(
result.sourceMapPath,
JSON.stringify(map),
'utf8',
);
});

it('does not write source map if not given by the transformer', () => {
config = Object.assign(config, {
transform: [['^.+\\.js$', 'preprocessor-with-sourcemaps']],
});
const scriptTransformer = new ScriptTransformer(config);

require('preprocessor-with-sourcemaps').process.mockReturnValue({
code: 'content',
map: null,
});

const result = scriptTransformer.transform('/fruits/banana.js', {
collectCoverage: true,
mapCoverage: false,
Expand Down

0 comments on commit abc1508

Please sign in to comment.