borp 0.21.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +7 -0
- package/.github/workflows/ci.yml +1 -4
- package/README.md +79 -60
- package/borp.js +34 -27
- package/fixtures/conf/cov-html.yaml +2 -0
- package/fixtures/only-src/src/add.test.ts +1 -1
- package/fixtures/only-src/src/add2.test.ts +1 -1
- package/fixtures/ts-esm/test/add.test.ts +1 -1
- package/fixtures/ts-esm/test/add2.test.ts +1 -1
- package/fixtures/ts-esm-check-coverage/test/add.test.ts +1 -1
- package/fixtures/ts-esm2/test/add.test.ts +1 -1
- package/fixtures/ts-esm2/test/add2.test.ts +1 -1
- package/lib/conf.js +4 -0
- package/lib/run.js +18 -214
- package/package.json +5 -2
- package/test/basic.test.js +40 -145
- package/test/cli-help.test.js +2 -0
- package/test/cli.test.js +4 -43
- package/test/config.test.js +13 -0
- package/test/coverage.test.js +25 -0
- package/test/watch.test.js +19 -105
- package/fixtures/monorepo/package-lock.json +0 -35
- package/fixtures/monorepo/package.json +0 -15
- package/fixtures/monorepo/package1/package.json +0 -13
- package/fixtures/monorepo/package1/src/lib/add.ts +0 -3
- package/fixtures/monorepo/package1/src/test/add.test.ts +0 -7
- package/fixtures/monorepo/package1/src/test/add2.test.ts +0 -7
- package/fixtures/monorepo/package1/tsconfig.json +0 -10
- package/fixtures/monorepo/package2/package.json +0 -15
- package/fixtures/monorepo/package2/src/lib/add.ts +0 -4
- package/fixtures/monorepo/package2/src/test/add.test.ts +0 -7
- package/fixtures/monorepo/package2/src/test/add2.test.ts +0 -7
- package/fixtures/monorepo/package2/tsconfig.json +0 -11
- package/fixtures/monorepo/tsconfig.base.json +0 -24
- package/fixtures/monorepo/tsconfig.json +0 -7
- package/fixtures/src-to-dist/src/lib/add.ts +0 -3
- package/fixtures/src-to-dist/src/test/add.test.ts +0 -7
- package/fixtures/src-to-dist/src/test/add2.test.ts +0 -7
- package/fixtures/src-to-dist/tsconfig.json +0 -24
- package/fixtures/ts-cjs/package.json +0 -3
- package/fixtures/ts-cjs/src/add.ts +0 -3
- package/fixtures/ts-cjs/test/add.test.ts +0 -7
- package/fixtures/ts-cjs/test/add2.test.ts +0 -7
- package/fixtures/ts-cjs/tsconfig.json +0 -24
- package/fixtures/ts-cjs-post-compile/package.json +0 -3
- package/fixtures/ts-cjs-post-compile/postCompile.ts +0 -1
- package/fixtures/ts-cjs-post-compile/src/add.ts +0 -3
- package/fixtures/ts-cjs-post-compile/test/add.test.ts +0 -7
- package/fixtures/ts-cjs-post-compile/test/add2.test.ts +0 -7
- package/fixtures/ts-cjs-post-compile/tsconfig.json +0 -24
- package/fixtures/ts-esm-post-compile/postCompile.ts +0 -1
- package/fixtures/ts-esm-post-compile/src/add.ts +0 -3
- package/fixtures/ts-esm-post-compile/test/add.test.ts +0 -7
- package/fixtures/ts-esm-post-compile/test/add2.test.ts +0 -7
- package/fixtures/ts-esm-post-compile/tsconfig.json +0 -24
- package/fixtures/ts-esm-source-map/src/add.ts +0 -3
- package/fixtures/ts-esm-source-map/test/add.test.ts +0 -7
- package/fixtures/ts-esm-source-map/tsconfig.json +0 -24
- package/test/sourceMap.test.js +0 -87
package/.github/workflows/ci.yml
CHANGED
|
@@ -16,11 +16,8 @@ jobs:
|
|
|
16
16
|
|
|
17
17
|
strategy:
|
|
18
18
|
matrix:
|
|
19
|
-
node-version: [
|
|
19
|
+
node-version: [22.x, 24.x, 25.x]
|
|
20
20
|
os: [ubuntu-latest, windows-latest]
|
|
21
|
-
exclude:
|
|
22
|
-
- os: windows-latest
|
|
23
|
-
node-version: 21.x
|
|
24
21
|
steps:
|
|
25
22
|
- uses: actions/checkout@v4
|
|
26
23
|
|
package/README.md
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
# borp
|
|
2
2
|
|
|
3
|
-
Borp is a
|
|
4
|
-
|
|
3
|
+
Borp is a TypeScript-aware test runner for `node:test` with built-in code coverage support via [c8](https://npm.im/c8).
|
|
4
|
+
|
|
5
|
+
Borp uses Node.js native [type stripping](https://nodejs.org/api/typescript.html) to run TypeScript files directly without compilation. No build step required!
|
|
5
6
|
|
|
6
7
|
Borp is self-hosted, i.e. Borp runs its own tests.
|
|
7
8
|
|
|
9
|
+
## Requirements
|
|
10
|
+
|
|
11
|
+
- Node.js >= 22.6.0 (22.19.0+ or 24.x+ recommended for best TypeScript support)
|
|
12
|
+
|
|
8
13
|
## Install
|
|
9
14
|
|
|
10
15
|
```bash
|
|
@@ -14,40 +19,47 @@ npm i borp --save-dev
|
|
|
14
19
|
## Usage
|
|
15
20
|
|
|
16
21
|
```bash
|
|
22
|
+
# Run all tests
|
|
23
|
+
borp
|
|
24
|
+
|
|
25
|
+
# With code coverage
|
|
17
26
|
borp --coverage
|
|
18
27
|
|
|
19
|
-
#
|
|
28
|
+
# With coverage threshold checking
|
|
20
29
|
borp --coverage --check-coverage --lines 95
|
|
21
30
|
|
|
22
|
-
#
|
|
31
|
+
# With a node_modules located reporter
|
|
23
32
|
borp --reporter foo
|
|
24
33
|
|
|
25
|
-
#
|
|
34
|
+
# With a node_modules located reporter writing to stderr
|
|
26
35
|
borp --reporter foo:stderr
|
|
27
36
|
|
|
28
|
-
#
|
|
37
|
+
# With a local custom reporter
|
|
29
38
|
borp --reporter ./lib/some-reporter.mjs
|
|
30
39
|
|
|
31
|
-
#
|
|
40
|
+
# Matching all test.js files except ones in nested node_modules directories
|
|
32
41
|
borp 'test/**/*.test.js' '!test/**/node_modules/**/*.test.js'
|
|
33
42
|
```
|
|
34
43
|
|
|
35
|
-
Borp will automatically run all
|
|
44
|
+
Borp will automatically run all test files matching `*.test.{js|ts|mts|cts}`.
|
|
45
|
+
|
|
46
|
+
## TypeScript Support
|
|
47
|
+
|
|
48
|
+
Borp uses Node.js native type stripping to run TypeScript files directly. No compilation step is required!
|
|
36
49
|
|
|
37
50
|
### Example project setup
|
|
38
51
|
|
|
39
52
|
```
|
|
40
53
|
.
|
|
41
54
|
├── src
|
|
42
|
-
│
|
|
43
|
-
│
|
|
44
|
-
│
|
|
45
|
-
│
|
|
46
|
-
└──
|
|
47
|
-
|
|
55
|
+
│ ├── lib
|
|
56
|
+
│ │ └── math.ts
|
|
57
|
+
│ └── test
|
|
58
|
+
│ └── math.test.ts
|
|
59
|
+
└── package.json
|
|
48
60
|
```
|
|
49
61
|
|
|
50
|
-
As an example, consider having a `src/lib/math.ts` file
|
|
62
|
+
As an example, consider having a `src/lib/math.ts` file:
|
|
51
63
|
|
|
52
64
|
```typescript
|
|
53
65
|
export function math (x: number, y: number): number {
|
|
@@ -59,7 +71,7 @@ and a `src/test/math.test.ts` file:
|
|
|
59
71
|
|
|
60
72
|
```typescript
|
|
61
73
|
import { test } from 'node:test'
|
|
62
|
-
import { math } from '../lib/math.
|
|
74
|
+
import { math } from '../lib/math.ts'
|
|
63
75
|
import { strictEqual } from 'node:assert'
|
|
64
76
|
|
|
65
77
|
test('math', () => {
|
|
@@ -67,43 +79,51 @@ test('math', () => {
|
|
|
67
79
|
})
|
|
68
80
|
```
|
|
69
81
|
|
|
70
|
-
|
|
82
|
+
Note: Use `.ts` extensions in your imports, not `.js`!
|
|
83
|
+
|
|
84
|
+
### TypeScript Constraints
|
|
85
|
+
|
|
86
|
+
Type stripping has some limitations compared to full TypeScript compilation. Your code must follow these rules:
|
|
87
|
+
|
|
88
|
+
- **Use type-only imports**: Use `import type { Foo }` or `import { type Foo }` for type imports
|
|
89
|
+
- **No enums**: Use const objects with `as const` instead
|
|
90
|
+
- **No namespaces**: Use regular modules instead
|
|
91
|
+
- **No parameter properties**: Explicitly declare class properties in the constructor body
|
|
92
|
+
- **File extensions**: Import `.ts` files with `.ts` extension
|
|
93
|
+
|
|
94
|
+
See the [Node.js TypeScript documentation](https://nodejs.org/api/typescript.html) for full details.
|
|
95
|
+
|
|
96
|
+
### Optional tsconfig.json
|
|
97
|
+
|
|
98
|
+
A `tsconfig.json` is not required for borp to work, but you can include one for IDE support and type checking:
|
|
71
99
|
|
|
72
100
|
```json
|
|
73
101
|
{
|
|
74
|
-
"$schema": "https://json.schemastore.org/tsconfig",
|
|
75
102
|
"compilerOptions": {
|
|
76
|
-
"outDir": "dist",
|
|
77
|
-
"sourceMap": true,
|
|
78
103
|
"target": "ES2022",
|
|
79
104
|
"module": "NodeNext",
|
|
80
105
|
"moduleResolution": "NodeNext",
|
|
81
|
-
"esModuleInterop": true,
|
|
82
106
|
"strict": true,
|
|
83
|
-
"
|
|
84
|
-
"
|
|
85
|
-
"
|
|
86
|
-
"noUnusedLocals": true,
|
|
87
|
-
"noFallthroughCasesInSwitch": true,
|
|
107
|
+
"noEmit": true,
|
|
108
|
+
"allowImportingTsExtensions": true,
|
|
109
|
+
"verbatimModuleSyntax": true,
|
|
88
110
|
"isolatedModules": true,
|
|
89
|
-
"
|
|
90
|
-
"skipLibCheck": true,
|
|
91
|
-
"lib": [
|
|
92
|
-
"ESNext"
|
|
93
|
-
],
|
|
94
|
-
"incremental": true
|
|
111
|
+
"skipLibCheck": true
|
|
95
112
|
}
|
|
96
113
|
}
|
|
97
114
|
```
|
|
98
115
|
|
|
99
|
-
|
|
116
|
+
Key options:
|
|
117
|
+
- `noEmit: true` - No compilation output needed
|
|
118
|
+
- `allowImportingTsExtensions: true` - Allow `.ts` imports
|
|
119
|
+
- `verbatimModuleSyntax: true` - Enforce type-only imports
|
|
100
120
|
|
|
101
121
|
## Options
|
|
102
122
|
|
|
103
123
|
* `--concurrency` or `-c`, to set the number of concurrent tests. Defaults to the number of available CPUs minus one.
|
|
104
124
|
* `--coverage` or `-C`, enables code coverage
|
|
105
|
-
* `--only` or `-o`, only run `node:test` with the `only` option set
|
|
106
|
-
* `--watch` or `-w`, re-run tests on changes
|
|
125
|
+
* `--only` or `-o`, only run `node:test` with the `only` option set
|
|
126
|
+
* `--watch` or `-w`, re-run tests on file changes using Node.js native watch mode
|
|
107
127
|
* `--timeout` or `-t`, timeouts the tests after a given time; default is 30000 ms
|
|
108
128
|
* `--no-timeout`, disables the timeout
|
|
109
129
|
* `--coverage-exclude` or `-X`, a list of comma-separated patterns to exclude from the coverage report. All tests files are ignored by default.
|
|
@@ -111,14 +131,16 @@ Note the use of `incremental: true`, which speed up compilation massively.
|
|
|
111
131
|
* `--expose-gc`, exposes the gc() function to tests
|
|
112
132
|
* `--pattern` or `-p`, run tests matching the given glob pattern
|
|
113
133
|
* `--reporter` or `-r`, set up a reporter, use a colon to set a file destination. Reporter may either be a module name resolvable by standard `node_modules` resolution, or a path to a script relative to the process working directory (must be an ESM script). Default: `spec`.
|
|
114
|
-
* `--no-typescript` or `-T`, disable automatic TypeScript compilation if `tsconfig.json` is found.
|
|
115
|
-
* `--post-compile` or `-P`, the path to a file that will be executed after each typescript compilation.
|
|
116
134
|
* `--check-coverage`, enables c8 check coverage; default is false
|
|
135
|
+
* `--coverage-html`, generates c8 html report; default is false
|
|
136
|
+
|
|
117
137
|
### Check coverage options
|
|
138
|
+
|
|
118
139
|
* `--lines`, set the lines threshold when check coverage is active; default is 100
|
|
119
140
|
* `--functions`, set the functions threshold when check coverage is active; default is 100
|
|
120
141
|
* `--statements`, set the statements threshold when check coverage is active; default is 100
|
|
121
142
|
* `--branches`, set the branches threshold when check coverage is active; default is 100
|
|
143
|
+
|
|
122
144
|
## Reporters
|
|
123
145
|
|
|
124
146
|
Here are the available reporters:
|
|
@@ -131,32 +153,19 @@ Here are the available reporters:
|
|
|
131
153
|
|
|
132
154
|
## Config File Support
|
|
133
155
|
|
|
134
|
-
A limited set of options may be specified via a configuration file. The
|
|
135
|
-
configuration file is expected to be in the process's working directory, and
|
|
136
|
-
named either `.borp.yaml` or `.borp.yml`; it may also be specified by
|
|
137
|
-
defining the environment variable `BORP_CONF_FILE` and setting it to the
|
|
138
|
-
full path to some yaml file.
|
|
156
|
+
A limited set of options may be specified via a configuration file. The configuration file is expected to be in the process's working directory, and named either `.borp.yaml` or `.borp.yml`; it may also be specified by defining the environment variable `BORP_CONF_FILE` and setting it to the full path to some yaml file.
|
|
139
157
|
|
|
140
158
|
The current supported options are:
|
|
141
159
|
|
|
142
|
-
+ `coverage` (object): A hash of options relating to test coverage. By defining
|
|
143
|
-
|
|
144
|
-
- `
|
|
145
|
-
|
|
146
|
-
- `
|
|
147
|
-
|
|
148
|
-
- `
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
lines. Default: 100.
|
|
152
|
-
- `statements` (number): Define the percentage of acceptable coverage for
|
|
153
|
-
statements. Default: 100.
|
|
154
|
-
+ `files` (string[]): An array of test files to include. Globs are supported.
|
|
155
|
-
Note: any glob that starts with a `!` (bang character) will be treated as
|
|
156
|
-
an ignore glob, e.g. `'!test/**/node_modules/**/*'` will ignore all files
|
|
157
|
-
in nested `node_modules` directories that would otherwise be matched.
|
|
158
|
-
+ `reporters` (string[]): An array of reporters to use. May be relative path
|
|
159
|
-
strings, or module name strings.
|
|
160
|
+
+ `coverage` (object): A hash of options relating to test coverage. By defining this configuration object, coverage reporting will be enabled.
|
|
161
|
+
- `check-coverage` (boolean): Set to `true` to enable coverage checking. Omit to disable coverage checking.
|
|
162
|
+
- `coverage-html` (boolean): Set to `true` to generate an HTML coverage report.
|
|
163
|
+
- `branches` (number): Define the percentage of acceptable coverage for branches. Default: 100.
|
|
164
|
+
- `functions` (number): Define the percentage of acceptable coverage for functions. Default: 100.
|
|
165
|
+
- `lines` (number): Define the percentage of acceptable coverage for lines. Default: 100.
|
|
166
|
+
- `statements` (number): Define the percentage of acceptable coverage for statements. Default: 100.
|
|
167
|
+
+ `files` (string[]): An array of test files to include. Globs are supported. Note: any glob that starts with a `!` (bang character) will be treated as an ignore glob, e.g. `'!test/**/node_modules/**/*'` will ignore all files in nested `node_modules` directories that would otherwise be matched.
|
|
168
|
+
+ `reporters` (string[]): An array of reporters to use. May be relative path strings, or module name strings.
|
|
160
169
|
|
|
161
170
|
### Example
|
|
162
171
|
|
|
@@ -178,6 +187,16 @@ reporters:
|
|
|
178
187
|
- '@reporters/silent'
|
|
179
188
|
```
|
|
180
189
|
|
|
190
|
+
## Migration from borp < 1.0
|
|
191
|
+
|
|
192
|
+
If you're upgrading from an older version of borp, here are the key changes:
|
|
193
|
+
|
|
194
|
+
1. **No compilation step**: Tests run directly from source files
|
|
195
|
+
2. **Import extensions**: Change `.js` to `.ts` in your TypeScript imports
|
|
196
|
+
3. **No outDir**: Remove `outDir` from tsconfig or set to your source directory
|
|
197
|
+
4. **Removed options**: `--no-typescript` and `--post-compile` are removed
|
|
198
|
+
5. **Type constraints**: See TypeScript Constraints section above
|
|
199
|
+
|
|
181
200
|
## License
|
|
182
201
|
|
|
183
202
|
MIT
|
package/borp.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
#! /usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import { parseArgs } from 'node:util'
|
|
4
|
+
import runTests from './lib/run.js'
|
|
4
5
|
import Reporters from 'node:test/reporters'
|
|
5
6
|
import { findUp } from 'find-up'
|
|
6
7
|
import { mkdtemp, rm, readFile } from 'node:fs/promises'
|
|
7
8
|
import { createWriteStream } from 'node:fs'
|
|
8
9
|
import { finished } from 'node:stream/promises'
|
|
9
|
-
import { join,
|
|
10
|
-
import posix from 'node:path/posix'
|
|
11
|
-
import runWithTypeScript from './lib/run.js'
|
|
10
|
+
import { join, resolve } from 'node:path'
|
|
12
11
|
import githubReporter from '@reporters/github'
|
|
13
12
|
import { Report } from 'c8'
|
|
14
13
|
import { checkCoverages } from 'c8/lib/commands/check-coverage.js'
|
|
@@ -17,6 +16,10 @@ import { execa } from 'execa'
|
|
|
17
16
|
import { pathToFileURL } from 'node:url'
|
|
18
17
|
import loadConfig from './lib/conf.js'
|
|
19
18
|
|
|
19
|
+
// This is a hack to override
|
|
20
|
+
// https://github.com/nodejs/node/commit/d5c9adf3df
|
|
21
|
+
delete process.env.NODE_TEST_CONTEXT
|
|
22
|
+
|
|
20
23
|
/* c8 ignore next 4 */
|
|
21
24
|
process.on('unhandledRejection', (err) => {
|
|
22
25
|
console.error(err)
|
|
@@ -38,10 +41,9 @@ Options:
|
|
|
38
41
|
-X, --coverage-exclude Exclude patterns from coverage (can be used multiple times)
|
|
39
42
|
-i, --ignore <pattern> Ignore glob pattern (can be used multiple times)
|
|
40
43
|
--expose-gc Expose the gc() function to tests
|
|
41
|
-
-T, --no-typescript Disable automatic TypeScript compilation
|
|
42
|
-
-P, --post-compile <file> Execute file after TypeScript compilation
|
|
43
44
|
-r, --reporter <name> Set reporter (can be used multiple times, default: spec)
|
|
44
45
|
--check-coverage Enable coverage threshold checking
|
|
46
|
+
--coverage-html Generate HTML coverage report
|
|
45
47
|
--lines <threshold> Set lines coverage threshold (default: 100)
|
|
46
48
|
--branches <threshold> Set branches coverage threshold (default: 100)
|
|
47
49
|
--functions <threshold> Set functions coverage threshold (default: 100)
|
|
@@ -73,8 +75,6 @@ const optionsConfig = {
|
|
|
73
75
|
ignore: { type: 'string', short: 'i', multiple: true },
|
|
74
76
|
'expose-gc': { type: 'boolean' },
|
|
75
77
|
help: { type: 'boolean', short: 'h' },
|
|
76
|
-
'no-typescript': { type: 'boolean', short: 'T' },
|
|
77
|
-
'post-compile': { type: 'string', short: 'P' },
|
|
78
78
|
reporter: {
|
|
79
79
|
type: 'string',
|
|
80
80
|
short: 'r',
|
|
@@ -82,6 +82,7 @@ const optionsConfig = {
|
|
|
82
82
|
multiple: true
|
|
83
83
|
},
|
|
84
84
|
'check-coverage': { type: 'boolean' },
|
|
85
|
+
'coverage-html': { type: 'boolean' },
|
|
85
86
|
lines: { type: 'string', default: '100' },
|
|
86
87
|
branches: { type: 'string', default: '100' },
|
|
87
88
|
functions: { type: 'string', default: '100' },
|
|
@@ -116,16 +117,16 @@ if (args.values.help) {
|
|
|
116
117
|
|
|
117
118
|
/* c8 ignore next 20 */
|
|
118
119
|
if (args.values['expose-gc'] && typeof global.gc !== 'function') {
|
|
119
|
-
const
|
|
120
|
+
const spawnArgs = [...process.argv.slice(1)]
|
|
120
121
|
const nodeVersion = process.version.split('.').map((v) => parseInt(v.replace('v', '')))[0]
|
|
121
122
|
if (nodeVersion >= 24) {
|
|
122
123
|
process.env.NODE_OPTIONS = (process.env.NODE_OPTIONS ? process.env.NODE_OPTIONS + ' ' : '') + '--expose-gc'
|
|
123
124
|
} else {
|
|
124
|
-
|
|
125
|
+
spawnArgs.unshift('--expose-gc')
|
|
125
126
|
}
|
|
126
127
|
|
|
127
128
|
try {
|
|
128
|
-
await execa('node',
|
|
129
|
+
await execa('node', spawnArgs, {
|
|
129
130
|
stdio: 'inherit',
|
|
130
131
|
env: {
|
|
131
132
|
...process.env
|
|
@@ -155,14 +156,6 @@ if (args.values.coverage) {
|
|
|
155
156
|
process.env.NODE_V8_COVERAGE = covDir
|
|
156
157
|
}
|
|
157
158
|
|
|
158
|
-
const config = {
|
|
159
|
-
...args.values,
|
|
160
|
-
typescript: !args.values['no-typescript'],
|
|
161
|
-
files: args.positionals,
|
|
162
|
-
pattern: args.values.pattern,
|
|
163
|
-
cwd: process.cwd()
|
|
164
|
-
}
|
|
165
|
-
|
|
166
159
|
try {
|
|
167
160
|
const pipes = []
|
|
168
161
|
|
|
@@ -205,7 +198,14 @@ try {
|
|
|
205
198
|
pipes.push([reporter, output])
|
|
206
199
|
}
|
|
207
200
|
|
|
208
|
-
const
|
|
201
|
+
const config = {
|
|
202
|
+
...args.values,
|
|
203
|
+
files: args.positionals,
|
|
204
|
+
pattern: args.values.pattern,
|
|
205
|
+
cwd: process.cwd()
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const stream = await runTests(config)
|
|
209
209
|
|
|
210
210
|
stream.on('test:fail', () => {
|
|
211
211
|
process.exitCode = 1
|
|
@@ -218,18 +218,25 @@ try {
|
|
|
218
218
|
await finished(stream)
|
|
219
219
|
|
|
220
220
|
if (covDir) {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
if (exclude && config.prefix) {
|
|
224
|
-
const localPrefix = relative(process.cwd(), config.prefix)
|
|
225
|
-
exclude = exclude.map((file) => posix.join(localPrefix, file))
|
|
226
|
-
}
|
|
221
|
+
const exclude = args.values['coverage-exclude']
|
|
227
222
|
const nycrc = await findUp(['.c8rc', '.c8rc.json', '.nycrc', '.nycrc.json'], { cwd: config.cwd })
|
|
223
|
+
const nycrcConfig = nycrc ? JSON.parse(await readFile(nycrc, 'utf8')) : {}
|
|
224
|
+
const configuredReporters = Array.isArray(nycrcConfig.reporter)
|
|
225
|
+
? nycrcConfig.reporter
|
|
226
|
+
: typeof nycrcConfig.reporter === 'string' && nycrcConfig.reporter.length > 0
|
|
227
|
+
? [nycrcConfig.reporter]
|
|
228
|
+
: ['text']
|
|
229
|
+
|
|
230
|
+
const coverageReporters = args.values['coverage-html']
|
|
231
|
+
? Array.from(new Set([...configuredReporters, 'html']))
|
|
232
|
+
: configuredReporters
|
|
233
|
+
|
|
234
|
+
delete nycrcConfig.reporter
|
|
228
235
|
const report = Report({
|
|
229
|
-
reporter:
|
|
236
|
+
reporter: coverageReporters,
|
|
230
237
|
tempDirectory: covDir,
|
|
231
238
|
exclude,
|
|
232
|
-
...
|
|
239
|
+
...nycrcConfig
|
|
233
240
|
})
|
|
234
241
|
|
|
235
242
|
if (args.values['check-coverage']) {
|
package/lib/conf.js
CHANGED
|
@@ -67,6 +67,10 @@ async function loadConfig () {
|
|
|
67
67
|
result.push('--check-coverage')
|
|
68
68
|
continue
|
|
69
69
|
}
|
|
70
|
+
if (option === 'coverage-html' && value === true) {
|
|
71
|
+
result.push('--coverage-html')
|
|
72
|
+
continue
|
|
73
|
+
}
|
|
70
74
|
if (allowed.includes(option) === false) continue
|
|
71
75
|
if (isNaN(parseInt(value, 10)) === true) continue
|
|
72
76
|
result.push(`--${option}=${value}`)
|