Describe the bug
When using --json and --watch together a infinite jest test loop occurs
To Reproduce
Steps to reproduce the behavior:
"test:output:watch": "jest --json --outputFile=jest-lock.json --watch"nom test:output:watchExpected behavior
There shouldn't be a infinite loop, or how can I avoid it?
System:
What can I do to avoid it or how can I help in order to resolve this? Is this the right place to report it?
Sorry, I don't get how the infinite loop is related to Storybook?
Maybe we should redirect this to Jest?
@igor-dv @Keraito Sorry I wasn't more specific at first. The documentation here (inside Storybook) explains that:
We can run the following:
npm run test:generate-output -- --watch
While having
"scripts": {
"test:generate-output": "jest --json --outputFile=jest-test-results.json"
}
Which I believe is basically the same as:
npm run jest --json --outputFile=jest-test-results.json --watch
This results for me in an infinite loop as expressed above. Perhaps I'm doing something wrong here or the docs are outdated. Do you happen to know any info about this?
Any help is appreciated. Cheers.
Didn't try to reproduce it yet, but here is what I think out loud:
jest-test-results.json file on any test (or the dependencies of the test) changesAre you using Storyshots / or importing stories in the test in some other way?
This might help. Found the time to make a minimal, complete, and verifiable example:
https://github.com/fillipvt/jest-watch-json-infinite-loop
Just follow the readme instructions and let me know what you think.
A: I'm not using Storyshots
Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks!
As @igor-dv correctly reasoned, the output JSON file being (re)created on test completion is causing the watcher to rerun the tests. A simple workaround is to tell Jest to ignore the output, e.g by specifying the modulePathIgnorePatterns in your Jest config:
// my output json file is named jest-test-results.json, so:
modulePathIgnorePatterns: ['node_modules', 'jest-test-results.json'],
Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks!
With the workaround the loop doesn't happen. Thank you all
Most helpful comment
As @igor-dv correctly reasoned, the output JSON file being (re)created on test completion is causing the watcher to rerun the tests. A simple workaround is to tell Jest to ignore the output, e.g by specifying the
modulePathIgnorePatternsin your Jest config: