4

I'm trying to create a simple test script that when run enters watch mode and re-writes a file called jest-lock.json

"test:output:watch": "jest --json --outputFile=jest-lock.json --watch"

When this runs it simply enters an infinite loop and I'm not sure what I'm doing wrong.

I have a simple test and I'm trying to do this in order to use the storybook jest-addon.

Any thoughts? All is appreciated.

Thanks

skyboyer
  • 22,209
  • 7
  • 57
  • 64
fillipvt
  • 556
  • 3
  • 14
  • exclude `jest-lock.json` from what's being watched - https://stackoverflow.com/questions/40486567/how-to-exclude-files-from-jest-watch feels appropriate here. – Mike 'Pomax' Kamermans Nov 15 '18 at 01:44
  • Thanks for answering @Mike'Pomax'Kamermans , I just implemented `watchPathIgnorePatterns`, `testPathIgnorePatterns` and `modulePathIgnorePatterns` just to be sure, but sadly it's still in an infinite loop. Have you run `--json` and `--watch` simultaneously without this behaviour? – fillipvt Nov 15 '18 at 03:08
  • Can't say I've used jest before, just react with webpack and chokidar. – Mike 'Pomax' Kamermans Nov 15 '18 at 05:31
  • you need to turn off the hotkey "a" from being used. This is usually what causes the loop. Though it is inconsistent, removing the hotkey from being pressed will not ever cause the loop. – DeerSpotter Nov 28 '18 at 14:12

1 Answers1

1

it appears this wasnt really solved anywhere (A good challenge! if i could add my reputation with your bounty i would), this source does give good information on why watch loops.

this isnt my solution but i believe you can use this:

watch -n1 'wc -l my.log | tee -a statistics.log'

This will execute your wc each second, add its output to the statistics.log file, and also show it on the screen. So, you'll end up with a file filled with numbers, representing the successive number of lines of my.log.

now using this structure, (im not a json expert) we can restructure your line for what it should be. I may need some colleagues help with this. (a good start at least)

DeerSpotter
  • 417
  • 1
  • 6
  • 17
  • 1
    I have here a repo where you can reproduce the problem: https://github.com/fillipvt/jest-watch-json-infinite-loop And I've reported this in Jest too https://github.com/facebook/jest/issues/7389 no solution yet – fillipvt Nov 30 '18 at 06:50
  • Thank you for the REPO, i will test when i go home today. Can i ask why this is important for you? Or just Bug hunting? – DeerSpotter Nov 30 '18 at 14:54
  • This is important, at least for me, in order to focus on the development of small components using `StorybooksJS` and create unit tests along with them without the need to have a separate server running the test suite. It's all just in one command. It might be a slight none critical bug at first sight but it can save a few minutes that might compound later down the road making it a somewhat noticeable problem. – fillipvt Dec 01 '18 at 00:10