-
-
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.
Improve source map handling when instrumenting transformed code (#9811)
- Loading branch information
Showing
18 changed files
with
249 additions
and
86 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
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 wrap from 'jest-snapshot-serializer-raw'; | ||
import {extractSummary, run} from '../Utils'; | ||
import runJest from '../runJest'; | ||
|
||
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.