Skip to content

Commit

Permalink
track coverage for borp
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 49726c2 commit 0ff1863
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
21 changes: 14 additions & 7 deletions borp.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ const args = parseArgs({
watch: { type: 'boolean', short: 'w' },
pattern: { type: 'string', short: 'p' },
concurrency: { type: 'string', short: 'c' },
coverage: { type: 'boolean', short: 'C' }
coverage: { type: 'boolean', short: 'C' },
'coverage-exclude': { type: 'string', short: 'X' }
},
allowPositionals: true
})
Expand All @@ -32,7 +33,6 @@ if (args.values.concurrency) {
args.values.concurrency = parseInt(args.values.concurrency)
}


let covDir
if (args.values.coverage) {
covDir = await mkdtemp(join(process.cwd(), 'coverage-'))
Expand All @@ -53,12 +53,19 @@ stream.compose(reporter).pipe(process.stdout)
await finished(stream)

if (covDir) {
const report = Report({
reporter: ['text'],
tempDirectory: covDir
})

try {
let exclude = [
...(args.values['coverage-exclude'] || '').split(',')
].filter(Boolean)
if (exclude.length === 0) {
exclude = undefined
}
const report = Report({
reporter: ['text'],
tempDirectory: covDir,
exclude
})

await report.run()
} catch (err) {
console.error(err)
Expand Down
4 changes: 2 additions & 2 deletions lib/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { glob } from 'glob'
import { findUp } from 'find-up'
import { createRequire } from 'node:module'
import { resolve, join, dirname } from 'node:path'
import { access, readFile, mkdtemp } from 'node:fs/promises'
import { access, readFile } from 'node:fs/promises'
import { execa } from 'execa'

async function isFileAccessible (filename, directory) {
Expand All @@ -17,7 +17,7 @@ async function isFileAccessible (filename, directory) {
}

export default async function runWithTypeScript (config) {
const { cwd, coverage } = config
const { cwd } = config
const tsconfigPath = await findUp('tsconfig.json', { cwd })

let prefix = ''
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"description": "node:test wrapper with TypeScript support",
"main": "borp.js",
"scripts": {
"test": "rm -rf fixtures/*/dist && standard | snazzy && ./borp.js"
"test": "rm -rf fixtures/*/dist && standard | snazzy && ./borp.js --concurrency=1 --coverage --coverage-exclude 'fixtures/**/*,test/**/*'"
},
"keywords": [],
"author": "Matteo Collina <hello@matteocollina.com>",
Expand Down
19 changes: 19 additions & 0 deletions test/coverage.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { test } from 'node:test'
import { match } from 'node:assert'
import { execa } from 'execa'
import { join } from 'desm'

const borp = join(import.meta.url, '..', 'borp.js')

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

match(res.stdout, /% Stmts/)
match(res.stdout, /All files/)
match(res.stdout, /add\.ts/)
})

0 comments on commit 0ff1863

Please sign in to comment.