Greetings,
Entering week 10 of the open source course. We have been assigned to learn about a topic that has always interested me Continuous Integration (CI) Workflows, and automated testing. I've always wanted to work with GitHub Actions, and this weeks assignment gave the perfect time to do it.
Setting up this workflow was very simple, as the project tests were also simple. The default template GitHub Action for NodeJS testing was able to work out of the box. It functions on every PR and push to the main branch and runs the npm test
command which runs the full suite of tests on three major versions on Node.
The full file can be seen below:
name: Node.js CI
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x, 20.x, 22.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm run build --if-present
- run: npm test
Writing tests for my partners repo was interesting as they had used a different testing framework. They had opted to use Jest where I was using Vitest while syntactically similar the functions had some slight differences. Given that they had very good test coverage out of the gate, I only opted to add some minor tests for some edge cases.
Having implemented CI for this assignment while not a very complex implementation. The fact that a basic automated testing system is just a few clicks away is new information to me. Seeing this I look forwards to adding this to more of my personal project.
Top comments (0)