Skip to content

Commit

Permalink
--coverage-excludes
Browse files Browse the repository at this point in the history
Signed-off-by: Matteo Collina <hello@matteocollina.com>
  • Loading branch information
mcollina committed Nov 27, 2023
1 parent 0ff1863 commit 7efc135
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
10 changes: 6 additions & 4 deletions borp.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { parseArgs } from 'node:util'
import { tap, spec } from 'node:test/reporters'
import { mkdtemp, rm } from 'node:fs/promises'
import { finished } from 'node:stream/promises'
import { join } from 'node:path'
import { join, relative } from 'node:path'
import runWithTypeScript from './lib/run.js'
import { Report } from 'c8'

Expand Down Expand Up @@ -54,11 +54,13 @@ await finished(stream)

if (covDir) {
try {
let exclude = [
...(args.values['coverage-exclude'] || '').split(',')
].filter(Boolean)
let exclude = (args.values['coverage-exclude'] || '').split(',').filter(Boolean)

if (exclude.length === 0) {
exclude = undefined
} else if (config.prefix) {
const localPrefix = relative(process.cwd(), config.prefix)
exclude = exclude.map((file) => join(localPrefix, file))
}
const report = Report({
reporter: ['text'],
Expand Down
1 change: 1 addition & 0 deletions lib/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export default async function runWithTypeScript (config) {
}

config.files = files
config.prefix = prefix

const stream = run(config)
return stream
Expand Down
16 changes: 16 additions & 0 deletions test/coverage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,19 @@ test('coverage', async () => {
match(res.stdout, /All files/)
match(res.stdout, /add\.ts/)
})

test('coverage excludes', async () => {
const res = await execa('node', [
borp,
'--coverage',
'--coverage-exclude=src'
], {
cwd: join(import.meta.url, '..', 'fixtures', 'ts-esm')
})

match(res.stdout, /% Stmts/)
match(res.stdout, /All files/)
// The test files are shown
match(res.stdout, /add\.test\.ts/)
match(res.stdout, /add2\.test\.ts/)
})

0 comments on commit 7efc135

Please sign in to comment.