From 5b0c6b4cb0aab252b1bba70fd510bb2f37cc8fd1 Mon Sep 17 00:00:00 2001 From: Stefan Verhoeven Date: Thu, 8 Aug 2024 11:06:03 +0200 Subject: [PATCH] Add coverage and codecov --- .github/workflows/test.yml | 10 +++- .gitignore | 3 + CONTRIBUTING.md | 5 +- package.json | 1 + pnpm-lock.yaml | 113 +++++++++++++++++++++++++++++++++++++ vite.config.ts | 6 ++ 6 files changed, 136 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a38acca..34b8d72 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,6 +6,9 @@ on: pull_request: branches: [ "main" ] +permissions: + id-token: write # This is required for requesting the JWT + jobs: test: runs-on: ubuntu-latest @@ -24,4 +27,9 @@ jobs: - name: Install Playwright Browsers run: pnpm exec playwright install --with-deps chromium - name: Test - run: pnpm test + run: pnpm test -- run --coverage --coverage.reporter=clover + - name: Code coverage upload + uses: codecov/codecov-action@v4 + with: + files: ./coverage/clover.xml + use_oidc: true diff --git a/.gitignore b/.gitignore index 178cdaa..18f6828 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,6 @@ docs # Pack i-vresse-haddock3-ui-*.tgz + +# Test +coverage diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 35b1064..b3cc77d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -48,10 +48,13 @@ pnpm format Testing logic can be done with tests written with [vitest](https://vitest.dev) in [browser mode](https://vitest.dev/guide/browser/). ```bash -pnpm exec playwright install # Only needed once +pnpm exec playwright install # Only needed once per installation pnpm test # Or to run headless CI=1 pnpm test +# Or for coverage +CI=1 pnpm test -- run --coverage --coverage.reporter=html +# Open coverage/index.html in browser ``` Stories and tests can be located next to the code in the `src/` folder. diff --git a/package.json b/package.json index c333ba2..e88fcf3 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,7 @@ "@typescript-eslint/parser": "^7.15.0", "@vitejs/plugin-react": "^4.3.1", "@vitest/browser": "^2.0.5", + "@vitest/coverage-istanbul": "^2.0.5", "autoprefixer": "^10.4.19", "playwright": "^1.46.0", "postcss": "^8.4.40", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7448ec2..9697586 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -57,6 +57,9 @@ importers: '@vitest/browser': specifier: ^2.0.5 version: 2.0.5(playwright@1.46.0)(typescript@5.5.4)(vitest@2.0.5) + '@vitest/coverage-istanbul': + specifier: ^2.0.5 + version: 2.0.5(vitest@2.0.5(@types/node@20.14.12)(@vitest/browser@2.0.5)) autoprefixer: specifier: ^10.4.19 version: 10.4.19(postcss@8.4.40) @@ -453,6 +456,10 @@ packages: resolution: {integrity: sha512-O8jcjabXaleOG9DQ0+ARXWZBTfnP4WNAqzuiJK7ll44AmxGKv/J2M4TPjxjY3znBCfvBXFzucm1twdyFybFqEA==} engines: {node: '>=12'} + '@istanbuljs/schema@0.1.3': + resolution: {integrity: sha512-ZXRY4jNvVgSVQ8DL3LTcakaAtXwTVUxE81hslsyD2AtoXW/wVob10HkOJ1X/pAlcI7D+2YoZKg5do8G/w6RYgA==} + engines: {node: '>=8'} + '@jridgewell/gen-mapping@0.3.5': resolution: {integrity: sha512-IzL8ZoEDIBRWEzlCcRhOaCupYyN5gdIK+Q6fbFdPDg6HqX6jpkItn7DFIpW9LQzXG6Df9sA7+OKnq0qlz/GaQg==} engines: {node: '>=6.0.0'} @@ -975,6 +982,11 @@ packages: webdriverio: optional: true + '@vitest/coverage-istanbul@2.0.5': + resolution: {integrity: sha512-BvjWKtp7fiMAeYUD0mO5cuADzn1gmjTm54jm5qUEnh/O08riczun8rI4EtQlg3bWoRo2lT3FO8DmjPDX9ZthPw==} + peerDependencies: + vitest: 2.0.5 + '@vitest/expect@2.0.5': resolution: {integrity: sha512-yHZtwuP7JZivj65Gxoi8upUN2OzHTi3zVfjwdpu2WrvCZPLwsJ2Ey5ILIPccoW23dd/zQBlJ4/dhi7DWNyXCpA==} @@ -1884,6 +1896,9 @@ packages: history@5.3.0: resolution: {integrity: sha512-ZqaKwjjrAYUYfLG+htGaIIZ4nioX2L70ZUMIFysS3xvBsSG4x/n1V6TXV3N8ZYNuFGlDirFg32T7B6WOUPDYcQ==} + html-escaper@2.0.2: + resolution: {integrity: sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==} + html-url-attributes@3.0.0: resolution: {integrity: sha512-/sXbVCWayk6GDVg3ctOX6nxaVj7So40FcFAnWlWGNAB1LpYKcV5Cd10APjPjW80O7zYW2MsjBV4zZ7IZO5fVow==} @@ -2090,6 +2105,26 @@ packages: isexe@2.0.0: resolution: {integrity: sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==} + istanbul-lib-coverage@3.2.2: + resolution: {integrity: sha512-O8dpsF+r0WV/8MNRKfnmrtCWhuKjxrq2w+jpzBL5UZKTi2LeVWnWOmWRxFlesJONmc+wLAGvKQZEOanko0LFTg==} + engines: {node: '>=8'} + + istanbul-lib-instrument@6.0.3: + resolution: {integrity: sha512-Vtgk7L/R2JHyyGW07spoFlB8/lpjiOLTjMdms6AFMraYt3BaJauod/NGrfnVG/y4Ix1JEuMRPDPEj2ua+zz1/Q==} + engines: {node: '>=10'} + + istanbul-lib-report@3.0.1: + resolution: {integrity: sha512-GCfE1mtsHGOELCU8e/Z7YWzpmybrx/+dSTfLrvY8qRmaY6zXTKWn6WQIjaAFw069icm6GVMNkgu0NzI4iPZUNw==} + engines: {node: '>=10'} + + istanbul-lib-source-maps@5.0.6: + resolution: {integrity: sha512-yg2d+Em4KizZC5niWhQaIomgf5WlL4vOOjZ5xGCmF8SnPE/mDWWXgvRExdcpCgh9lLRRa1/fSYp2ymmbJ1pI+A==} + engines: {node: '>=10'} + + istanbul-reports@3.1.7: + resolution: {integrity: sha512-BewmUXImeuRk2YY0PVbxgKAysvhRPUQE0h5QRM++nVWyubKGV0l8qQ5op8+B2DOmwSe63Jivj0BjkPQVf8fP5g==} + engines: {node: '>=8'} + jackspeak@3.4.3: resolution: {integrity: sha512-OGlZQpz2yfahA/Rd1Y8Cd9SIEsqvXkLVoSw/cgwhnhFMDbsQFeZYoJJ7bIZBS9BcamUW96asq/npPWugM+RQBw==} @@ -2223,6 +2258,13 @@ packages: magic-string@0.30.10: resolution: {integrity: sha512-iIRwTIf0QKV3UAnYK4PU8uiEc4SRh5jX0mwpIwETPpHdhVM4f53RSwS/vXvN1JhGX+Cs7B8qIq3d6AH49O5fAQ==} + magicast@0.3.4: + resolution: {integrity: sha512-TyDF/Pn36bBji9rWKHlZe+PZb6Mx5V8IHCSxk7X4aljM4e/vyDvZZYwHewdVaqiA0nb3ghfHU/6AUpDxWoER2Q==} + + make-dir@4.0.0: + resolution: {integrity: sha512-hXdUTZYIVOt1Ex//jAQi+wTZZpUpwBj/0QsOzqegb3rGMMeJiSEu5xLHnYfBrRV4RH2+OCSOO95Is/7x1WJ4bw==} + engines: {node: '>=10'} + markdown-extensions@2.0.0: resolution: {integrity: sha512-o5vL7aDWatOTX8LzaS1WMoaoxIiLRQJuIKKe2wAw6IeULDHaqbiqiggmx+pKvZDb1Sj+pE46Sn1T7lCqfFtg1Q==} engines: {node: '>=16'} @@ -3128,6 +3170,10 @@ packages: engines: {node: '>=14.0.0'} hasBin: true + test-exclude@7.0.1: + resolution: {integrity: sha512-pFYqmTw68LXVjeWJMST4+borgQP2AyMNbg1BpZh9LbyhUeNkeaPF9gzfPGUAnSMV3qPYdWUwDIjjCLiSDOl7vg==} + engines: {node: '>=18'} + text-table@0.2.0: resolution: {integrity: sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==} @@ -3895,6 +3941,8 @@ snapshots: wrap-ansi: 8.1.0 wrap-ansi-cjs: wrap-ansi@7.0.0 + '@istanbuljs/schema@0.1.3': {} + '@jridgewell/gen-mapping@0.3.5': dependencies: '@jridgewell/set-array': 1.2.1 @@ -4519,6 +4567,22 @@ snapshots: - typescript - utf-8-validate + '@vitest/coverage-istanbul@2.0.5(vitest@2.0.5(@types/node@20.14.12)(@vitest/browser@2.0.5))': + dependencies: + '@istanbuljs/schema': 0.1.3 + debug: 4.3.5 + istanbul-lib-coverage: 3.2.2 + istanbul-lib-instrument: 6.0.3 + istanbul-lib-report: 3.0.1 + istanbul-lib-source-maps: 5.0.6 + istanbul-reports: 3.1.7 + magicast: 0.3.4 + test-exclude: 7.0.1 + tinyrainbow: 1.2.0 + vitest: 2.0.5(@types/node@20.14.12)(@vitest/browser@2.0.5) + transitivePeerDependencies: + - supports-color + '@vitest/expect@2.0.5': dependencies: '@vitest/spy': 2.0.5 @@ -5660,6 +5724,8 @@ snapshots: dependencies: '@babel/runtime': 7.24.8 + html-escaper@2.0.2: {} + html-url-attributes@3.0.0: {} html-void-elements@3.0.0: {} @@ -5843,6 +5909,37 @@ snapshots: isexe@2.0.0: {} + istanbul-lib-coverage@3.2.2: {} + + istanbul-lib-instrument@6.0.3: + dependencies: + '@babel/core': 7.24.9 + '@babel/parser': 7.24.8 + '@istanbuljs/schema': 0.1.3 + istanbul-lib-coverage: 3.2.2 + semver: 7.6.3 + transitivePeerDependencies: + - supports-color + + istanbul-lib-report@3.0.1: + dependencies: + istanbul-lib-coverage: 3.2.2 + make-dir: 4.0.0 + supports-color: 7.2.0 + + istanbul-lib-source-maps@5.0.6: + dependencies: + '@jridgewell/trace-mapping': 0.3.25 + debug: 4.3.5 + istanbul-lib-coverage: 3.2.2 + transitivePeerDependencies: + - supports-color + + istanbul-reports@3.1.7: + dependencies: + html-escaper: 2.0.2 + istanbul-lib-report: 3.0.1 + jackspeak@3.4.3: dependencies: '@isaacs/cliui': 8.0.2 @@ -5979,6 +6076,16 @@ snapshots: dependencies: '@jridgewell/sourcemap-codec': 1.5.0 + magicast@0.3.4: + dependencies: + '@babel/parser': 7.24.8 + '@babel/types': 7.24.9 + source-map-js: 1.2.0 + + make-dir@4.0.0: + dependencies: + semver: 7.6.3 + markdown-extensions@2.0.0: {} markdown-it@14.1.0: @@ -7236,6 +7343,12 @@ snapshots: transitivePeerDependencies: - ts-node + test-exclude@7.0.1: + dependencies: + '@istanbuljs/schema': 0.1.3 + glob: 10.4.5 + minimatch: 9.0.5 + text-table@0.2.0: {} thenify-all@1.6.0: diff --git a/vite.config.ts b/vite.config.ts index 915fa60..bdfaefa 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -13,5 +13,11 @@ export default defineConfig({ provider: "playwright", providerOptions: {}, }, + coverage: { + provider: "istanbul", + reporter: ["text"], + include: ["src/**/*"], + exclude: ["**/*.stories.*", "**/*.test.*"], + }, }, });