From bb54dd6f13f0deadd244803db67b1c0ff7931e77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sindre=20B=C3=B8yum?= Date: Mon, 20 Oct 2025 19:52:25 +0200 Subject: [PATCH 1/5] ci: comment test coverage --- .github/workflows/test-coverage.yml | 68 +++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 .github/workflows/test-coverage.yml diff --git a/.github/workflows/test-coverage.yml b/.github/workflows/test-coverage.yml new file mode 100644 index 0000000..58e1d18 --- /dev/null +++ b/.github/workflows/test-coverage.yml @@ -0,0 +1,68 @@ +name: Test Coverage + +on: + pull_request: + branches: [ main ] + +jobs: + test: + runs-on: ubuntu-latest + permissions: + contents: read + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + cache: 'npm' + + - name: Install dependencies + run: npm install + + - name: Run tests with coverage + run: | + npm run test:coverage > coverage-output.txt 2>&1 || true + + - name: Upload coverage report + uses: actions/upload-artifact@v4 + with: + name: coverage-report + path: coverage-output.txt + retention-days: 1 + + comment: + runs-on: ubuntu-latest + needs: test + permissions: + pull-requests: write + + steps: + - name: Download coverage report + uses: actions/download-artifact@v4 + with: + name: coverage-report + + - name: Read coverage report + id: coverage + run: | + echo "COVERAGE_REPORT<> $GITHUB_OUTPUT + cat coverage-output.txt >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT + + - name: Post coverage comment + uses: peter-evans/create-or-update-comment@v4 + with: + issue-number: ${{ github.event.pull_request.number }} + body: | + ## Test Coverage Report + + ``` + ${{ steps.coverage.outputs.COVERAGE_REPORT }} + ``` + + --- + *Coverage report generated by GitHub Actions* From e6826a7a5ce6e0727e25bcd7d847e01f608eec5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sindre=20B=C3=B8yum?= Date: Mon, 20 Oct 2025 19:54:09 +0200 Subject: [PATCH 2/5] test: make test fail --- src/mathUtils.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mathUtils.test.js b/src/mathUtils.test.js index b594427..0c202ea 100644 --- a/src/mathUtils.test.js +++ b/src/mathUtils.test.js @@ -9,7 +9,7 @@ import { average, isPrime, max, min, sum } from "./mathUtils.js"; describe("mathUtils", () => { describe("sum", () => { test("should sum an array of numbers", () => { - assert.strictEqual(sum([1, 2, 3, 4, 5]), 15); + assert.strictEqual(sum([1, 2, 3, 4, 5]), 16); assert.strictEqual(sum([10, 20, 30]), 60); }); From 234af3bc7f41dcd6216c4313533b4fd9df1e138f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sindre=20B=C3=B8yum?= Date: Mon, 20 Oct 2025 19:57:36 +0200 Subject: [PATCH 3/5] test: make test fail --- src/stringUtils.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stringUtils.test.js b/src/stringUtils.test.js index 7909c8f..e980aff 100644 --- a/src/stringUtils.test.js +++ b/src/stringUtils.test.js @@ -10,7 +10,7 @@ describe("stringUtils", () => { describe("capitalize", () => { test("should capitalize the first letter", () => { assert.strictEqual(capitalize("hello"), "Hello"); - assert.strictEqual(capitalize("world"), "World"); + assert.strictEqual(capitalize("world"), "Wodsdsdsrld"); }); test("should handle already capitalized strings", () => { From 60cad0b033740b97483605e332015aef11c032c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sindre=20B=C3=B8yum?= Date: Mon, 20 Oct 2025 20:00:06 +0200 Subject: [PATCH 4/5] ci: make test step fail if tests fail --- .github/workflows/test-coverage.yml | 2 +- tasks/005-outputs-and-artifacts.md | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test-coverage.yml b/.github/workflows/test-coverage.yml index 58e1d18..527c6bf 100644 --- a/.github/workflows/test-coverage.yml +++ b/.github/workflows/test-coverage.yml @@ -25,7 +25,7 @@ jobs: - name: Run tests with coverage run: | - npm run test:coverage > coverage-output.txt 2>&1 || true + npm run test:coverage > coverage-output.txt 2>&1 - name: Upload coverage report uses: actions/upload-artifact@v4 diff --git a/tasks/005-outputs-and-artifacts.md b/tasks/005-outputs-and-artifacts.md index e69de29..ace7afd 100644 --- a/tasks/005-outputs-and-artifacts.md +++ b/tasks/005-outputs-and-artifacts.md @@ -0,0 +1,3 @@ + +> [!TIP] +> An artifact is a file or set of files that are produced by a workflow and can be used by other jobs or downloaded later. \ No newline at end of file From 68d26752f28405f0b08f5cff33661f8a8b31f86c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sindre=20B=C3=B8yum?= Date: Mon, 20 Oct 2025 20:08:10 +0200 Subject: [PATCH 5/5] chore: fix tests --- .github/workflows/test-coverage.yml | 2 +- src/mathUtils.test.js | 2 +- src/stringUtils.test.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test-coverage.yml b/.github/workflows/test-coverage.yml index 527c6bf..12e76e9 100644 --- a/.github/workflows/test-coverage.yml +++ b/.github/workflows/test-coverage.yml @@ -54,7 +54,7 @@ jobs: echo "EOF" >> $GITHUB_OUTPUT - name: Post coverage comment - uses: peter-evans/create-or-update-comment@v4 + uses: peter-evans/create-or-update-comment@v5 with: issue-number: ${{ github.event.pull_request.number }} body: | diff --git a/src/mathUtils.test.js b/src/mathUtils.test.js index 0c202ea..b594427 100644 --- a/src/mathUtils.test.js +++ b/src/mathUtils.test.js @@ -9,7 +9,7 @@ import { average, isPrime, max, min, sum } from "./mathUtils.js"; describe("mathUtils", () => { describe("sum", () => { test("should sum an array of numbers", () => { - assert.strictEqual(sum([1, 2, 3, 4, 5]), 16); + assert.strictEqual(sum([1, 2, 3, 4, 5]), 15); assert.strictEqual(sum([10, 20, 30]), 60); }); diff --git a/src/stringUtils.test.js b/src/stringUtils.test.js index e980aff..7909c8f 100644 --- a/src/stringUtils.test.js +++ b/src/stringUtils.test.js @@ -10,7 +10,7 @@ describe("stringUtils", () => { describe("capitalize", () => { test("should capitalize the first letter", () => { assert.strictEqual(capitalize("hello"), "Hello"); - assert.strictEqual(capitalize("world"), "Wodsdsdsrld"); + assert.strictEqual(capitalize("world"), "World"); }); test("should handle already capitalized strings", () => {