question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SnapshotCodeLensProvider crashes when working with TypeScript files

See original GitHub issue

Environment

  1. node -v: v9.4.0

  2. npm -v: 6.2.0

  3. npm ls jest or npm ls react-scripts (if you haven’t ejected): jest@23.4.2

  4. 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 or node_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:open
  • Created 5 years ago
  • Reactions:7
  • Comments:6

github_iconTop GitHub Comments

1reaction
connectdotzcommented, Oct 24, 2020

@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?

0reactions
dinofxcommented, Oct 23, 2020

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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeScript editor crashes on opening any .ts file
When I'm trying to open any .ts file, VS2017 will show an error telling me that an extension caused the issue and I...
Read more >
Install and use behind a firewall or proxy server - Visual Studio ...
Service or scenario DNS endpoint Protocol/Port URL resolution go.microsoft.com aka.ms Start Page vsstartpage.blob.core.windows.net 443 AI Project Integration az861674.vo.msecnd.net 443
Read more >
VSCode 所有的默认配置项 - CSDN博客
vscode.typescript-language-features: Provides rich language support for ... Special handling for large files to disable certain memory ...
Read more >
@volar/typescript-faster | Yarn - Package Manager
@volar/typescript-faster. TypeScript Language Service Completion API is slow when calculate auto-import. This package make it faster by ported tsserver ...
Read more >
Speed up ReSharper (and Visual Studio) - JetBrains
We believe that Visual Studio developers are working towards the same things ... state of opened documents may be useful in case of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found