-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Removing the mapCoverage condition on reading inlineSourceMaps. #5177
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
Changes from 1 commit
00cb000
f927798
fdefcaa
c1f6712
970c94f
5f17ea3
936c4cc
62f3b31
520a141
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…rumented by us * Feat: Return sourcemap from babel-jest
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -95,6 +95,7 @@ class Runtime { | |
| _mockRegistry: {[key: string]: any, __proto__: null}; | ||
| _moduleMocker: ModuleMocker; | ||
| _moduleRegistry: ModuleRegistry; | ||
| _needsCoverageMapped: string[]; | ||
| _resolver: Resolver; | ||
| _shouldAutoMock: boolean; | ||
| _shouldMockModuleCache: BooleanObject; | ||
|
|
@@ -129,6 +130,7 @@ class Runtime { | |
| this._mockRegistry = Object.create(null); | ||
| this._moduleMocker = this._environment.moduleMocker; | ||
| this._moduleRegistry = Object.create(null); | ||
| this._needsCoverageMapped = []; | ||
|
||
| this._resolver = resolver; | ||
| this._scriptTransformer = new ScriptTransformer(config); | ||
| this._shouldAutoMock = config.automock; | ||
|
|
@@ -435,10 +437,10 @@ class Runtime { | |
| return deepCyclicCopy(this._environment.global.__coverage__); | ||
| } | ||
|
|
||
| getSourceMapInfo(coveredFiles: Array<string>) { | ||
| getSourceMapInfo() { | ||
| return Object.keys(this._sourceMapRegistry).reduce((result, sourcePath) => { | ||
| if ( | ||
| coveredFiles.includes(sourcePath) && | ||
| this._needsCoverageMapped.includes(sourcePath) && | ||
| fs.existsSync(this._sourceMapRegistry[sourcePath]) | ||
| ) { | ||
| result[sourcePath] = this._sourceMapRegistry[sourcePath]; | ||
|
|
@@ -533,6 +535,9 @@ class Runtime { | |
|
|
||
| if (transformedFile.sourceMapPath) { | ||
| this._sourceMapRegistry[filename] = transformedFile.sourceMapPath; | ||
| if (transformedFile.mapCoverage) { | ||
| this._needsCoverageMapped.push(filename); | ||
| } | ||
| } | ||
|
|
||
| const wrapper = this._environment.runScript(transformedFile.script)[ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -185,13 +185,26 @@ export default class ScriptTransformer { | |
| // Ignore cache if `config.cache` is set (--no-cache) | ||
| let code = this._config.cache ? readCodeCacheFile(cacheFilePath) : null; | ||
|
|
||
| const shouldCallTransform = | ||
| transform && shouldTransform(filename, this._config); | ||
|
|
||
| // That means that the transform has a custom instrumentation | ||
| // logic and will handle it based on `config.collectCoverage` option | ||
| const transformWillInstrument = | ||
| shouldCallTransform && transform && transform.canInstrument; | ||
|
|
||
| // If we handle the coverage instrumentation, we should try to map code | ||
| // coverage against original source with any provided source map | ||
| const mapCoverage = instrument && !transformWillInstrument; | ||
|
|
||
| if (code) { | ||
| // This is broken: we return the code, and a path for the source map | ||
| // directly from the cache. But, nothing ensures the source map actually | ||
| // matches that source code. They could have gotten out-of-sync in case | ||
| // two separate processes write concurrently to the same cache files. | ||
| return { | ||
| code, | ||
| mapCoverage, | ||
| sourceMapPath, | ||
| }; | ||
| } | ||
|
|
@@ -201,7 +214,7 @@ export default class ScriptTransformer { | |
| map: null, | ||
| }; | ||
|
|
||
| if (transform && shouldTransform(filename, this._config)) { | ||
| if (transform && shouldCallTransform) { | ||
| const processed = transform.process(content, filename, this._config, { | ||
| instrument, | ||
| returnSourceString: false, | ||
|
||
|
|
@@ -228,11 +241,7 @@ export default class ScriptTransformer { | |
| } | ||
| } | ||
|
|
||
| // That means that the transform has a custom instrumentation | ||
| // logic and will handle it based on `config.collectCoverage` option | ||
| const transformDidInstrument = transform && transform.canInstrument; | ||
|
|
||
| if (!transformDidInstrument && instrument) { | ||
| if (!transformWillInstrument && instrument) { | ||
| code = this._instrumentFile(filename, transformed.code); | ||
| } else { | ||
| code = transformed.code; | ||
|
|
@@ -252,6 +261,7 @@ export default class ScriptTransformer { | |
|
|
||
| return { | ||
| code, | ||
| mapCoverage, | ||
| sourceMapPath, | ||
| }; | ||
| } | ||
|
|
@@ -270,6 +280,7 @@ export default class ScriptTransformer { | |
|
|
||
| let wrappedCode: string; | ||
| let sourceMapPath: ?string = null; | ||
| let mapCoverage = false; | ||
|
|
||
| const willTransform = | ||
| !isInternalModule && | ||
|
|
@@ -286,11 +297,13 @@ export default class ScriptTransformer { | |
|
|
||
| wrappedCode = wrap(transformedSource.code); | ||
| sourceMapPath = transformedSource.sourceMapPath; | ||
| mapCoverage = transformedSource.mapCoverage; | ||
| } else { | ||
| wrappedCode = wrap(content); | ||
| } | ||
|
|
||
| return { | ||
| mapCoverage, | ||
| script: new vm.Script(wrappedCode, { | ||
| displayErrors: true, | ||
| filename: isCoreModule ? 'jest-nodejs-core-' + filename : filename, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this condition is wrong.
Should be
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so that if
transformOptionsis not passed inshouldReturnCodeOnly === trueThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
potentially
to be explicit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Waiting for this change before merging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm outside. I'll change n push in an hour.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is pushed!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should have a test for this - mind adding one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay. Will add and push.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!