Skip to content
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

Using typescript typecasting with <> prevents to show test info in the editor #706

Closed
jseto opened this issue May 19, 2021 · 5 comments
Closed

Comments

@jseto
Copy link

jseto commented May 19, 2021

Using typescript typecasting with <> prevents to show test info in the editor (no gutter checkmarks, no errors next to the expect functions, etc.)

Environment

  1. vscode-jest version: 4.0.1

  2. node -v: 14.16.1

  3. npm -v : 7.9.0

  4. npm ls jest :
    ├── [email protected]
    └─┬ [email protected]
    └── [email protected] deduped

  5. your vscode-jest settings if customized:

    • jest.jestCommandLine? n/a
    • jest.autoRun? n/a
    • anything else that you think might be relevant? n/a
  6. Operating system: Ubuntu 20.04

Prerequisite

  • are you able to run jest test from the command line? yes, works as expected
  • how do you run your tests from the command line? (for example: npm run test or node_modules/.bin/jest) jest

Steps to Reproduce

Using typescript typecasting with <>, ie in a test file

const a = <number>'23'

using the as typecast behaves normal

const a = '23' as number

Check this repo for minimal code bug reproduction

https://github.com/jseto/vscode-jest-bug

Relevant Debug Info

Output from vscode jest output tab

PASS src/index.spec.ts
  ✓ should select concrete instance (1 ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        1.007 s, estimated 2 s
Ran all test suites.

/home/jseto/programing-projects/web/jest-bug/src/index.spec.ts: failed to parse test results: SyntaxError: Unterminated JSX contents (10:8)

Output from jest in terminal

 PASS  src/index.spec.ts
  ✓ should select concrete instance (1 ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        0.899 s, estimated 1 s
Ran all test suites.
@connectdotz
Copy link
Collaborator

looks like the babel-parser might be parsing this as JSX syntax instead of a TS typecasting. If you are indeed in a react/react-native project, probably won't be able to use "<>" as typecasting, otherwise you should be able to. We should probably distinguish the jsx/tsx files in jest-editor-support parser to only enable the "jsx" plugin for those...

@jseto
Copy link
Author

jseto commented May 20, 2021

I think it is not related to babel nor jsx as they are not used in my project. Actually it is vanilla typescript. You can have a look at the package.json in the git link in my previous comment.
I agree that in react or jsx projects you should avoid prefixed typecast in favour of sufixed typecast but this should not prevent vscode-jest to accept valid typescript syntax.
As a workaround solution the sufixed typecast as can be used.
Another reason for thinking it is not related to babel or jsx is that running jest in the command line works without any problem.

Hope this helps

@connectdotz
Copy link
Collaborator

connectdotz commented May 21, 2021

@jseto sorry I might have confused you.

The babel-parser was used by the vscode-jest dependency jest-editor-support to parse the source file in order to put the decorators and test status markers. (You can see some warning messages in the Developer Console if you turn on the jest.debugMode=true) It is not related to your project or jest itself.

It's a bug in jest-editor-support that we should fix. Thanks for raising that to our attention 👍 Fortunately, the workaround is pretty easy as you already discovered.

@connectdotz
Copy link
Collaborator

@connectdotz
Copy link
Collaborator

close via jest-community/jest-editor-support#72 and #724

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants