diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 015f5f18..60463d20 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -9,10 +9,54 @@ on: jobs: run-unit-tests: runs-on: ubuntu-latest + permissions: + contents: read steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v2 with: node-version: "20" - run: yarn install - - run: yarn test + - run: yarn test:coverage + - name: Add coverage summary + if: always() + run: | + node <<'EOF' + const fs = require("fs"); + + const summaryPath = "coverage/coverage-summary.json"; + + if (!fs.existsSync(summaryPath)) { + fs.appendFileSync( + process.env.GITHUB_STEP_SUMMARY, + "## Coverage Summary\n\nCoverage summary was not generated.\n" + ); + process.exit(0); + } + + const summary = JSON.parse(fs.readFileSync(summaryPath, "utf8")).total; + const metrics = [ + ["Lines", summary.lines.pct], + ["Statements", summary.statements.pct], + ["Functions", summary.functions.pct], + ["Branches", summary.branches.pct], + ]; + + const output = [ + "## Coverage Summary", + "", + "| Metric | Coverage |", + "| --- | ---: |", + ...metrics.map(([label, value]) => `| ${label} | ${Number(value).toFixed(1)}% |`), + "", + ].join("\n"); + + fs.appendFileSync(process.env.GITHUB_STEP_SUMMARY, output); + EOF + - name: Upload coverage to Codecov + if: always() + uses: codecov/codecov-action@v5 + with: + files: ./coverage/lcov.info + fail_ci_if_error: false + verbose: true diff --git a/README.md b/README.md index 430e9634..db11388b 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ ![alt text](https://github.com/eclipse-editdor/editdor/blob/master/logo/1585_ediTDor_logo.png "ediTDor logo") [![Discord](https://img.shields.io/badge/Discord-7289DA?logo=discord&logoColor=white&label=WoT-CG-Discord)](https://discord.com/channels/1081253871688622181/1359286591100817549) +[![Coverage](https://codecov.io/gh/eclipse-editdor/editdor/graph/badge.svg?branch=master)](https://codecov.io/gh/eclipse-editdor/editdor) A tool for simply designing W3C Thing Descriptions and Thing Models diff --git a/vite.config.js b/vite.config.js index 20f5ca87..a4730068 100644 --- a/vite.config.js +++ b/vite.config.js @@ -24,6 +24,11 @@ export default defineConfig(({ mode }) => { environment: "jsdom", setupFiles: "./src/setupTests.ts", include: ["src/**/*.{test,spec}.{ts,tsx}"], + coverage: { + provider: "v8", + reportsDirectory: "./coverage", + reporter: ["text", "json-summary", "lcov"], + }, }, }; });