From 7caf09042a349676f1a0a58f604004048b06b27d Mon Sep 17 00:00:00 2001 From: Kevin van Zonneveld Date: Thu, 5 Dec 2024 13:08:33 +0100 Subject: [PATCH] Add Codecov (#202) * Add comprehensive coverage reporting and thresholds * Lower thresholds * Also update in vitest * Update vitest.config.mjs * Update vitest.config.mjs Co-authored-by: Remco Haszing * Update .github/workflows/ci.yml Co-authored-by: Mikael Finstad * Update ci.yml --------- Co-authored-by: Remco Haszing Co-authored-by: Mikael Finstad --- .github/workflows/ci.yml | 25 +++++++++++++++++++++++++ README.md | 36 ++++++++++++++++++++++++++++++++++++ vitest.config.mjs | 14 ++++++++++++-- 3 files changed, 73 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9d24223..a3b0308 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -66,6 +66,30 @@ jobs: node-version: ${{ matrix.node }} - run: corepack yarn - run: corepack yarn vitest run --coverage ./test/unit + - name: Upload coverage reports artifact + if: matrix.node == 22 # Only upload coverage from the latest Node.js version + uses: actions/upload-artifact@v4 + with: + name: coverage-reports + path: coverage/ + + coverage: + needs: vitest + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/download-artifact@v4 + with: + name: coverage-reports + path: coverage + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} + files: ./coverage/lcov.info + flags: unittests + name: node-sdk + fail_ci_if_error: true release: runs-on: ubuntu-latest @@ -75,6 +99,7 @@ jobs: - prettier - typescript - vitest + - coverage if: startsWith(github.ref, 'refs/tags/') permissions: id-token: write diff --git a/README.md b/README.md index 48580f5..3fad67e 100644 --- a/README.md +++ b/README.md @@ -489,3 +489,39 @@ Thanks to [Ian Hansen](https://github.com/supershabam) for donating the `translo ## License [MIT](LICENSE) © [Transloadit](https://transloadit.com) + +## Development + +### Testing + +This project uses [Vitest](https://vitest.dev) for testing. There are two types of tests: + +#### Unit Tests + +Run unit tests with: + +```bash +yarn test-unit +``` + +This will also generate a coverage report in the `coverage` directory. + +#### Integration Tests + +Run integration tests with: + +```bash +yarn test-integration +``` + +Note: Integration tests require valid Transloadit credentials. + +### Code Coverage + +Coverage reports are: + +- Generated locally in the `coverage` directory +- Uploaded to Codecov for tracking +- Enforced in CI (builds will fail if coverage drops below thresholds) + +View the coverage report locally by opening `coverage/index.html` in your browser. diff --git a/vitest.config.mjs b/vitest.config.mjs index 109cde7..2e8f04f 100644 --- a/vitest.config.mjs +++ b/vitest.config.mjs @@ -3,8 +3,18 @@ import { defineConfig } from 'vitest/config' export default defineConfig({ test: { coverage: { - include: 'src', - reporter: ['json', 'lcov', 'text', 'clover', 'json-summary'], + include: ['src/**/*.ts'], + exclude: ['**/*.d.ts', '**/*.test.ts', '**/test/**'], + reporter: ['json', 'lcov', 'text', 'clover', 'json-summary', 'html'], + provider: 'v8', + thresholds: { + // We want to boost this to 80%, but that should happen in a separate PR + statements: 2, + branches: 2, + functions: 0, + lines: 2, + perFile: true, + }, }, globals: true, },