Testing.. how?!
jsong89
Posted on November 20, 2021
Github repo: Repo
Github github actions run: Action Run
Testing PR at Another Repo: Another Repo
Add CI
This week's Lab09 was to apply CI and check the compatibility of the test code using Github Action for the function. I added node.js.yaml
for this task.
name: Node.js CI
on:
push:
branches: [master]
pull_request:
branches: [master]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x, 15.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run build --if-present
- run: npm test
It is possible to remove or add a version to test the node of the desired version by modifying node-version
in the relevant part. In my case, I only tested the 14.x and 16.x versions because the core features of SSG are based on Node 14. At first, I didn't understand why I had to do this, but after a while I realized the importance of compatibility. In addition, it is now possible to know which parts are in conflict before the application of PR.
Add test another Project
To meet the other requirements of Lab09, I collaborated with Hung Nguyen, a student I had worked with previously, and Mizuho Okimoto, a very cool and fun new collaborator. After adding the simple level test code in the student's project
describe("test syntaxHighlight", () => {
const prepareForHead = () => {
const head = parse(`<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>`);
return head;
};
const prepareForBody = () => {
const body = parse(`<body>
<pre>will be highlight</pre>
</body>`);
return body;
};
test("No commands were passed", () => {
const body = prepareForBody();
const head = prepareForHead();
syntaxHighlight(body, head);
expect(head.querySelector("link")).not.toBeNull();
expect(
body.querySelector("pre").classList.contains("highlight")
).toBeTruthy();
});
});
As a result of the CI, fortunately, it passed safely and I requested a PR.
Posted on November 20, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
November 11, 2024