Runner hangs sometimes after all Jest tests are completed

I use GitLab cloud CI to run Jest tests on my node project and after deploy the app to AWS. It happened now quite frequently (1/3) that after all the tests completes during the first job the runner hangs and doesn’t move to the next job (deployment).

It hangs here:
Screenshot 2020-06-16 at 11.52.38
until the runner timeout kicks and makes it fail.

This happened once or twice a while ago but became all of a sudden quite frequent. Maybe around the time I started mocking dates on the server for testing in particular dates (I use both SinonFakeTimers and jest.spyOn(global.Date, ‘now’).mockImplementationOnce).

It is mostly an end-to-end test and besides the main image we use a postgis service. This is the job that hangs:

build:
  stage: build
  allow_failure: false
  services:
    - postgis/postgis:11-2.5
  script:
    - npm install --quiet
    - npm run build
    - find ./build/db/migrations -name '*.map' -delete
    - NODE_ENV=ci ./node_modules/.bin/sequelize db:migrate --migrations-path ./build/db/migrations
    - NODE_ENV=ci npm run test # which runs: jest --no-cache --detectOpenHandles
  artifacts:
    paths:
      - build

How could I debug such problem?

Thank you so much for any help!

Jest --forceExit remove the problem, perhaps not in a very elegant way. But the problem definitely lies on Jest and some operations lingering somewhere.

1 Like

did you ever resolve this or did anything improve? Having same issue

I am also still having this issue, but with Jasmine instead of Jest. Any idea as to what I can do to resolve this?

I am facing same issue Tried 29 - 24 version of jest along with --forceExit option with no resolve. It gets stuck till timeout by gitlab pipeline.