If interested, please also check previous two articles on setting up the tests:
- https://jczhang.com/2022/08/08/startup-mvp-recipes-9-nest-js-typeorm-postgres-unit-testing-service-onlywith-jest-pg-mem/
- https://jczhang.com/2022/08/09/startup-mvp-recipes-10-nest-js-unit-testing-mocking-service-and-the-universal-mock/
References
- https://medium.com/swlh/jest-and-github-actions-eaf3eaf2427d
- https://github.com/marketplace/actions/run-jest
- https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request
- https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
Config
On PR open, we will trigger this github action workflow on the cloud and let it run the checks remotely.
name: Nest.js Jest CI
on:
push:
branches: [dev]
pull_request:
types: [opened, reopened, synchronize]
branches: [dev]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run prebuild
- run: NODE_ENV=development npm run lint
- run: NODE_ENV=development npm run build
- run: NODE_ENV=development npm run test