Nestjs has Jest built in so that UnitTest can be run.
This is automatically run at the time of the Pull Request to get feedback on whether the developer’s modifications are causing problems.
目次
Create Directory
Create a directory .github/workflows.
This will side with the GitHub Actions workflows.
ワークフローについて – GitHub Docs
トリガー、構文、高度な機能など、GitHub Actions のワークフローの概要について説明します。
Running UnitTest in YML
Workflows are defined in YML.
It is simple to define.
- Checking out the repository
- Setting up node
- Installing npm
- Building npm
- Test runs
name: UnitTest for PullRequest
on:
pull_request:
branches:
- '*'
jobs:
tests:
name: run unit test
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: repogitory checkout
uses: actions/checkout@v3
- name: setup node
uses: actions/setup-node@v3
with:
node-version: '20.x'
cache: npm
- name: npm install
run: npm install
- name: npm build
run: npm run build --if-present
- name: run test
run: npm run test
Commit this and Pull Request.
You will see UnitTest running at that timing.
Summay
As we got bigger, we often forgot to do UnitTest.
I would like to have it built in, as it would help me to do UnitTest and prevent quality assurance omissions if it was automatically executed at Pull Request time.