Vscode-jest: Does not load setup file defined in package.json

Created on 17 Oct 2017  路  6Comments  路  Source: jest-community/vscode-jest

Environment

  1. node -v: v8.6.0
  2. npm -v: yarn 1.1.0
  3. npm ls react-scripts (if you haven鈥檛 ejected): not a cra project

  4. Operating system: OS X

Steps to Reproduce

Define a setup script in package.json, as explained in the jest docs

{
    "jest": {
        "setupTestFrameworkScriptFile": "./test-setup.js"
    },
    ...
}

Expected Behavior

Jest should run the setup file. I use it to initialize enzyme with a React adapter.

Actual Behavior

Jest does load the setup file when called via ./node_modules/.bin/jest, but not in VSCode.

This causes the following error from enzyme in VSCode Jest output:

          Enzyme Internal Error: Enzyme expects an adapter to be configured, but found none. To
          configure an adapter, you should call `Enzyme.configure({ adapter: new Adapter() })`
          before using any of Enzyme's top level APIs, where `Adapter` is the adapter
          corresponding to the library currently being tested. For example:

          import Adapter from 'enzyme-adapter-react-15';

          To find out more about this, see http://airbnb.io/enzyme/docs/installation/index.html
enhancement help wanted

Most helpful comment

Created a sample repo in https://github.com/fzaninotto/vscode-jest-error, but it seems to work now... Maybe I needed to relaunch the editor.

Thanks for looking into this anyway.

All 6 comments

Environment

  • node -v: v8.7.0


    • npm -v: yarn 0.27.5



    • npm ls react-scripts (if you haven鈥檛 ejected): not a cra project



    • Operating system: OS X

Steps to Reproduce

Define a setup script in package.json, as explained in the jest docs

{
    "test": "jest --config=jest.config.json --watch"
    },
    ...
}

Expected Behaviour

Jest should run the setup file. I use it to initialize enzyme with a React adapter.

Actual Behaviour
Same as fzaninotto

Can you create a sample repo so we can clone and try to reproduce?

Created a sample repo in https://github.com/fzaninotto/vscode-jest-error, but it seems to work now... Maybe I needed to relaunch the editor.

Thanks for looking into this anyway.

You need relaunch the editor. Thanks @fzaninotto 馃槃

Seems like we an opportunity for a PR to refresh the extension if package.json or the VS Code settings change.

I'm going to close this in favor of #231 that aggregates the issues. We'd love you help fixing the problem!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

radfahrer picture radfahrer  路  3Comments

jpokrzyk picture jpokrzyk  路  5Comments

ryanlittle picture ryanlittle  路  3Comments

offero picture offero  路  4Comments

elderfo picture elderfo  路  4Comments