-
Notifications
You must be signed in to change notification settings - Fork 294
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
SnapshotCodeLensProvider crashes when working with TypeScript files #355
Comments
Would turning on the typescript plugin be a problem? class SnapshotCodeLensProvider implements vscode.CodeLensProvider {
public provideCodeLenses(document: vscode.TextDocument, _token: vscode.CancellationToken) {
function parseTS(file: string) {
return parse(readFileSync(file, 'utf8'), { sourceType: 'module', plugins: ['typescript'] });
}
const snapshots = new Snapshot(parseTS); I tried this out and it supported most TS syntax. Newer syntax like |
@connectdotz Does the above make sense? I could open a PR or investigate some other approach. |
hey @dinofx and @trixnz sorry somehow I didn't see this issue until now, yes this is not good and probably is related our recent switch to babel typescript parser... @dinofx it will be great for a PR 👍 [update]
let's dig a bit further to see if we can understand this problem better...? |
I think the flow and typescript plugin are mutually exclusive. I’m not sure if Babel parser includes the flow plugin by default, but we could look at the file’s path and use the extension to decide when to add the typescript plugin. Of course, the same could also be done in jest-editor-support, but ideally you’d use typescript rather than Babel to parse typescript. I noticed that the ‘asserts’ syntax from TS 3.7 still caused problems. |
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? |
@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? |
Environment
node -v
: v9.4.0npm -v
: 6.2.0npm ls jest
ornpm ls react-scripts
(if you haven’t ejected): [email protected]Operating system: Windows 10
Prerequisite
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:
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.The text was updated successfully, but these errors were encountered: