Jest: --watch loops infinitely with custom testResultsProcessor

Created on 9 Oct 2017  Â·  12Comments  Â·  Source: facebook/jest


Do you want to request a feature or report a bug?

Bug

What is the current behavior?

When running Jest in watch mode with a custom testResultsProcessor, it loops infinitely instead of running watch properly. Instead of waiting for files to change, the screen keeps refreshing and needs several Ctrl-C keypresses to quit.

If the current behavior is a bug, please provide the steps to reproduce and either a repl.it demo through https://repl.it/languages/jest or a minimal repository on GitHub that we can yarn install and yarn test.

  1. Create a new directory and initialise package.json: npm init -y
  2. Install jest: npm i -D jest (tested with Jest 21.2.1)
  3. Install jest bamboo formatter: npm i -D jest-bamboo-formatter (tested with 1.0.1)
  4. Add the following config to package.json:

      "jest": {
         "testResultsProcessor": "./node_modules/jest-bamboo-formatter"
      }
    
  5. Create a sample test containing a simple expection

  6. Run jest in watch mode: npx jest --watchAll

What is the expected behavior?

watch mode should start normally and wait for files to change.

Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.

  • Jest: 21.2.1
  • node: 8.6.0
  • npm: 5.3.0
  • OS: MacOS 10.12.6
Confirmed

Most helpful comment

@spinningarrow @acostaf @brysbra A workaround is to ignore the generated file:

diff --git i/package.json w/package.json
index 30ffd55..714a773 100644
--- i/package.json
+++ w/package.json
@@ -8,6 +8,9 @@
     "jest-bamboo-formatter": "^1.0.1"
   },
   "jest": {
-    "testResultsProcessor": "./node_modules/jest-bamboo-formatter"
+    "testResultsProcessor": "./node_modules/jest-bamboo-formatter",
+    "watchPathIgnorePatterns": [
+      "<rootDir>/jest.json"
+    ]
   }
 }

All 12 comments

I can confirm that this it is happening on version 20 with jest-bamboo-formatter

Same here (v20.0.0) and "testResultsProcessor": "./node_modules/jest-bamboo-formatter",.
Tried updating jest to latest version (v21.2.1) but it was the same.
If I remove testResultsProcessor from the jest config, then jest --watch works as expected.

Since the reporter writes a file to disk, jest sees the new file, triggering a rerun, triggering a changed file, triggering a rerun etc.

https://github.com/adalbertoteixeira/jest-bamboo-formatter/blob/c7ece99102862834698fb90de08bbdb35afbf0f3/index.js#L51
Handle called in jest: https://github.com/facebook/jest/blob/1aef0f6d27d11fc2ae9307aea56d73558be46708/packages/jest-cli/src/watch.js#L65
eventsQueue here includes the file written to disk by the processor. Ignoring the file with git makes no difference.

Should the processor just _not_ write to disk in watch mode?

I'm not familiar with this part of the code base. @rogeliog ideas?

Reproduction repo: https://github.com/SimenB/jest-preprocessor-rerun

IMO, the formatter should use be a reporter, as it's not really a processor.

https://facebook.github.io/jest/docs/en/configuration.html#reporters-array-modulename-modulename-options. Not sure if it would help in this case, though

@spinningarrow @acostaf @brysbra A workaround is to ignore the generated file:

diff --git i/package.json w/package.json
index 30ffd55..714a773 100644
--- i/package.json
+++ w/package.json
@@ -8,6 +8,9 @@
     "jest-bamboo-formatter": "^1.0.1"
   },
   "jest": {
-    "testResultsProcessor": "./node_modules/jest-bamboo-formatter"
+    "testResultsProcessor": "./node_modules/jest-bamboo-formatter",
+    "watchPathIgnorePatterns": [
+      "<rootDir>/jest.json"
+    ]
   }
 }

Closing as watchPathIgnorePatterns seems to be the right fix.

@cpojer Is there a way for testResultsProcessors to indicate which files to ignore? Otherwise this kind of thing becomes quite hard to track.

I still think using testResultsProcessors for writing to disk is wrong, it should be a reporter.

I don't think it'll help right now, but we might me able to extend a reporter to be able to signal any files it wants to be ignored by the watcher

A reporter receives the config as well, so it can choose not to write to disk in watch mode. That feels like the correct solution

I don’t think I know enough about this to understand; are you saying that
the config should be fixed, or that the fix should be made in the jest
bamboo plugin, or somewhere else?

On Fri, 20 Oct 2017 at 11:36 AM, Simen Bekkhus notifications@github.com
wrote:

I still think using testResultsProcessors for writing to disk is wrong,
it should be a reporter.

I don't think it'll help right now, but we might me able to extend a
reporter to be able to signal any files it wants to be ignored by the
watcher

—
You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub
https://github.com/facebook/jest/issues/4635#issuecomment-338171021, or mute
the thread
https://github.com/notifications/unsubscribe-auth/ABts0IHsOOAqz-uGb6mmQJPJrAZP8VMJks5suHfDgaJpZM4PyGpV
.

>

—Sahil

The fix should be in jest-bamboo-formatter

The fix will be two-fold:

  1. Turn jest-bamboo-formatter into a reporter
  2. Have jest-bamboo-formatter take an option to disable output in watch mode

    1. Or have it just not write during watch anyways

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jardakotesovec picture jardakotesovec  Â·  3Comments

ticky picture ticky  Â·  3Comments

paularmstrong picture paularmstrong  Â·  3Comments

StephanBijzitter picture StephanBijzitter  Â·  3Comments

mmcgahan picture mmcgahan  Â·  3Comments