Jest tests hang

We have a project we’ve been trying to get a CI build running for with GitHub actions. It’s a Sapper project for which we’re using Jest for tests. We set a CI configuration to run our tests, which all run fine locally on both MacOS and Linux, but when the CI build attempts to run the tests, it just hangs.

Has anyone else noticed an issue with Jest tests hanging when running in a GitHub Action like this? This is what our build config looked like:

name: CI
on: [push]
jobs:
  build:
    name: Test
    runs-on: ubuntu-16.04
    steps:
      - uses: actions/checkout@v1
        with:
          node-version: '12.x'
      - run: echo "//npm.pkg.github.com/:_authToken=${{ secrets.NPM_AUTH_TOKEN }}" > ~/.npmrc
      - run: yarn install
      - run: yarn lint
      - run: yarn build
      - run: yarn test
        env:
          ISOLATE: true
2 Likes

From the configuration of the workfolw you shared, I remember that there is not an input parameter name  node-version  for the action actions/checkout@v1. If you wants to setup a specific version of node, you should use the action actions/setup-node.

If the problem still exists, please share your repository with us, so that we can check the full configurations of your workflow and the detailed debug logs of the workflow runs to analyze the root cause.

1 Like

It works for me when I add a CI: true environment variable to the step.

I think what’s happening is that Jest runs with –onlychanged by default (https://jestjs.io/docs/en/cli#–onlychanged) but that things should work as expected in the future once this PR is merged.

1 Like

Thank you @brightran and @benpickles for your replies and suggestions. I updated my config to try the changes that you both suggested, but I am still seeing the same results. The tests task hangs after running 4 of the 8 test suites in the project. Unfortunately @brightran this is a private repository that I am unable to share. If I am unable to get this figured out long-term, I may try to create a public repository in which I can reproduce the issue, for reference.

I was hopeful that  you guys had pointed me in a working direction and that I just had a couple of tweaks to make to get this working, but unless I’m still missing something, it’s still not working.

Here is my updated config:

name: CI
on: [push]
jobs:
  build:
    name: Test
    runs-on: ubuntu-16.04
    steps:
      - uses: actions/checkout@v2
      - name: Use Node.js
        uses: actions/setup-node@v1
        with:
          node-version: '12.x'
      - run: echo "//npm.pkg.github.com/:_authToken=${{ secrets.NPM_AUTH_TOKEN }}" > ~/.npmrc
      - run: yarn install
      - run: yarn lint
      - run: yarn build
      - run: yarn test
        env:
          CI: true
          EXCHANGE_OMS_ID: 1
          ISOLATE: true

Here is a screen capture of the output that I see on GitHub:

This is what I see when I run the tests locally on MacOS (we also get the same results running on Linux as well):

1 Like

@ryexley ,

Did you try the same commands for the tests on your local Linux machine (or VM)? Did they work as expected?

If they can work on your Linux machine, you can try to install a self-hosted runner on the machine to run your workflow.

I got the same problem too.

In my local, the test was run ok, but it was hanging when applying into Github action.

It works for me when I add cleanup function into the test file:

afterEach(() => {
   cleanup()
  });

Hope it works for you.

In my case, I fixed it by adding --forceExit flag

Hey! Did you solve your problem? My tests hangs after the first test is passed, just like you. Adding the --forceExit flag did not help

Thanks for your help

Hello all. just sharing some code that helped me debug jest hanging in github actions but some how weirdly not locally

const wtf = require('wtfnode');
const whyRunNodelog = require('why-is-node-running') // should be your first require

// ... rest of your require statements and such ....


afterAll(async () => {
  wtf.dump()
  whyRunNodelog()
  console.log('process._getActiveHandles()', process._getActiveHandles())
});


// rest of your code ...

These pretty every options for finding out whatever is hanging your tests.

I included it in each test individually until I figured out what was doing it

Turns out at least to start it was an open connection to aws secrets manager for me

Hat tip to a commeont on this answer on stackoverflow for the pointer

Also obviously you can do jest --forceExit but then your code could be leaking memory or some other unsavory issue because of open handles and such