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?
CodePudding user response:
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.