Create-react-app: add support to setuptests.js when running tests in webstorme

Created on 22 Apr 2017  Â·  8Comments  Â·  Source: facebook/create-react-app

So WebStorm 2017.1.2 is out, so I added a configuration to run my tests.
image

Its seems to work (Thanks WebStorm devs !!) but there is still some problems:

This works:
image

But when I Moved global.a to setupTests.js it fails (console.log doesn't print on console as well)
image

It seems that setupTests isn't been run before each test, because all my test depends on setupTests.js, I can run any test.
notice that in terminal the same test is passes
also adding import '../../setupTests' in the test file will make it work in WebStorm also.
so the issue is that in WebStorm, setupTests.js does not run before each test.

Most helpful comment

@shai32 Please while running from webstorm add this to --env=jsdom to JEST options.

Let us know how it goes?

All 8 comments

@shai32 can you include "setupTestFrameworkScriptFile": "<rootDir>/src/setupTests.js", in your jest(in package.json). That should run setupTests before jest!

Something on these lines

// package.json
"jest": {
    "collectCoverageFrom": [
      "src/**/*.{js,jsx}"
    ],
    "setupFiles": [
      "<rootDir>/config/polyfills.js"
    ],
    "setupTestFrameworkScriptFile": "<rootDir>/src/setupTests.js",
    "testPathIgnorePatterns": [
      "<rootDir>[/\\\\](build|docs|node_modules|scripts)[/\\\\]"
    ],
}

Let me know if it helps!

Yea, this will not be very smooth because WebStorm isn't aware of the configuration we're passing to Jest. So indeed your best option would be to (unfortunately) duplicate it in package.json as described by @anilreddykatta.

it works, thanks (should be added to docs)
but there is another problem.
this is the test:
image

this is the error
image

when running from terminal the test passes

@shai32 Please while running from webstorm add this to --env=jsdom to JEST options.

Let us know how it goes?

@anilreddykatta works!!!! :)

@shai32 Can you close if the issue is resolved?

Close - works when defining setupTestFrameworkScriptFile in package.json and add --env=jsdom to JEST options

This solution doesn't seem to work anymore without ejection:

These options in your package.json Jest configuration are not currently supported by Create React App:

  • setupFiles
Was this page helpful?
0 / 5 - 0 ratings

Related issues

oltsa picture oltsa  Â·  3Comments

alleroux picture alleroux  Â·  3Comments

rdamian3 picture rdamian3  Â·  3Comments

xgqfrms-GitHub picture xgqfrms-GitHub  Â·  3Comments

wereHamster picture wereHamster  Â·  3Comments