-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removing the mapCoverage condition on reading inlineSourceMaps. (#5177)
* * Removed usage of mapCoverage on reading inline sourcemaps. * Removed usage of instrument check before saving file into cache. * Passing sourceMaps only for files on which the coverage was obtained * Updated the changelog * Removed usage of mapCoverage from codebase * * Maintaining internal mapCoverage, map only for files which are instrumented by us * Feat: Return sourcemap from babel-jest * Adding back retainLines * * Removed the mapCoverage from docs * Updated the integration testcases * Remove mapCoverage from code base and add deprecation warning * Get sourcemaps only for the files covered in testcases * Updated the condition in babel-jest to prevent breaking changes for the existing users * Added some tests for babel-jest
- Loading branch information
Showing
36 changed files
with
1,612 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
integration-tests/__tests__/__snapshots__/coverage_transform_instrumented.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`code coverage for transform instrumented code 1`] = ` | ||
Object { | ||
"covered.js": Object { | ||
"_coverageSchema": "332fd63041d2c1bcb487cc26dd0d5f7d97098a6c", | ||
"b": Object {}, | ||
"branchMap": Object {}, | ||
"f": Object { | ||
"0": 1, | ||
}, | ||
"fnMap": Object { | ||
"0": Object { | ||
"decl": Object { | ||
"end": Object { | ||
"column": 36, | ||
"line": 9, | ||
}, | ||
"start": Object { | ||
"column": 26, | ||
"line": 9, | ||
}, | ||
}, | ||
"line": 9, | ||
"loc": Object { | ||
"end": Object { | ||
"column": 1, | ||
"line": 12, | ||
}, | ||
"start": Object { | ||
"column": 58, | ||
"line": 9, | ||
}, | ||
}, | ||
"name": "doES6Stuff", | ||
}, | ||
}, | ||
"path": "covered.js", | ||
"s": Object { | ||
"0": 1, | ||
"1": 1, | ||
"2": 1, | ||
}, | ||
"statementMap": Object { | ||
"0": Object { | ||
"end": Object { | ||
"column": 2, | ||
"line": 12, | ||
}, | ||
"start": Object { | ||
"column": 0, | ||
"line": 9, | ||
}, | ||
}, | ||
"1": Object { | ||
"end": Object { | ||
"column": 41, | ||
"line": 10, | ||
}, | ||
"start": Object { | ||
"column": 34, | ||
"line": 10, | ||
}, | ||
}, | ||
"2": Object { | ||
"end": Object { | ||
"column": 33, | ||
"line": 11, | ||
}, | ||
"start": Object { | ||
"column": 2, | ||
"line": 11, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
integration-tests/__tests__/coverage_transform_instrumented.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const {readFileSync} = require('fs'); | ||
const path = require('path'); | ||
const {cleanup, run} = require('../Utils'); | ||
const runJest = require('../runJest'); | ||
|
||
const dir = path.resolve(__dirname, '../coverage-transform-instrumented'); | ||
const coverageDir = path.join(dir, 'coverage'); | ||
|
||
beforeAll(() => { | ||
cleanup(coverageDir); | ||
}); | ||
|
||
it('code coverage for transform instrumented code', () => { | ||
run('yarn', dir); | ||
const result = runJest(dir, ['--coverage', '--no-cache']); | ||
|
||
expect(result.status).toBe(0); | ||
|
||
const coverageMapFile = path.join(coverageDir, 'coverage-final.json'); | ||
const coverageMap = JSON.parse(readFileSync(coverageMapFile, 'utf-8')); | ||
|
||
// reduce absolute paths embedded in the coverage map to just filenames | ||
Object.keys(coverageMap).forEach(filename => { | ||
coverageMap[filename].path = path.basename(coverageMap[filename].path); | ||
delete coverageMap[filename].hash; | ||
coverageMap[path.basename(filename)] = coverageMap[filename]; | ||
delete coverageMap[filename]; | ||
}); | ||
expect(coverageMap).toMatchSnapshot(); | ||
}); |
23 changes: 23 additions & 0 deletions
23
integration-tests/__tests__/stack_trace_source_maps.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const path = require('path'); | ||
const {run} = require('../Utils'); | ||
const runJest = require('../runJest'); | ||
|
||
it('processes stack traces and code frames with source maps', () => { | ||
const dir = path.resolve(__dirname, '../stack-trace-source-maps'); | ||
run('yarn', dir); | ||
const {stderr} = runJest(dir, ['--no-cache']); | ||
expect(stderr).toMatch('> 14 | (() => expect(false).toBe(true))();'); | ||
expect(stderr).toMatch(`at __tests__/fails.ts:14:24 | ||
at Object.<anonymous> (__tests__/fails.ts:14:35)`); | ||
}); |
43 changes: 43 additions & 0 deletions
43
integration-tests/coverage-transform-instrumented/Preprocessor.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
const jestPreset = require('babel-preset-jest'); | ||
const babelTransform = require('babel-core').transform; | ||
const babelIstanbulPlugin = require('babel-plugin-istanbul').default; | ||
|
||
const options = { | ||
presets: ['env', jestPreset], | ||
retainLines: true, | ||
sourceMaps: 'inline', | ||
}; | ||
|
||
module.exports = { | ||
canInstrument: true, | ||
process(src, filename, config, transformOptions) { | ||
options.filename = filename; | ||
if (transformOptions && transformOptions.instrument) { | ||
options.auxiliaryCommentBefore = ' istanbul ignore next '; | ||
options.plugins = [ | ||
[ | ||
babelIstanbulPlugin, | ||
{ | ||
cwd: config.rootDir, | ||
exclude: [], | ||
}, | ||
], | ||
]; | ||
} | ||
|
||
const transformResult = babelTransform(src, options); | ||
|
||
if (!transformResult) { | ||
return src; | ||
} | ||
|
||
return transformResult.code; | ||
}, | ||
}; |
13 changes: 13 additions & 0 deletions
13
integration-tests/coverage-transform-instrumented/__tests__/covered-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
const doES6Stuff = require('../covered.js'); | ||
|
||
it('works correctly', () => { | ||
const someObj = {someNumber: 10, this: 'is irrelevant'}; | ||
expect(doES6Stuff(someObj, 2)).toBe(20); | ||
}); |
12 changes: 12 additions & 0 deletions
12
integration-tests/coverage-transform-instrumented/covered.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* eslint-disable no-unused-vars */ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
module.exports = function doES6Stuff(testObj, multiplier) { | ||
const {someNumber, ...others} = testObj; | ||
return someNumber * multiplier; | ||
}; |
20 changes: 20 additions & 0 deletions
20
integration-tests/coverage-transform-instrumented/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"jest": { | ||
"rootDir": "./", | ||
"transform": { | ||
"^.+\\.(js)$": "<rootDir>/Preprocessor.js" | ||
}, | ||
"testRegex": "/__tests__/.*\\.(js)$", | ||
"testEnvironment": "node", | ||
"moduleFileExtensions": ["js"] | ||
}, | ||
"babel": { | ||
"presets": ["env"] | ||
}, | ||
"dependencies": { | ||
"babel-core": "6.26.0", | ||
"babel-plugin-istanbul": "4.1.5", | ||
"babel-preset-env": "1.6.1", | ||
"babel-preset-jest": "22.2.0" | ||
} | ||
} |
Oops, something went wrong.