Vscode-jest: can't pass arguments like: --env=jsdom

Created on 19 Feb 2018  ·  3Comments  ·  Source: jest-community/vscode-jest

Environment

  1. node -v: 8.9.1
  2. npm -v: 5.5.1
  3. npm ls react-scripts (if you haven’t ejected): Custom project

  4. Operating system: Zorinos (ubuntu based)

Steps to Reproduce

Make a test with DOM as requirement. for example

import createHistory from 'history/createBrowserHistory';
const history = createHistory();

Expected Behavior

Should be posibility add custom arguments to this runner.
I have custom already added in my package.json scripts like

"scripts": {
    "test": "cross-env NODE_ENV=test jest --env=jsdom --watch",
    "test:ci": "cross-env NODE_ENV=test jest --env=jsdom --no-cache --maxWorkers=2 --ci"
}

Actual Behavior

Getting error in OUTPUT:

FAIL src/components/tests/App.test.js

  ● Test suite failed to run

    Invariant Violation: Browser history needs a DOM

      43 | });
      44 | 
    > 45 | const history = createHistory();
      46 | 
      47 | const reducers = {
      48 |   productReducer,

      at invariant (node_modules/invariant/invariant.js:42:15)
      at createBrowserHistory (node_modules/history/createBrowserHistory.js:49:27)
      at Object.<anonymous> (src/components/App.js:45:52)
      at Object.<anonymous> (src/components/tests/App.test.js:9:12)

In VSCode I tried those settings

  1. "jest.pathToJest": "npx jest --env=jsdom"
  2. "jest.pathToJest": "yarn test"
  3. "jest.pathToJest": "yarn test --env=jsdom"
  4. "jest.pathToJest": "npm test -- --env=jsdom"
  5. "jest.pathToJest": "yarn test:ci"

1. "jest.pathToJest": "node_modules/.bin/jest --env=jsdom"

If I run in terminal any of thous commands all tests are passing

bug

Most helpful comment

Glad you got it sorted. There's an open issue to re-initialize things when the settings change that'll help. Sorry for forgetting about #231.

All 3 comments

Based on how much troubleshooting you've done so far it seems like you're pretty motivated to figure this one out. I'd suggest you try to debug the extension to see why it's not using jest.pathToJest. If you set up the repo following the these instructions from the README (skip the part about jest-editor-support), then you can start Debugging using the "Launch Extension" configuration. A breakpoint in pathToJest may help determine what's happening.

Thanks, after restart it's worked. :congratulations:

Glad you got it sorted. There's an open issue to re-initialize things when the settings change that'll help. Sorry for forgetting about #231.

Was this page helpful?
0 / 5 - 0 ratings