Last week, I added unit and integration tests. However, I need to run the test whenever I push the commits to the repo. But, there is a good way to solve this, I did add CI workflow to GitHub Actions.
Step 1: Go to GitHub Actions
Step 2: New workflow
Step 3: Choose a workflow
Step 4: Create a .yml
file based on your prefrence.
I chose Node
and this is my .yml
file for Linting
and Unit Tests
.
name: Node.js CI
on:
push:
branches: ['main']
pull_request:
branches: ['main']
jobs:
lint:
name: ESLint
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: '18'
cache: 'npm'
- name: Install node dependencies
run: npm ci
- name: Run ESLint
run: npm run lint
unit-tests:
name: Unit Tests
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: '18'
cache: 'npm'
- name: Install npm
run: npm ci
- name: Test
run: npm run test
This workflow is triggered when you push the code or when you merge the PR. This CI workflow is successful after I merge the PR.
Also, when you create the PR, you must see GitHub is automatically running the CI workflow as below:
Top comments (0)