Vscode-jest: Vscode extension fails (Unexpected token)

Created on 2 Mar 2017  ·  14Comments  ·  Source: jest-community/vscode-jest

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

bug needs information

Most helpful comment

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!

All 14 comments

Same here. Did you find a solution?

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.

That's bizarre. Still broken for me.

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

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

This problem is because this PR in jest has not been released yet. https://github.com/facebook/jest/pull/3076

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)

`

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

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

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: https://github.com/creationix/nvm/issues/890

@5achinJani +1, bumping this issue.

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

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 %*

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!

My node version was the same in both places (_system_ & _repo_).

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kartheektrilochan picture kartheektrilochan  ·  28Comments

Pajn picture Pajn  ·  31Comments

dandv picture dandv  ·  17Comments

fwielstra picture fwielstra  ·  29Comments

karb0f0s picture karb0f0s  ·  37Comments