Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Report coverage with CodeCov #2862

Merged
merged 8 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 57 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,31 @@ on:
- 'LICENSE'

jobs:
coverage:
name: 'Coverage'
runs-on: ubuntu-latest
needs:
# bun excluded because it uses built-in test tool which does not support coverage in v8/istanbul format.
# refer https://github.com/oven-sh/bun/issues/4015
- main
- fastly
- node
- wrangler
- lambda
- lambda-edge
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
pattern: coverage-*
merge-multiple: true
path: ./coverage
- uses: codecov/codecov-action@v4
with:
fail_ci_if_error: true
directory: ./coverage
token: ${{ secrets.CODECOV_TOKEN }}

main:
name: 'Main'
runs-on: ubuntu-latest
Expand All @@ -28,6 +53,10 @@ jobs:
- run: bun run lint
- run: bun run build
- run: bun run test
- uses: actions/upload-artifact@v4
with:
name: coverage-main
path: coverage/

jsr-dry-run:
name: "Checking if it's valid for JSR"
Expand All @@ -47,9 +76,13 @@ jobs:
- uses: denoland/setup-deno@v1
with:
deno-version: v1.x
- run: env NAME=Deno deno test --allow-read --allow-env --allow-write -c runtime_tests/deno/deno.json runtime_tests/deno
- run: deno test -c runtime_tests/deno-jsx/deno.precompile.json runtime_tests/deno-jsx
- run: deno test -c runtime_tests/deno-jsx/deno.react-jsx.json runtime_tests/deno-jsx
- run: env NAME=Deno deno test --coverage=coverage/raw/deno-runtime --allow-read --allow-env --allow-write -c runtime_tests/deno/deno.json runtime_tests/deno
- run: deno test -c runtime_tests/deno-jsx/deno.precompile.json --coverage=coverage/raw/deno-precompile-jsx runtime_tests/deno-jsx
- run: deno test -c runtime_tests/deno-jsx/deno.react-jsx.json --coverage=coverage/raw/deno-react-jsx runtime_tests/deno-jsx
- uses: actions/upload-artifact@v4
with:
name: coverage-deno
path: coverage/

bun:
name: 'Bun'
Expand All @@ -70,6 +103,10 @@ jobs:
- run: bun install
- run: bun run build
- run: bun run test:fastly
- uses: actions/upload-artifact@v4
with:
name: coverage-fastly
path: coverage/

node:
name: 'Node.js v${{ matrix.node }}'
Expand All @@ -86,6 +123,11 @@ jobs:
- run: bun install
- run: bun run build
- run: bun run test:node
- uses: actions/upload-artifact@v4
if: matrix.node == '22.x'
with:
name: coverage-node
path: coverage/

wrangler:
name: 'Cloudflare Workers'
Expand All @@ -96,6 +138,10 @@ jobs:
- run: bun install
- run: bun run build
- run: bun run test:wrangler
- uses: actions/upload-artifact@v4
with:
name: coverage-wrangler
path: coverage/

lambda:
name: 'AWS Lambda'
Expand All @@ -106,6 +152,10 @@ jobs:
- run: bun install
- run: bun run build
- run: bun run test:lambda
- uses: actions/upload-artifact@v4
with:
name: coverage-lambda
path: coverage/

lambda-edge:
name: 'Lambda@Edge'
Expand All @@ -116,3 +166,7 @@ jobs:
- run: bun install --frozen-lockfile
- run: bun run build
- run: bun run test:lambda-edge
- uses: actions/upload-artifact@v4
with:
name: coverage-lambda-edge
path: coverage/
3 changes: 3 additions & 0 deletions .vitest.config/jsx-runtime-default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@ if (config.test) {
'**/src/jsx/dom/**/(*.)+(spec|test).+(ts|tsx|js)',
'src/jsx/hooks/dom.test.tsx',
]
if (config.test.coverage) {
config.test.coverage.reportsDirectory = './coverage/raw/jsx-runtime'
}
}
export default config
3 changes: 3 additions & 0 deletions .vitest.config/jsx-runtime-dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@ if (config.test) {
'**/src/jsx/dom/**/(*.)+(spec|test).+(ts|tsx|js)',
'src/jsx/hooks/dom.test.tsx',
]
if (config.test.coverage) {
config.test.coverage.reportsDirectory = './coverage/raw/jsx-dom'
}
}
export default config
13 changes: 13 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Edit "test.coverage.exclude" option in vitest.config.ts to exclude specific files from coverage reports.
# We can also use "ignore" option in codecov.yml, but it is not recognized by vitest, so results may differ on local.

