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

Vscode extension fails (Unexpected token) #84

Closed
pkearney13 opened this issue Mar 2, 2017 · 14 comments
Closed

Vscode extension fails (Unexpected token) #84

pkearney13 opened this issue Mar 2, 2017 · 14 comments

Comments

@pkearney13
Copy link

The Vscode extension fails to run the the tests, output

FAIL  src/App.test.js

  ● Test suite failed to run

    /Users/pkearney/Development/react-app/src/App.test.js: Unexpected token (6:10)
        4 | 
        5 | it('renders without crashing', () => {
      > 6 |   shallow(<App />);
          |           ^
        7 | });
        8 | 

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        0.058s
Ran all test suites.

The tests run normally on the command line with npm test

@ryan-mars
Copy link

Same here. Did you find a solution?

@pkearney13
Copy link
Author

I actually tried it on the same mac when I got home from work, it works now. I haven't tried it in work since.

@ryan-mars
Copy link

That's bizarre. Still broken for me.

@bookman25
Copy link
Collaborator

Just judging by the output it looks like jsx is emitted. And I'm guessing that maybe the babel config isn't getting picked up?

https://github.com/facebook/jest/blob/master/packages/jest-editor-support/src/parsers/BabylonParser.js#L51

@pkearney13
Copy link
Author

Probably not related in any way but I was behind a proxy on work. Only thing that is different

@danez
Copy link

danez commented Apr 21, 2017

This problem is because this PR in jest has not been released yet. jestjs/jest#3076

@5achinJani
Copy link

Same here. Works fine in the terminal though.
`
FAIL src/App.test.js

● Test suite failed to run

/var/www/html/sachin-github/file-content/file-content-viewer/src/App.js:83
  async getFileData() {/* istanbul ignore next */cov_1ze3mh3x5a.f[13]++;
        ^^^^^^^^^^^
SyntaxError: Unexpected identifier
  
  at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/ScriptTransformer.js:289:17)
  at Object.<anonymous> (src/App.test.js:3:12)

`

@seanpoulter
Copy link
Member

@5achinJani, do you have a repo we can use to troubleshoot this?

@5achinJani
Copy link

@seanpoulter I figured the problem is with the node version. My system node version is v7 and the local/repo specific node is set using nvm which is v8.9.1 . vscode-jest runs on the system node so that's why this issue was produced. Apologies from my side I should have checked the node version before.
Is there any way i could tell vscode-jest extension to run on node v8.9.1 cause that would fix the issue or any other recommend way to fix this type issue?

@seanpoulter
Copy link
Member

That would do it. You might be able to tell it to use a specific version using the pathToJest setting. This nvm issue might help: nvm-sh/nvm#890

@aleccool213
Copy link

@5achinJani +1, bumping this issue.

@seanpoulter pathToJest doesn't work as its node which is the problem and not jest itself.

@seanpoulter
Copy link
Member

You're given no details about your problem @aleccool213. If the following suggestions don't help, please create a new issue with all the instructions we need to reproduce your environment and a minimal example repo (e.g.: https://stackoverflow.com/help/mcve).

The symptoms from the original post have been happening lately because we're calling jest instead of npm test in an app that has been bootstrapped with create-react-app. If that's you problem, change pathToJest to npm test -- and call it a day.


There's also mention above about working with different versions of Node. and using nvm. We'll spawn whatever command you put in pathToJest so you may be able to work around an nvm issue with a shell script that runs your Node setup and passes the received args to Jest.

Try something like this Bash script on a POSIX system:

#!/bin/bash
nvm use v9.11.1 && jest $*

Or on Windows, something like this in a .bat file:

nvm use v9.11.1 && jest.cmd %*

@aleccool213
Copy link

Sorry, should have linked that I had the same problem as this comment.

If that's you problem, change pathToJest to npm test -- and call it a day.

This solution works! Thank you!

@dreamyguy
Copy link

dreamyguy commented Jun 7, 2018

My node version was the same in both places (system & repo).

Disabling and re-enabling the vscode-jest extension worked for me. 💖

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

8 participants