【Nestjs】GitHub Actions to run UnitTest on Pull Request.

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.

Running UnitTest in YML

Workflows are defined in YML.

It is simple to define.

  1. Checking out the repository
  2. Setting up node
  3. Installing npm
  4. Building npm
  5. 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.

よかったらシェアしてね!
目次