-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Improve source map handling when instrumenting transformed code (#5739) #9811
Merged
Merged
Changes from 14 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
9174c60
Improve source map handling when instrumenting transformed code (#5739)
118c951
Remove the concept of using Jest's stored sourceMaps to map BabelCove…
40fcece
Remove use of mapCoverage in jest-runtime.
6adade9
Restore 'mapCoverage' as a nullable field on TransformResult.
5a02bb1
Removing more code downstream of 'mapCoverage' in jest-runtime.
fcc7383
Add test arounds stack traces for code which is both transformed and …
472b882
Update changelog.
a24fbe6
Feedback - add Jest 26 TODO for restructuring TransformedSource.
4cc5905
Feedback - rephrase determination of 'shouldEmitSourceMap'
28ccbf4
Merge branch 'master' into coverage-maps-patch
SimenB 7aff546
Remove unused __needsCoverageMapped property.
63324f3
Convert stack trace test to a snapshot test.
30ec3c5
Restore comment in stack trace test.
f0e256f
Update snapshot to extract 'rest' from summary and wrap.
3a30ae1
Lint fix - import order.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
20 changes: 20 additions & 0 deletions
20
e2e/__tests__/__snapshots__/stackTraceSourceMapsWithCoverage.test.ts.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,20 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`processes stack traces and code frames with source maps with coverage 1`] = ` | ||
FAIL __tests__/fails.ts | ||
✕ fails | ||
|
||
● fails | ||
|
||
This did not work! | ||
|
||
11 | | ||
12 | export function error() { | ||
> 13 | throw new Error('This did not work!'); | ||
| ^ | ||
14 | } | ||
15 | | ||
|
||
at Object.error (lib.ts:13:9) | ||
at Object.<anonymous> (__tests__/fails.ts:10:3) | ||
`; | ||
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,22 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. 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. | ||
*/ | ||
import * as path from 'path'; | ||
import {extractSummary, run} from '../Utils'; | ||
import runJest from '../runJest'; | ||
import wrap from 'jest-snapshot-serializer-raw'; | ||
SimenB marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
it('processes stack traces and code frames with source maps with coverage', () => { | ||
const dir = path.resolve( | ||
__dirname, | ||
'../stack-trace-source-maps-with-coverage', | ||
); | ||
run('yarn', dir); | ||
const {stderr} = runJest(dir, ['--no-cache', '--coverage']); | ||
|
||
// Should report an error at source line 13 in lib.ts at line 10 of the test | ||
expect(wrap(extractSummary(stderr).rest)).toMatchSnapshot(); | ||
}); |
11 changes: 11 additions & 0 deletions
11
e2e/stack-trace-source-maps-with-coverage/__tests__/fails.ts
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,11 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. 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. | ||
*/ | ||
import {error} from '../lib'; | ||
|
||
it('fails', () => { | ||
error(); | ||
}); |
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,14 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. 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. | ||
*/ | ||
interface NotUsedButTakesUpLines { | ||
a: number; | ||
b: string; | ||
} | ||
|
||
export function error() { | ||
throw new Error('This did not work!'); | ||
} |
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 @@ | ||
{ | ||
"jest": { | ||
"rootDir": "./", | ||
"transform": { | ||
"^.+\\.(ts)$": "<rootDir>/preprocessor.js" | ||
}, | ||
"testEnvironment": "node", | ||
"testRegex": "fails" | ||
}, | ||
"dependencies": { | ||
"typescript": "^3.7.4" | ||
} | ||
} |
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,21 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. 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 tsc = require('typescript'); | ||
|
||
module.exports = { | ||
process(src, path) { | ||
return tsc.transpileModule(src, { | ||
compilerOptions: { | ||
inlineSourceMap: true, | ||
module: tsc.ModuleKind.CommonJS, | ||
target: 'es5', | ||
}, | ||
fileName: path, | ||
}).outputText; | ||
}, | ||
}; |
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,8 @@ | ||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
# yarn lockfile v1 | ||
|
||
|
||
typescript@^3.7.4: | ||
version "3.8.3" | ||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.8.3.tgz#409eb8544ea0335711205869ec458ab109ee1061" | ||
integrity sha512-MYlEfn5VrLNsgudQTVJeNaQFUAI7DkhnOjdpAp4T+ku1TfQClewlbSuTVHiA+8skNBgaf02TL/kLOvig4y3G8w== |
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
For posterity (if we ever come back to this and wonder why we pass sourcemap into Babel), this is the error if running this test without the other changes in this PR