SnapshotCodeLensProvider crashes when working with TypeScript files
See original GitHub issueEnvironment
-
node -v
: v9.4.0 -
npm -v
: 6.2.0 -
npm ls jest
ornpm ls react-scripts
(if you haven’t ejected): jest@23.4.2 -
Operating system: Windows 10
Prerequisite
- are you able to run jest test from command line? yes
- how do yo run your tests from command line? (for example:
npm run test
ornode_modules/.bin/jest
)npm run test
Steps to Reproduce
Repo: https://github.com/trixnz/vscode-jest-ts-repro
Simply open the checked out repro in vscode, wait for the initial tests to run in the background and observe the following error in the developer console:
ERR Unexpected token (2:11): SyntaxError: Unexpected token (2:11)
at Parser.pp$5.raise (C:\Users\Cam\.vscode-insiders\extensions\orta.vscode-jest-2.9.0\node_modules\babylon\lib\index.js:4454:13)
at Parser.pp.unexpected (C:\Users\Cam\.vscode-insiders\extensions\orta.vscode-jest-2.9.0\node_modules\babylon\lib\index.js:1761:8)
at Parser.pp$1.parseClassBody (C:\Users\Cam\.vscode-insiders\extensions\orta.vscode-jest-2.9.0\node_modules\babylon\lib\index.js:2554:14)
at Parser.pp$1.parseClass (C:\Users\Cam\.vscode-insiders\extensions\orta.vscode-jest-2.9.0\node_modules\babylon\lib\index.js:2406:8)
at Parser.pp$1.parseStatement (C:\Users\Cam\.vscode-insiders\extensions\orta.vscode-jest-2.9.0\node_modules\babylon\lib\index.js:1843:19)
at Parser.parseStatement (C:\Users\Cam\.vscode-insiders\extensions\orta.vscode-jest-2.9.0\node_modules\babylon\lib\index.js:5910:22)
at Parser.pp$1.parseBlockBody (C:\Users\Cam\.vscode-insiders\extensions\orta.vscode-jest-2.9.0\node_modules\babylon\lib\index.js:2268:21)
at Parser.pp$1.parseTopLevel (C:\Users\Cam\.vscode-insiders\extensions\orta.vscode-jest-2.9.0\node_modules\babylon\lib\index.js:1778:8)
at Parser.parse (C:\Users\Cam\.vscode-insiders\extensions\orta.vscode-jest-2.9.0\node_modules\babylon\lib\index.js:1673:17)
at parse (C:\Users\Cam\.vscode-insiders\extensions\orta.vscode-jest-2.9.0\node_modules\babylon\lib\index.js:7305:37)
at Snapshot.exports.getASTfor.file [as _parser] (C:\Users\Cam\.vscode-insiders\extensions\orta.vscode-jest-2.9.0\node_modules\jest-editor-support\build\parsers\babylon_parser.js:29:50)
at Snapshot.getMetadata (C:\Users\Cam\.vscode-insiders\extensions\orta.vscode-jest-2.9.0\node_modules\jest-editor-support\build\Snapshot.js:108:27)
at SnapshotCodeLensProvider.provideCodeLenses (C:\Users\Cam\.vscode-insiders\extensions\orta.vscode-jest-2.9.0\out\src\SnapshotCodeLens\SnapshotCodeLensProvider.js:23:26)
This exception propagates and will break other features of the extension, most obvious to me was the code coverage overlay. Setting jest.enableSnapshotPreviews
to false will fix it in the interim.
Of Note: JavaScript compatible TypeScript will work fine. The repro includes some TypeScript specific syntax to trigger the issue.
Expected Behavior
The snapshot code lens provider should pass a custom parser into the jest-editor-support.Snapshot
constructor to allow Typescript to be parsed.
Actual Behavior
The default parser in jest-editor-support.Snapshot
(babylon) is used instead, and throws SyntaxErrors on TypeScript code.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:7
- Comments:6
Top GitHub Comments
@dinofx @trixnz I tried the test repo above with the v4.0.0-alpha.1 today and all appears to be working, no error in the developer console… Can you guys give it a try and let us know the result?
jest-community/jest-editor-support#51 is related. This package is written in TypeScript. Is it not annoying that you can’t even self host your own unit tests?