skip to Main Content

My Jest tests are passing, but Github actions workflow isn’t completing.

Here’s my main.yaml.

name: Jest Unit Tests
on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [14.x, 16.x]
        mongodb-version: ['4.2', '4.4', '5.0']
    steps:
      - uses: actions/checkout@v3
      - name: Setup Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v3
        with:
          node-version: ${{ matrix.node-version }}
      - name: Start MongoDB
        uses: supercharge/[email protected]
        with:
          mongodb-version: ${{ matrix.mongodb-version }}
      - run: npm ci
      - run: npm run workflow
    env: 
      CI: true

enter image description here

Do I need to fix my yaml file?

3

Answers


  1. Chosen as BEST ANSWER

    So turns out Github issues has issues with async processes. Even though the tests passed, there were still async operations occurring from Jest, so Github actions defaults to not completing.

    Fix this by adding --forceExit to force the test to end and --detectOpenHandles to see what async operations are still happening.

    Added these to my package.json scripts.

    "scripts": {
        "local-test": "jest --watchAll",
        "workflow": "jest --forceExit --detectOpenHandles",
        "start": "node server.js",
        "dev": "nodemon server.js"
      },
    

    For those new to Github actions, the yaml file in my original post calls npm run workflow at the end, which is the script in my package.json.

    See https://jestjs.io/docs/cli for more info on the Jest options.


  2. Please also ensure your jest has no warnings during pipeline running:

    eg: Jest: "global" coverage threshold for branches (10%) not met: 8.33%

    Such as ensure the threshold value is always passed:

    you can setup something like below in jest.config.js file:

    coverageThreshold: {
        global: {
          branches: 1,
          functions: 1,
          lines: 1,
          statements: 1,
        },
      },
    
    Login or Signup to reply.
  3. Remove "–watchAll" from the command, and add other for GitHub Workflow

    "scripts": {
       "test": "jest --watchAll",
       "ghworkflowtest": "jest"
    }
    

    Run "npm test" for local tests and in .yml file call "npm run ghworkflowtest" for GitHub actions

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search