1. Lab9 requirement
In this lab, I am required to create a GitHub Actions Workflow to my repo. By doing so, the tests I created in the previous lab will be triggered and run whenever a PR is submitted or a commit is pushed.
In addition, I need to add tests to Dustin's project.
2. Setup process
To set up the GitHub workflow, I came to the Action tab and clicked set up this workflow button in the Node.js section.
After that, a new file called node.js.yml is created, I modified some parts to make the build suit my purpose. And its content is:
# This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
name: Node.js CI
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x, 16.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
cache: "npm"
- run: npm ci
- run: npm test
Next, I created some e2e tests. Then, submitting a PR to make sure that it did trigger the CI Workflow. After a couple of times modifying the source code. My tests were passed successfully. Successful GitHub Action Run
3. Adding Tests To Another Project
After forking and cloning Dustin's repo to my local machine, I read through the CONTRIBUTING.md to set up and run the tool to make sure it work correctly.
I saw the init() in the readPath module did not have any test so I created a new branch and started working on it.
After all, here are 4 tests I came up with:
- Constructor should set the value of
pathequals to the link passed from arg. -
readFile()should return1if file path is invalid . -
init()should setextandresultvalues correctly for text file. -
init()should setextandresultvalues correctly for markdown file.
When newly created tests run successfully in the local machine, I submitted a PR to the repo and make sure it passed the repo's CI workflow.
4. Overall
It's interesting to work and learn about CI. I definitely make use of this tool to my future projects.
All in all, thank you for reading the post.
Happy coding!
Top comments (0)