1

I have a suite of Jest tests that work ok running jest locally - but when it runs just jest in Jenkins it freezes on one of the tests and just hangs. The whole test suite normally takes about 15 seconds locally.

It does work on Jenkins when I run jest --runInBand so that the tests are running sequentially.

What's the best way to debug this and/or what might be happening?

We just converted to typescript and ts-jest recently so I think that may be the culprit but still would like to understand the issue.

// jest.config.js

/* @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
  roots: ["./src"],
  preset: "ts-jest",
  testEnvironment: "node",
  transform: {
      "^.+\\.(ts|tsx)?$": "ts-jest",
  },
  testMatch: ["**/?(*.)+(spec|test).+(ts|tsx|js)"],
 

}

Ryan
  • 449
  • 5
  • 21

2 Answers2

0

In general, jest is going to hold itself open until all handles are released. This causes Jenkins to appear to hang because jest hasn't released control of the terminal yet (and tends to behave differently when running locally due to the backgroun worker nodes that jest uses to run tests). Generally running --forceExit --detectOpenHandles will both force the terminal to release (and thus prevent jenkins hanging) and detect if there are still open handles that you need to fix in your tests.

Check out jest hangs indefinitely, runs no tests for more info.

Patrick
  • 2,885
  • 1
  • 14
  • 20
0

Jest will adapt to your maximum resources. Doesn’t matter how many resources you have. Jest will drain them all. You can limit the CPU use by using --maxWorkers option.

--maxWorkers=<num>|<string>

lissettdm
  • 12,267
  • 1
  • 18
  • 39