Skip to content

Commit

Permalink
Add Codecov (#202)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* Update .github/workflows/ci.yml

Co-authored-by: Mikael Finstad <[email protected]>

* Update ci.yml

---------

Co-authored-by: Remco Haszing <[email protected]>
Co-authored-by: Mikael Finstad <[email protected]>
  • Loading branch information
3 people authored Dec 5, 2024
1 parent 3c0ef2e commit 7caf090
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 2 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -75,6 +99,7 @@ jobs:
- prettier
- typescript
- vitest
- coverage
if: startsWith(github.ref, 'refs/tags/')
permissions:
id-token: write
Expand Down
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
14 changes: 12 additions & 2 deletions vitest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down

0 comments on commit 7caf090

Please sign in to comment.