Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

let transformers adjust cache key based on mapCoverage #4187

Merged
merged 1 commit into from
Aug 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`ScriptTransformer passes expected transform options to getCacheKey 1`] = `
Object {
"instrument": true,
"mapCoverage": true,
}
`;

exports[`ScriptTransformer transforms a file properly 1`] = `
"({\\"Object.<anonymous>\\":function(module,exports,require,__dirname,__filename,global,jest){/* istanbul ignore next */var cov_25u22311x4 = function () {var path = \\"/fruits/banana.js\\",hash = \\"04636d4ae73b4b3e24bf6fba39e08c946fd0afb5\\",global = new Function('return this')(),gcv = \\"__coverage__\\",coverageData = { path: \\"/fruits/banana.js\\", statementMap: { \\"0\\": { start: { line: 1, column: 0 }, end: { line: 1, column: 26 } } }, fnMap: {}, branchMap: {}, s: { \\"0\\": 0 }, f: {}, b: {}, _coverageSchema: \\"332fd63041d2c1bcb487cc26dd0d5f7d97098a6c\\" },coverage = global[gcv] || (global[gcv] = {});if (coverage[path] && coverage[path].hash === hash) {return coverage[path];}coverageData.hash = hash;return coverage[path] = coverageData;}();++cov_25u22311x4.s[0];module.exports = \\"banana\\";
}});"
Expand Down
15 changes: 15 additions & 0 deletions packages/jest-runtime/src/__tests__/script_transformer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,21 @@ describe('ScriptTransformer', () => {
expect(writeFileAtomic.sync).toHaveBeenCalledTimes(1);
});

it('passes expected transform options to getCacheKey', () => {
config = Object.assign(config, {
transform: [['^.+\\.js$', 'test_preprocessor']],
});
const scriptTransformer = new ScriptTransformer(config);

scriptTransformer.transform('/fruits/banana.js', {
collectCoverage: true,
mapCoverage: true,
});

const {getCacheKey} = require('test_preprocessor');
expect(getCacheKey.mock.calls[0][3]).toMatchSnapshot();
});

it('reads values from the cache', () => {
const transformConfig = Object.assign(config, {
transform: [['^.+\\.js$', 'test_preprocessor']],
Expand Down
1 change: 1 addition & 0 deletions packages/jest-runtime/src/script_transformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class ScriptTransformer {
.update(
transformer.getCacheKey(fileData, filename, configString, {
instrument,
mapCoverage,
}),
)
.update(CACHE_VERSION)
Expand Down
7 changes: 6 additions & 1 deletion types/Transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ export type TransformOptions = {|
instrument: boolean,
|};

export type CacheKeyOptions = {|
instrument: boolean,
mapCoverage: boolean,
|};

export type Transformer = {|
canInstrument?: boolean,
createTransformer(options: any): Transformer,
Expand All @@ -33,7 +38,7 @@ export type Transformer = {|
fileData: string,
filePath: Path,
configStr: string,
options: TransformOptions,
options: CacheKeyOptions,
) => string,

process: (
Expand Down