Comparing version
@@ -23,3 +23,3 @@ import type { Report } from 'c8'; | ||
* | ||
* @default process.cwd | ||
* @defaultValue `process.cwd` | ||
*/ | ||
@@ -34,3 +34,3 @@ cwd?: string | URL | undefined; | ||
* | ||
* @default 'coverage' | ||
* @defaultValue `'coverage'` | ||
*/ | ||
@@ -51,3 +51,3 @@ reportsDirectory?: string | undefined; | ||
* | ||
* @default true | ||
* @defaultValue `true` | ||
*/ | ||
@@ -165,3 +165,3 @@ useC8Config?: boolean | undefined; | ||
* | ||
* @default false | ||
* @defaultValue `false` | ||
*/ | ||
@@ -173,3 +173,3 @@ all?: boolean | undefined; | ||
* | ||
* @default false | ||
* @defaultValue `false` | ||
*/ | ||
@@ -182,3 +182,3 @@ 100?: boolean | undefined; | ||
* | ||
* @default 0 | ||
* @defaultValue `0` | ||
*/ | ||
@@ -190,3 +190,3 @@ branches?: number | undefined; | ||
* | ||
* @default await import('@istanbuljs/schema/default-exclude.js') | ||
* @defaultValue `await import('@istanbuljs/schema/default-exclude.js')` | ||
*/ | ||
@@ -199,3 +199,3 @@ exclude?: string | string[] | undefined; | ||
* | ||
* @default false | ||
* @defaultValue `false` | ||
*/ | ||
@@ -207,3 +207,3 @@ excludeAfterRemap?: boolean; | ||
* | ||
* @default true | ||
* @defaultValue `true` | ||
*/ | ||
@@ -215,3 +215,3 @@ excludeNodeModules?: boolean | undefined; | ||
* | ||
* @default ['.js', '.cjs', '.mjs', '.ts', '.tsx', '.jsx'] | ||
* @defaultValue `['.js', '.cjs', '.mjs', '.ts', '.tsx', '.jsx']` | ||
*/ | ||
@@ -224,3 +224,3 @@ extension?: string | string[] | undefined; | ||
* | ||
* @default 0 | ||
* @defaultValue `0` | ||
*/ | ||
@@ -233,3 +233,3 @@ functions?: number | undefined; | ||
* | ||
* @default [] | ||
* @defaultValue `[]` | ||
*/ | ||
@@ -242,3 +242,3 @@ include?: string | string[] | undefined; | ||
* | ||
* @default 90 | ||
* @defaultValue `90` | ||
*/ | ||
@@ -250,3 +250,3 @@ lines?: number | undefined; | ||
* | ||
* @default false | ||
* @defaultValue `false` | ||
*/ | ||
@@ -266,3 +266,3 @@ perFile?: boolean | undefined; | ||
* | ||
* @default 0 | ||
* @defaultValue `0` | ||
*/ | ||
@@ -331,3 +331,3 @@ statements?: number | undefined; | ||
* | ||
* @default false | ||
* @defaultValue `false` | ||
*/ | ||
@@ -341,3 +341,3 @@ clean?: boolean | undefined; | ||
* | ||
* @default 'utf8' | ||
* @defaultValue `'utf8'` | ||
*/ | ||
@@ -349,3 +349,3 @@ encoding?: BufferEncoding | 'buffer' | null | undefined; | ||
* | ||
* @default process.env | ||
* @defaultValue `process.env` | ||
*/ | ||
@@ -363,3 +363,3 @@ env?: NodeJS.ProcessEnv | undefined; | ||
* | ||
* @default 'SIGTERM' | ||
* @defaultValue `'SIGTERM'` | ||
*/ | ||
@@ -372,3 +372,3 @@ killSignal?: NodeJS.Signals | number | undefined; | ||
* | ||
* @default 1024 * 1024 | ||
* @defaultValue `1024 * 1024` | ||
*/ | ||
@@ -381,3 +381,3 @@ maxBuffer?: number | undefined; | ||
* | ||
* @default false | ||
* @defaultValue `false` | ||
*/ | ||
@@ -408,5 +408,5 @@ silent?: boolean | undefined; | ||
* | ||
* @default 'early' | ||
* @defaultValue `'early'` | ||
*/ | ||
throwExecError?: 'early' | 'late' | 'never' | undefined; | ||
throwExecError?: 'early' | 'late' | 'never' | undefined; | ||
@@ -417,3 +417,3 @@ /** | ||
* | ||
* @default undefined | ||
* @defaultValue `undefined` | ||
*/ | ||
@@ -453,3 +453,3 @@ timeout?: number | undefined; | ||
* | ||
* @default false | ||
* @defaultValue `false` | ||
*/ | ||
@@ -461,3 +461,3 @@ checkCoverage?: boolean | undefined; | ||
* | ||
* @default 'text' | ||
* @defaultValue `'text'` | ||
*/ | ||
@@ -467,6 +467,12 @@ reporter?: string | string[] | undefined; | ||
/** | ||
* An object mapping reporter names to additional options passed directly to the respective | ||
* reporters. | ||
*/ | ||
reporterOptions?: Record<string, Record<string, unknown>>; | ||
/** | ||
* If `true`, files with 100% statement, branch, and function coverage will not be shown by | ||
* the text reporter. | ||
* | ||
* @default false | ||
* @defaultValue `false` | ||
*/ | ||
@@ -473,0 +479,0 @@ skipFull?: boolean | undefined; |
@@ -22,6 +22,10 @@ import { requireAsC8 } from './utils.js'; | ||
createContext({ coverageMap, dir: this.reportsDirectory, watermarks: this.watermarks }); | ||
const options = | ||
const baseOptions = | ||
{ maxCols: 100, projectRoot: this.cwd, skipEmpty: false, skipFull: this.skipFull }; | ||
for (const _reporter of this.reporter) | ||
create(_reporter, options).execute(context); | ||
const { reporterOptions } = this; | ||
for (const reporter of this.reporter) | ||
{ | ||
const options = { ...baseOptions, ...reporterOptions?.[reporter] }; | ||
create(reporter, options).execute(context); | ||
} | ||
} |
@@ -186,3 +186,3 @@ import { spawn } from 'child_process'; | ||
output: [null, stdout, stderr], | ||
pid: child.pid, | ||
pid: child.pid, | ||
stdout, | ||
@@ -189,0 +189,0 @@ stderr, |
@@ -27,2 +27,3 @@ import { requireAsC8 } from './utils.js'; | ||
'reporter', | ||
'reporterOptions', | ||
'resolve', | ||
@@ -65,3 +66,3 @@ 'reportsDirectory', | ||
{ | ||
config: true, | ||
config: true, | ||
configParser(configPath) | ||
@@ -81,3 +82,3 @@ { | ||
}, | ||
default: configPath, | ||
default: configPath, | ||
}, | ||
@@ -84,0 +85,0 @@ ) |
@@ -33,2 +33,3 @@ import parseConfig from './parse-config.js'; | ||
// reporter | ||
reporterOptions: undefined, // { } | ||
skipFull: false, | ||
@@ -35,0 +36,0 @@ watermarks: undefined, |
{ | ||
"name": "c8js", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "A modern, asynchronous Node.js API for c8", | ||
@@ -27,5 +27,6 @@ "keywords": [ | ||
"coverage": "node dev/coverage", | ||
"lint": "eslint . --ignore-path .gitignore --ignore-pattern test/fixtures", | ||
"lint": "eslint . --format compact --ignore-path .gitignore --ignore-pattern test/fixtures", | ||
"make-docs": "node dev/make-docs", | ||
"test": "mocha --check-leaks --timeout=10000 ./test/*.spec.js" | ||
"release": "git add CHANGELOG.md && npm version -f -m 'Version %s'", | ||
"test": "mocha --check-leaks --timeout=10000 test/*.spec.js" | ||
}, | ||
@@ -46,8 +47,2 @@ "dependencies": { | ||
}, | ||
"overrides": { | ||
"c8": { | ||
"foreground-child": "file:../_EXCLUDED_", | ||
"rimraf": "file:../_EXCLUDED_" | ||
} | ||
}, | ||
"engines": { | ||
@@ -54,0 +49,0 @@ "node": ">=14" |
@@ -13,2 +13,4 @@ # c8js | ||
 | ||
## Installation | ||
@@ -22,5 +24,9 @@ | ||
c8js exports the functions `c8js` (the default export), `report`, and `checkCoverage`, in place of the commands `c8`, `c8 report`, and `c8 check-coverage` respectively. | ||
Additionally, c8js exports the function `exec` that just runs a command and saves V8 coverage data. | ||
c8js exports the functions [`c8js`](https://origin-1.github.io/c8js/modules.html#default) (the default export), [`report`](https://origin-1.github.io/c8js/modules.html#report), and [`checkCoverage`](https://origin-1.github.io/c8js/modules.html#checkcoverage), in place of the commands `c8`, `c8 report`, and `c8 check-coverage` respectively. | ||
Additionally, c8js exports the function [`exec`](https://origin-1.github.io/c8js/modules.html#exec) that just runs a command and saves V8 coverage data. | ||
While c8 commands accept inline arguments, c8js functions accept in-code options. | ||
All [c8js options](https://origin-1.github.io/c8js/interfaces/default.Options.html) can be used in-code with all functions, but some options are only relevant to some of the functions. | ||
In-code options override options defined in .c8rc or another configuration file. | ||
An important difference is that all c8js functions throw exceptions in situations where c8 commands would terminate the process with a nonzero exit code. | ||
@@ -92,2 +98,43 @@ | ||
**NOTE:** Some versions of Node.js contain [a bug](https://github.com/nodejs/node/issues/45013) that causes `node --test` to crash when run from c8. | ||
The affected Node.js versions are 18.11.0, 18.12.0, 18.12.1, 19.0.0 and 19.0.1. | ||
### Sharing Options | ||
To use c8js in different build scripts or packages with similar settings, it is useful to export a function that calls c8js with the set of shared options. | ||
This function can be imported by each build script and invoked with specific parameters. | ||
```js | ||
// create-coverage.js | ||
export async function createCoverage(options) | ||
{ | ||
const { default: c8js, commands } = await import('c8js'); | ||
await c8js | ||
( | ||
commands.npm, | ||
['test'], | ||
{ | ||
all: true, | ||
src: 'lib', | ||
throwExecError: 'late', | ||
watermarks: | ||
{ | ||
branches: [90, 100], | ||
functions: [90, 100], | ||
lines: [90, 100], | ||
statements: [90, 100], | ||
}, | ||
...options, | ||
} | ||
); | ||
} | ||
``` | ||
```js | ||
// build.js | ||
import { createCoverage } from './create-coverage.js'; | ||
await createCoverage({ src: ['lib', 'src/app'], timeout: 300 * 1000 }); | ||
``` | ||
## Compatibility | ||
@@ -94,0 +141,0 @@ |
46035
5.52%1192
0.93%143
48.96%