macasas
macasas

Reputation: 582

Running Jest tests loop forever

Today, for some unexplained reason my jest test files started looping, resulting in a flickering terminal.

I am running jest src --watch, src being my source folder.

I followed a number of other discussions but none of them have helped solve my issue.

https://github.com/facebook/jest/issues/4635 is talking about a custom processor, but I am using a default setup.

I have tried ignoring folders.

I have ended up removing all my test files, at which point the looping stops. If I add a test file to __tests__ it matches the file but does not run a test. If I add the test file to my /src folder, it starts looping again, and it doesn't matter if the actual test passes or fails. Even if I add a fake test with a simple

describe('Test Suite', () => {
  test('two plus two is four', () => {
    expect(2 + 2).toBe(4)
  })
})

it loops and flickers.

This is my jest setup

  "jest": {
    "verbose": false,
    "watchPathIgnorePatterns": [
      "<rootDir>/dist/",
      "<rootDir>/node_modules/"
    ],
    "globalSetup": "./jest-setup.js",
    "globalTeardown": "./jest-teardown.js",
    "testEnvironment": "./jest-mongo.js"
  },

Does anyone know what is causing this to loop? I am not changing any files in any folder to make the --watch think it needs to run again, there are no other apps i.e. dropbox syncing the folder.

I am developing in VSCode, but the same thing happens if I test in a terminal window.

This was running fine just 5 hours ago, what went wrong?

Upvotes: 1

Views: 4235

Answers (2)

orccrusher99
orccrusher99

Reputation: 314

I just figured out my own version of this issue, posting for anyone else who may come across this. I had to add a specific json file globalConfig.json to my watchPathIgnorePatterns.

"watchPathIgnorePatterns": [
   "<rootDir>/globalConfig.json",
],

No idea why this file vs the jest.json referenced here: https://github.com/jestjs/jest/issues/5038

EDIT: it's because I'm using jest-mongodb. See https://github.com/shelfio/jest-mongodb#6-jest-watch-mode-gotcha

Upvotes: 1

macasas
macasas

Reputation: 582

It turns out that the jest.setup file was writing a configuration file to disk, while setting up a temporary mongoDB. If at least one of the tests used the mongoDB the looping stopped, or if I removed the setup files the looping stopped.

So my problem started when out of 30 test files, the one that connected to mongo was edited (starting the looping/flickering). In trying to solve the problem I removed all the rest of the test files, which left me with the most basic tests, but still the looping because I was still not connecting.

Still not 100% sure of the exact mechanism, but when inheriting someone else's codebase which doesn't use the default jest setup, probably best to expand jest knowledge to understand what's going on.

Upvotes: 1

Related Questions