Run each test case in a separate process / better isolated context?
See original GitHub issueDo you want to request a feature or report a bug?
Request a feature.
What is the current behavior?
Currently, tests in a single test source file are run one after the other in the same process / context.
One can use resetModules
and resetMocks
(disabled by default!?) to reduce the chances of one test to affect another test.
One of the problems with resetModules
and resetMocks
is that this doesn’t jive very well with having ES6’ top-level import
declarations in your test source file. They create references to the initial module / mock instances that resetModules
and resetMocks
won’t be able to “reset” to new instances. Someone had already filed a ticket for that in the past: https://github.com/facebook/jest/issues/3236
Instead of trying to reset the state after each test case (which is hard!), I think it’s better to run each test case in “true isolation” in a separate node.js process (or perhaps a lighter way of isolating, I’m not sure what it would be though).
Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.
Using:
- Jest v22.2.2
- Node v8.9.1
- Yarn v1.3.2
Issue Analytics
- State:
- Created 6 years ago
- Comments:15 (3 by maintainers)
Top GitHub Comments
jest
has a built in flat to run all tests sequentiallyalias
-i
I used that for running just test against storybook+puppeteer environment (e.g. npm lib spdt)
I actually needed this for some tests with puppeteer. I’m probably better off refactoring the setup or test logic, but meanwhile I got isolation with:
This runs each file as a separate jest command, so each of my test files spawn a new puppeteer context, solving my problem for now. Figured I would post this here in case it helps someone.