diff --git a/CHANGELOG.md b/CHANGELOG.md index 67f6ac0a17c8..5193d38f60e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,8 @@ ([#5658](https://github.com/facebook/jest/pull/5658)) * `[jest-cli]` Improve the error message when 2 projects resolve to the same config ([#5674](https://github.com/facebook/jest/pull/5674)) +* `[jest-runtime]` remove retainLines from coverage instrumentation + ([#5692](https://github.com/facebook/jest/pull/5692)) ## 22.4.2 diff --git a/docs/TutorialReact.md b/docs/TutorialReact.md index c8704c686f9a..f1f334304c0f 100644 --- a/docs/TutorialReact.md +++ b/docs/TutorialReact.md @@ -311,8 +311,7 @@ module.exports = { return babel.transform(src, { filename, presets: [jestPreset], - retainLines: true, - }).code; + }); } return src; }, diff --git a/packages/jest-runtime/src/__tests__/__snapshots__/script_transformer.test.js.snap b/packages/jest-runtime/src/__tests__/__snapshots__/script_transformer.test.js.snap index 5a93794d39b7..57301d112b4e 100644 --- a/packages/jest-runtime/src/__tests__/__snapshots__/script_transformer.test.js.snap +++ b/packages/jest-runtime/src/__tests__/__snapshots__/script_transformer.test.js.snap @@ -8,12 +8,134 @@ Object { `; exports[`ScriptTransformer transforms a file properly 1`] = ` -"({\\"Object.\\":function(module,exports,require,__dirname,__filename,global,jest){/* istanbul ignore next */var cov_25u22311x4 = function () {var path = \\"/fruits/banana.js\\",hash = \\"04636d4ae73b4b3e24bf6fba39e08c946fd0afb5\\",Function = function () {}.constructor,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\\"; +"({\\"Object.\\":function(module,exports,require,__dirname,__filename,global,jest){/* istanbul ignore next */var cov_25u22311x4 = function () { + var path = \\"/fruits/banana.js\\", + hash = \\"04636d4ae73b4b3e24bf6fba39e08c946fd0afb5\\", + Function = function () {}.constructor, + 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\\"; }});" `; exports[`ScriptTransformer transforms a file properly 2`] = ` -"({\\"Object.\\":function(module,exports,require,__dirname,__filename,global,jest){/* istanbul ignore next */var cov_23yvu8etmu = function () {var path = \\"/fruits/kiwi.js\\",hash = \\"58d742d8c615e16eb5dffec9322e6ed1babde8f3\\",Function = function () {}.constructor,global = new Function('return this')(),gcv = \\"__coverage__\\",coverageData = { path: \\"/fruits/kiwi.js\\", statementMap: { \\"0\\": { start: { line: 1, column: 0 }, end: { line: 1, column: 30 } }, \\"1\\": { start: { line: 1, column: 23 }, end: { line: 1, column: 29 } } }, fnMap: { \\"0\\": { name: \\"(anonymous_0)\\", decl: { start: { line: 1, column: 17 }, end: { line: 1, column: 18 } }, loc: { start: { line: 1, column: 23 }, end: { line: 1, column: 29 } }, line: 1 } }, branchMap: {}, s: { \\"0\\": 0, \\"1\\": 0 }, f: { \\"0\\": 0 }, 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_23yvu8etmu.s[0]++;module.exports = () => {/* istanbul ignore next */cov_23yvu8etmu.f[0]++;cov_23yvu8etmu.s[1]++;return \\"kiwi\\";}; +"({\\"Object.\\":function(module,exports,require,__dirname,__filename,global,jest){/* istanbul ignore next */var cov_23yvu8etmu = function () { + var path = \\"/fruits/kiwi.js\\", + hash = \\"58d742d8c615e16eb5dffec9322e6ed1babde8f3\\", + Function = function () {}.constructor, + global = new Function('return this')(), + gcv = \\"__coverage__\\", + coverageData = { + path: \\"/fruits/kiwi.js\\", + statementMap: { + \\"0\\": { + start: { + line: 1, + column: 0 + }, + end: { + line: 1, + column: 30 + } + }, + \\"1\\": { + start: { + line: 1, + column: 23 + }, + end: { + line: 1, + column: 29 + } + } + }, + fnMap: { + \\"0\\": { + name: \\"(anonymous_0)\\", + decl: { + start: { + line: 1, + column: 17 + }, + end: { + line: 1, + column: 18 + } + }, + loc: { + start: { + line: 1, + column: 23 + }, + end: { + line: 1, + column: 29 + } + }, + line: 1 + } + }, + branchMap: {}, + s: { + \\"0\\": 0, + \\"1\\": 0 + }, + f: { + \\"0\\": 0 + }, + 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_23yvu8etmu.s[0]++; +module.exports = () => { + /* istanbul ignore next */cov_23yvu8etmu.f[0]++; + cov_23yvu8etmu.s[1]++; + return \\"kiwi\\"; +}; }});" `; diff --git a/packages/jest-runtime/src/script_transformer.js b/packages/jest-runtime/src/script_transformer.js index 019cf2718e4b..cdddfb5b531f 100644 --- a/packages/jest-runtime/src/script_transformer.js +++ b/packages/jest-runtime/src/script_transformer.js @@ -165,7 +165,6 @@ export default class ScriptTransformer { }, ], ], - retainLines: true, }).code; }