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
Do I need to fix my yaml file?
3
Answers
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.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 mypackage.json
.See https://jestjs.io/docs/cli for more info on the Jest options.
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:Remove "–watchAll" from the command, and add other for GitHub Workflow
Run "npm test" for local tests and in .yml file call "npm run ghworkflowtest" for GitHub actions