Storybook: While using jest-addon with --json and --watch together an infinite loop is triggered

Created on 15 Nov 2018  路  9Comments  路  Source: storybookjs/storybook

Describe the bug
When using --json and --watch together a infinite jest test loop occurs

To Reproduce
Steps to reproduce the behavior:

  1. Create a simple jest test
  2. Implement jest-addon
  3. Create a script like this: "test:output:watch": "jest --json --outputFile=jest-lock.json --watch"
  4. See infinite loop on console when running nom test:output:watch

Expected behavior
There shouldn't be a infinite loop, or how can I avoid it?

System:

  • OS: MacOS
  • Framework: react
  • Addons: jest
  • Version 4.0.0

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?

jest has workaround question / support

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 modulePathIgnorePatterns in your Jest config:

// my output json file is named jest-test-results.json, so:
modulePathIgnorePatterns: ['node_modules', 'jest-test-results.json'],

All 9 comments

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:

  1. Watching jest will recreate the jest-test-results.json file on any test (or the dependencies of the test) changes
  2. The file recreation will trigger HMR in Storybook (not sure it's relevant)
  3. Also, might be, the story is in the dependencies tree of the test (for example Storyshots)
  4. This (3) triggers again the test and we start again (1)

Are 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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wahengchang picture wahengchang  路  3Comments

shilman picture shilman  路  3Comments

shilman picture shilman  路  3Comments

purplecones picture purplecones  路  3Comments

arunoda picture arunoda  路  3Comments