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.

Test suite failed to run in VSCode 1.22.2

See original GitHub issue

Environment

  1. node -v: 9.11.1
  2. npm -v: 5.6.0
  3. npm ls react-scripts (if you haven’t ejected): no
  4. Operating system: Microsoft Windows [Version 10.0.14393]
  5. VSCode: version 1.22.2

Steps to Reproduce

I was able to reproduce error with this repo https://github.com/karb0f0s/vscode-jest-test/ on Windows. Although this error doesn’t appear on MacOS. I guess it is somehow related to the way VSCode spawns jest process.

package.json

{
  "name": "app",
  "private": true,
  "scripts": {
    "test": "jest",
    "test:watch": "jest --watch",
    "build": "webpack",
    "watch": "webpack --watch"
  },
  "devDependencies": {
    "@babel/cli": "^7.0.0-beta.46",
    "@babel/core": "^7.0.0-beta.46",
    "@babel/preset-env": "^7.0.0-beta.46",
    "babel-core": "^7.0.0-bridge.0",
    "babel-jest": "^22.4.3",
    "babel-loader": "^8.0.0-beta.2",
    "jest": "^22.4.3",
    "webpack": "^4.6.0",
    "webpack-cli": "^2.0.15"
  },
  "jest": {
    "verbose": true,
    "bail": true,
    "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(js|ts)$",
    "transform": {
      "^.+\\.js?$": "babel-jest"
    }
  }
}

.babelrc

{
  "presets": [
    ["@babel/preset-env", {
      "targets": {
        "browsers": ["last 2 versions", "ie >= 10"]
      },
      "modules": false,
      "useBuiltIns": "usage",
      "debug": true
    }]
  ],
  "env": {
    "test": {
      "presets": ["@babel/preset-env"]
    }
  }
}

Expected Behavior

npm test works as expected, Debug under the test in source file works as expected, Debug configuration vscode-jest-tests works as expected, with transpilation and all

Actual Behavior

VSCode Jest plugin fails to run. Output contains:

FAIL test\countPrice.test.js

  ● Test suite failed to run

    .\app\test\countPrice.test.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import { getBladeCount, calculateCpuPrice, calculateRamPrice } from "../src/countPrice";
                                                                                             ^^^^^^
    
    SyntaxError: Unexpected token import
      
      at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:316:17)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        0.23s
Ran all test suites related to changed files.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:8
  • Comments:40 (9 by maintainers)

github_iconTop GitHub Comments

51reactions
seanpoultercommented, May 17, 2018

Based on the changes from #324 it looks like you can work around this issue by adding a "jest.pathToJest": "npm test --" setting in .vscode/settings.json. The PR closed a few issues that I haven’t had time to digest so I’m not keen to revert the breaking change just yet. If anyone’s got the bandwidth, I’d love some help with a fix or help building a list of what requirements were requested in those closed issues to guide some much-needed unit and integration tests.

20reactions
jorgegonzalezcommented, May 16, 2018

@seanpoulter to reproduce:

  • Create a new app: create-react-app my_app
  • Run npm test in a terminal and the tests will pass
  • Navigate to the src/App.test.js file and VSCode will show the following error:
 FAIL  src/App.test.js

  ● Test suite failed to run

    /Users/jorge/Code/tester/src/App.test.js: Unexpected token (7:18)
         5 | it('renders without crashing', () => {
         6 |   const div = document.createElement('div');
      >  7 |   ReactDOM.render(<App />, div);
           |                   ^
         8 |   ReactDOM.unmountComponentAtNode(div);
         9 | });
        10 | 


Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        0.973s
Ran all test suites.
Read more comments on GitHub >

github_iconTop Results From Across the Web

Test suite failed to run in VSCode 1.22.2 - - Bountysource
VSCode Jest plugin fails to run. Output contains: FAIL test\countPrice.test.js ○ Test suite failed to run .\app\test\countPrice.test.js:1 ({"Object.
Read more >
March 2018 (version 1.22) - Visual Studio Code
Update 1.22.2: The update addresses these issues. ... Auto attach to process - Automatically attach the debugger to running Node.js processes.
Read more >
Testing Extensions - Visual Studio Code
Visual Studio Code supports running and debugging tests for your extension. These tests will run inside a special instance of VS Code named...
Read more >
November 2022 (version 1.74) - Visual Studio Code
There are now audio cues for when notebook cells finish running. The cue is different to indicate whether the cell ran successfully or...
Read more >
Command Line Interface (CLI) - Visual Studio Code
If you are looking for how to run command-line tools inside VS Code, ... If this isn't the case, you can manually add...
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