From 405099e57742c675da8f27e518686ef5cb37032a Mon Sep 17 00:00:00 2001 From: Kevin van Zonneveld Date: Wed, 27 Nov 2024 12:06:56 +0100 Subject: [PATCH 1/7] Add comprehensive coverage reporting and thresholds --- .github/workflows/ci.yml | 42 +++++++++++++++++++++++++++++++++++++++ README.md | 43 ++++++++++++++++++++++++++++++++++++++++ vitest.config.mjs | 16 +++++++++++++-- 3 files changed, 99 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9d242237..aca17643 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -66,6 +66,47 @@ jobs: node-version: ${{ matrix.node }} - run: corepack yarn - run: corepack yarn vitest run --coverage ./test/unit + - name: Upload coverage reports + if: matrix.node == 22 # Only upload coverage from the latest Node.js version + uses: actions/upload-artifact@v4 + with: + name: coverage-reports + path: coverage/ + - name: Upload coverage to Codecov + if: matrix.node == 22 # Only upload coverage from the latest Node.js version + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} + files: ./coverage/lcov.info + flags: unittests + name: node-sdk + fail_ci_if_error: true + + coverage: + needs: vitest + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/download-artifact@v4 + with: + name: coverage-reports + path: coverage + - name: Check coverage thresholds + run: | + if [ ! -f coverage/coverage-summary.json ]; then + echo "No coverage report found" + exit 1 + fi + + COVERAGE=$(jq -r '.total.lines.pct' coverage/coverage-summary.json) + THRESHOLD=80 + + if (( $(echo "$COVERAGE < $THRESHOLD" | bc -l) )); then + echo "Coverage ($COVERAGE%) is below threshold ($THRESHOLD%)" + exit 1 + else + echo "Coverage ($COVERAGE%) meets threshold ($THRESHOLD%)" + fi release: runs-on: ubuntu-latest @@ -75,6 +116,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 739329b9..558df257 100644 --- a/README.md +++ b/README.md @@ -462,3 +462,46 @@ 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 + +We maintain high code coverage to ensure reliability. The minimum coverage thresholds are: + +- Statements: 80% +- Branches: 80% +- Functions: 80% +- Lines: 80% + +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 109cde70..91918846 100644 --- a/vitest.config.mjs +++ b/vitest.config.mjs @@ -3,9 +3,21 @@ 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: { + statements: 80, + branches: 80, + functions: 80, + lines: 80, + perFile: true, + }, + clean: true, + reportsDirectory: './coverage', }, globals: true, + environment: 'node', }, }) From f809d9f9f08a1905a280641c0aceb64c3180f0b0 Mon Sep 17 00:00:00 2001 From: Kevin van Zonneveld Date: Wed, 27 Nov 2024 12:39:13 +0100 Subject: [PATCH 2/7] Lower thresholds --- .github/workflows/ci.yml | 2 +- README.md | 7 ------- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index aca17643..19c13b82 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -99,7 +99,7 @@ jobs: fi COVERAGE=$(jq -r '.total.lines.pct' coverage/coverage-summary.json) - THRESHOLD=80 + THRESHOLD=1 if (( $(echo "$COVERAGE < $THRESHOLD" | bc -l) )); then echo "Coverage ($COVERAGE%) is below threshold ($THRESHOLD%)" diff --git a/README.md b/README.md index 558df257..090cf8e2 100644 --- a/README.md +++ b/README.md @@ -491,13 +491,6 @@ Note: Integration tests require valid Transloadit credentials. ### Code Coverage -We maintain high code coverage to ensure reliability. The minimum coverage thresholds are: - -- Statements: 80% -- Branches: 80% -- Functions: 80% -- Lines: 80% - Coverage reports are: - Generated locally in the `coverage` directory From 5b8b185e78f29a90bcf475b6f594375b8f074386 Mon Sep 17 00:00:00 2001 From: Kevin van Zonneveld Date: Wed, 27 Nov 2024 12:43:39 +0100 Subject: [PATCH 3/7] Also update in vitest --- .github/workflows/ci.yml | 10 ---------- vitest.config.mjs | 8 ++++---- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 19c13b82..a004b03f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -98,16 +98,6 @@ jobs: exit 1 fi - COVERAGE=$(jq -r '.total.lines.pct' coverage/coverage-summary.json) - THRESHOLD=1 - - if (( $(echo "$COVERAGE < $THRESHOLD" | bc -l) )); then - echo "Coverage ($COVERAGE%) is below threshold ($THRESHOLD%)" - exit 1 - else - echo "Coverage ($COVERAGE%) meets threshold ($THRESHOLD%)" - fi - release: runs-on: ubuntu-latest needs: diff --git a/vitest.config.mjs b/vitest.config.mjs index 91918846..97c7d05f 100644 --- a/vitest.config.mjs +++ b/vitest.config.mjs @@ -8,10 +8,10 @@ export default defineConfig({ reporter: ['json', 'lcov', 'text', 'clover', 'json-summary', 'html'], provider: 'v8', thresholds: { - statements: 80, - branches: 80, - functions: 80, - lines: 80, + statements: 2, + branches: 2, + functions: 2, + lines: 2, perFile: true, }, clean: true, From 996e1b635698969ddae8e5547007a6ec62147ae7 Mon Sep 17 00:00:00 2001 From: Kevin van Zonneveld Date: Wed, 27 Nov 2024 12:47:17 +0100 Subject: [PATCH 4/7] Update vitest.config.mjs --- vitest.config.mjs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vitest.config.mjs b/vitest.config.mjs index 97c7d05f..be31d01e 100644 --- a/vitest.config.mjs +++ b/vitest.config.mjs @@ -8,9 +8,10 @@ export default defineConfig({ 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: 2, + functions: 0, lines: 2, perFile: true, }, From ea6ba81b7286fcafc541f6405032ea467b1ddef7 Mon Sep 17 00:00:00 2001 From: Kevin van Zonneveld Date: Mon, 2 Dec 2024 15:42:52 +0100 Subject: [PATCH 5/7] Update vitest.config.mjs Co-authored-by: Remco Haszing --- vitest.config.mjs | 3 --- 1 file changed, 3 deletions(-) diff --git a/vitest.config.mjs b/vitest.config.mjs index be31d01e..2e8f04fd 100644 --- a/vitest.config.mjs +++ b/vitest.config.mjs @@ -15,10 +15,7 @@ export default defineConfig({ lines: 2, perFile: true, }, - clean: true, - reportsDirectory: './coverage', }, globals: true, - environment: 'node', }, }) From 20b3338ed95facb1ab5c640ffaf3ed4980ae9203 Mon Sep 17 00:00:00 2001 From: Kevin van Zonneveld Date: Mon, 2 Dec 2024 15:43:02 +0100 Subject: [PATCH 6/7] Update .github/workflows/ci.yml Co-authored-by: Mikael Finstad --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a004b03f..55c13d89 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -66,7 +66,7 @@ jobs: node-version: ${{ matrix.node }} - run: corepack yarn - run: corepack yarn vitest run --coverage ./test/unit - - name: Upload coverage reports + - name: Upload coverage reports artifact if: matrix.node == 22 # Only upload coverage from the latest Node.js version uses: actions/upload-artifact@v4 with: From 50cd6d125fd7493b8b67f5cf06ac6f3dd2a0c187 Mon Sep 17 00:00:00 2001 From: Kevin van Zonneveld Date: Mon, 2 Dec 2024 17:00:42 +0100 Subject: [PATCH 7/7] Update ci.yml --- .github/workflows/ci.yml | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 55c13d89..a3b03084 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -72,15 +72,6 @@ jobs: with: name: coverage-reports path: coverage/ - - name: Upload coverage to Codecov - if: matrix.node == 22 # Only upload coverage from the latest Node.js version - uses: codecov/codecov-action@v4 - with: - token: ${{ secrets.CODECOV_TOKEN }} - files: ./coverage/lcov.info - flags: unittests - name: node-sdk - fail_ci_if_error: true coverage: needs: vitest @@ -91,12 +82,14 @@ jobs: with: name: coverage-reports path: coverage - - name: Check coverage thresholds - run: | - if [ ! -f coverage/coverage-summary.json ]; then - echo "No coverage report found" - exit 1 - fi + - 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