coverage:
status:
patch:
default:
target: 80%
informational: true # Don't fail the build even if coverage is below target
project:
default:
target: 75%
threshold: 1%
5 changes: 5 additions & 0 deletions runtime_tests/bun/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
/// <reference types="vitest" />
import { defineConfig } from 'vitest/config'
import config from '../../vitest.config'

export default defineConfig({
test: {
globals: true,
include: ['**/runtime_tests/bun/**/*.+(ts|tsx|js)'],
coverage: {
...config.test?.coverage,
reportsDirectory: './coverage/raw/runtime-bun',
},
},
})
5 changes: 5 additions & 0 deletions runtime_tests/fastly/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
/// <reference types="vitest" />
import fastlyCompute from 'vite-plugin-fastly-js-compute'
import { defineConfig } from 'vitest/config'
import config from '../../vitest.config'

export default defineConfig({
plugins: [fastlyCompute()],
test: {
globals: true,
include: ['**/runtime_tests/fastly/**/(*.)+(test).+(ts|tsx)'],
exclude: ['**/runtime_tests/fastly/vitest.config.ts'],
coverage: {
...config.test?.coverage,
reportsDirectory: './coverage/raw/runtime-fastly',
},
},
})
5 changes: 5 additions & 0 deletions runtime_tests/lambda-edge/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/// <reference types="vitest" />
import { defineConfig } from 'vitest/config'
import config from '../../vitest.config'

export default defineConfig({
test: {
Expand All @@ -9,5 +10,9 @@ export default defineConfig({
globals: true,
include: ['**/runtime_tests/lambda-edge/**/*.+(ts|tsx|js)'],
exclude: ['**/runtime_tests/lambda-edge/vitest.config.ts'],
coverage: {
...config.test?.coverage,
reportsDirectory: './coverage/raw/runtime-lambda-edge',
},
},
})
5 changes: 5 additions & 0 deletions runtime_tests/lambda/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/// <reference types="vitest" />
import { defineConfig } from 'vitest/config'
import config from '../../vitest.config'

export default defineConfig({
test: {
Expand All @@ -9,5 +10,9 @@ export default defineConfig({
globals: true,
include: ['**/runtime_tests/lambda/**/*.+(ts|tsx|js)'],
exclude: ['**/runtime_tests/lambda/vitest.config.ts', '**/runtime_tests/lambda/mock.ts'],
coverage: {
...config.test?.coverage,
reportsDirectory: './coverage/raw/runtime-lambda',
},
},
})
5 changes: 5 additions & 0 deletions runtime_tests/node/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/// <reference types="vitest" />
import { defineConfig } from 'vitest/config'
import config from '../../vitest.config'

export default defineConfig({
test: {
Expand All @@ -9,5 +10,9 @@ export default defineConfig({
globals: true,
include: ['**/runtime_tests/node/**/*.+(ts|tsx|js)'],
exclude: ['**/runtime_tests/node/vitest.config.ts'],
coverage: {
...config.test?.coverage,
reportsDirectory: './coverage/raw/runtime-node',
},
},
})
5 changes: 5 additions & 0 deletions runtime_tests/wrangler/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
/// <reference types="vitest" />
import { defineConfig } from 'vitest/config'
import config from '../../vitest.config'

export default defineConfig({
test: {
globals: true,
include: ['**/runtime_tests/wrangler/**/(*.)+(test).+(ts|tsx)'],
exclude: ['**/runtime_tests/wrangler/vitest.config.ts'],
coverage: {
...config.test?.coverage,
reportsDirectory: './coverage/raw/runtime-wrangler',
},
},
})
12 changes: 11 additions & 1 deletion vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,18 @@ export default defineConfig({
exclude: [...configDefaults.exclude, '**/sandbox/**', '**/*.case.test.+(ts|tsx|js)'],
setupFiles: ['./src/test-utils/setup-vitest.ts'],
coverage: {
enabled: true,
provider: 'v8',
reporter: ['text'],
reportsDirectory: './coverage/raw/default',
reporter: ['json'],
exclude: [
...(configDefaults.coverage.exclude ?? []),
'benchmarks',
'runtime_tests',
'build.ts',
'src/test-utils',
'src/**/types.ts', // types are compile-time only, so their coverage cannot be measured
]
},
pool: 'forks',
},
Expand Down