c8 7.7.2 → 7.10.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/CHANGELOG.md +28 -0
- package/README.md +46 -2
- package/lib/commands/check-coverage.js +8 -0
- package/lib/commands/report.js +10 -1
- package/lib/parse-args.js +71 -30
- package/lib/report.js +4 -2
- package/package.json +6 -5
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,34 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [7.10.0](https://www.github.com/bcoe/c8/compare/v7.9.0...v7.10.0) (2021-10-06)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* `--100` ([#332](https://www.github.com/bcoe/c8/issues/332)) ([4205f2f](https://www.github.com/bcoe/c8/commit/4205f2f33585693d82c2500d0d6850571965bb8b))
|
|
11
|
+
|
|
12
|
+
## [7.9.0](https://www.github.com/bcoe/c8/compare/v7.8.0...v7.9.0) (2021-09-10)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
* add --exclude-node-modules option ([#321](https://www.github.com/bcoe/c8/issues/321)) ([a4733c6](https://www.github.com/bcoe/c8/commit/a4733c68abd778757bb6ed641e074be94b79c417))
|
|
18
|
+
|
|
19
|
+
## [7.8.0](https://www.github.com/bcoe/c8/compare/v7.7.3...v7.8.0) (2021-07-10)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Features
|
|
23
|
+
|
|
24
|
+
* add --config option and documentation on options and configs ([#308](https://www.github.com/bcoe/c8/issues/308)) ([99436ef](https://www.github.com/bcoe/c8/commit/99436ef131c2ab966174b5012fe22e499fb44ccd))
|
|
25
|
+
|
|
26
|
+
### [7.7.3](https://www.github.com/bcoe/c8/compare/v7.7.2...v7.7.3) (2021-06-03)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
### Bug Fixes
|
|
30
|
+
|
|
31
|
+
* **deps:** v8-to-istanbul with fix for Windows paths ([#311](https://www.github.com/bcoe/c8/issues/311)) ([ef1b875](https://www.github.com/bcoe/c8/commit/ef1b8757f5f9c664cf63cfce753e93b92057cab5))
|
|
32
|
+
|
|
5
33
|
### [7.7.2](https://www.github.com/bcoe/c8/compare/v7.7.1...v7.7.2) (2021-05-02)
|
|
6
34
|
|
|
7
35
|
|
package/README.md
CHANGED
|
@@ -16,6 +16,31 @@ c8 node foo.js
|
|
|
16
16
|
|
|
17
17
|
The above example will output coverage metrics for `foo.js`.
|
|
18
18
|
|
|
19
|
+
## CLI Options / Configuration
|
|
20
|
+
|
|
21
|
+
c8 can be configured via command-line flags, a `c8` section in `package.json`, or a JSON configuration file on disk.
|
|
22
|
+
|
|
23
|
+
A configuration file can be specified by passing its path on the command line with `--config` or `-c`. If no config option is provided, c8 searches for files named `.c8rc`, `.c8rc.json`, `.nycrc`, or `.nycrc.json`, starting from
|
|
24
|
+
`cwd` and walking up the filesystem tree.
|
|
25
|
+
|
|
26
|
+
When using `package.json` configuration or a dedicated configuration file, omit the `--` prefix from the long-form of the desired command-line option.
|
|
27
|
+
|
|
28
|
+
Here is a list of common options. Run `c8 --help` for the full list and documentation.
|
|
29
|
+
|
|
30
|
+
| Option | Description | Type | Default |
|
|
31
|
+
| ------ | ----------- | ---- | ------- |
|
|
32
|
+
| `-c`, `--config` | path to JSON configuration file | `string` | See above |
|
|
33
|
+
| `-r`, `--reporter` | coverage reporter(s) to use | `Array<string>` | `['text']` |
|
|
34
|
+
| `-o`, `--reports-dir`, `--report-dir` | directory where coverage reports will be output to | `string` | `./coverage` |
|
|
35
|
+
| `--all` | see [section below](#checking-for-full-source-coverage-using---all) for more info | `boolean` | `false` |
|
|
36
|
+
| `--src` | see [section below](#checking-for-full-source-coverage-using---all) for more info | `Array<string>` | `[process.cwd()]`|
|
|
37
|
+
| `-n`, `--include` | see [section below](#checking-for-full-source-coverage-using---all) for more info | `Array<string>` | `[]` (include all files) |
|
|
38
|
+
| `-x`, `--exclude` | see [section below](#checking-for-full-source-coverage-using---all) for more info | `Array<string>` | [list](https://github.com/istanbuljs/schema/blob/main/default-exclude.js) |
|
|
39
|
+
| `--skip-full` | do not show files with 100% statement, branch, and function coverage | `boolean` | `false` |
|
|
40
|
+
| `--check-coverage` | check whether coverage is within thresholds provided | `boolean` | `false` |
|
|
41
|
+
| `--temp-directory` | directory V8 coverage data is written to and read from | `string` | `process.env.NODE_V8_COVERAGE` |
|
|
42
|
+
| `--clean` | should temp files be deleted before script execution | `boolean` | `true` |
|
|
43
|
+
|
|
19
44
|
## Checking for "full" source coverage using `--all`
|
|
20
45
|
|
|
21
46
|
By default v8 will only give us coverage for files that were loaded by the engine. If there are source files in your
|
|
@@ -23,8 +48,9 @@ project that are flexed in production but not in your tests, your coverage numbe
|
|
|
23
48
|
if your project's `main.js` loads `a.js` and `b.js` but your unit tests only load `a.js` your total coverage
|
|
24
49
|
could show as `100%` for `a.js` when in fact both `main.js` and `b.js` are uncovered.
|
|
25
50
|
|
|
26
|
-
By supplying `--all` to c8, all files in `cwd` that pass the `--include`
|
|
27
|
-
report. If any of those files remain uncovered they will be factored
|
|
51
|
+
By supplying `--all` to c8, all files in directories specified with `--src` (defaults to `cwd`) that pass the `--include`
|
|
52
|
+
and `--exclude` flag checks, will be loaded into the report. If any of those files remain uncovered they will be factored
|
|
53
|
+
into the report with a default of 0% coverage.
|
|
28
54
|
|
|
29
55
|
## c8 report
|
|
30
56
|
|
|
@@ -54,6 +80,24 @@ To check thresholds on a per-file basis run:
|
|
|
54
80
|
c8 check-coverage --lines 95 --per-file
|
|
55
81
|
```
|
|
56
82
|
|
|
83
|
+
If you want to check for 100% coverage across all dimensions, use `--100`:
|
|
84
|
+
|
|
85
|
+
```shell
|
|
86
|
+
c8 --100 npm test
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Is equivalent to
|
|
90
|
+
|
|
91
|
+
```shell
|
|
92
|
+
c8 --check-coverage --lines 100 --functions 100 --branches 100 --statements 100 npm test
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
The `--100` flag can be set for the `check-coverage` as well:
|
|
96
|
+
|
|
97
|
+
```shell
|
|
98
|
+
c8 check-coverage --100
|
|
99
|
+
```
|
|
100
|
+
|
|
57
101
|
## Ignoring Uncovered Lines, Functions, and Blocks
|
|
58
102
|
|
|
59
103
|
Sometimes you might find yourself wanting to ignore uncovered portions of your
|
|
@@ -11,6 +11,14 @@ exports.builder = function (yargs) {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
exports.handler = function (argv) {
|
|
14
|
+
// TODO: this is a workaround until yargs gets upgraded to v17, see https://github.com/bcoe/c8/pull/332#discussion_r721636191
|
|
15
|
+
if (argv['100']) {
|
|
16
|
+
argv.lines = 100
|
|
17
|
+
argv.functions = 100
|
|
18
|
+
argv.branches = 100
|
|
19
|
+
argv.statements = 100
|
|
20
|
+
}
|
|
21
|
+
|
|
14
22
|
const report = Report({
|
|
15
23
|
include: argv.include,
|
|
16
24
|
exclude: argv.exclude,
|
package/lib/commands/report.js
CHANGED
|
@@ -10,6 +10,14 @@ exports.handler = async function (argv) {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
exports.outputReport = async function (argv) {
|
|
13
|
+
// TODO: this is a workaround until yargs gets upgraded to v17, see https://github.com/bcoe/c8/pull/332#discussion_r721636191
|
|
14
|
+
if (argv['100']) {
|
|
15
|
+
argv.checkCoverage = 100
|
|
16
|
+
argv.lines = 100
|
|
17
|
+
argv.functions = 100
|
|
18
|
+
argv.branches = 100
|
|
19
|
+
argv.statements = 100
|
|
20
|
+
}
|
|
13
21
|
const report = Report({
|
|
14
22
|
include: argv.include,
|
|
15
23
|
exclude: argv.exclude,
|
|
@@ -24,7 +32,8 @@ exports.outputReport = async function (argv) {
|
|
|
24
32
|
all: argv.all,
|
|
25
33
|
allowExternal: argv.allowExternal,
|
|
26
34
|
src: argv.src,
|
|
27
|
-
skipFull: argv.skipFull
|
|
35
|
+
skipFull: argv.skipFull,
|
|
36
|
+
excludeNodeModules: argv.excludeNodeModules
|
|
28
37
|
})
|
|
29
38
|
await report.run()
|
|
30
39
|
if (argv.checkCoverage) await checkCoverages(argv, report)
|
package/lib/parse-args.js
CHANGED
|
@@ -5,72 +5,123 @@ const Yargs = require('yargs/yargs')
|
|
|
5
5
|
const parser = require('yargs-parser')
|
|
6
6
|
const { resolve } = require('path')
|
|
7
7
|
|
|
8
|
-
const configPath = findUp.sync(['.c8rc', '.c8rc.json', '.nycrc', '.nycrc.json'])
|
|
9
|
-
const config = configPath ? JSON.parse(readFileSync(configPath)) : {}
|
|
10
|
-
|
|
11
8
|
function buildYargs (withCommands = false) {
|
|
12
9
|
const yargs = Yargs([])
|
|
13
10
|
.usage('$0 [opts] [script] [opts]')
|
|
11
|
+
.options('config', {
|
|
12
|
+
alias: 'c',
|
|
13
|
+
config: true,
|
|
14
|
+
describe: 'path to JSON configuration file',
|
|
15
|
+
configParser: (path) => JSON.parse(readFileSync(path)),
|
|
16
|
+
default: () => findUp.sync(['.c8rc', '.c8rc.json', '.nycrc', '.nycrc.json'])
|
|
17
|
+
})
|
|
14
18
|
.option('reporter', {
|
|
15
19
|
alias: 'r',
|
|
20
|
+
group: 'Reporting options',
|
|
16
21
|
describe: 'coverage reporter(s) to use',
|
|
17
22
|
default: 'text'
|
|
18
23
|
})
|
|
19
24
|
.option('reports-dir', {
|
|
20
25
|
alias: ['o', 'report-dir'],
|
|
26
|
+
group: 'Reporting options',
|
|
21
27
|
describe: 'directory where coverage reports will be output to',
|
|
22
28
|
default: './coverage'
|
|
23
29
|
})
|
|
30
|
+
.options('all', {
|
|
31
|
+
default: false,
|
|
32
|
+
type: 'boolean',
|
|
33
|
+
group: 'Reporting options',
|
|
34
|
+
describe: 'supplying --all will cause c8 to consider all src files in the current working directory ' +
|
|
35
|
+
'when the determining coverage. Respects include/exclude.'
|
|
36
|
+
})
|
|
37
|
+
.options('src', {
|
|
38
|
+
default: undefined,
|
|
39
|
+
type: 'string',
|
|
40
|
+
group: 'Reporting options',
|
|
41
|
+
describe: 'supplying --src will override cwd as the default location where --all looks for src files. --src can be ' +
|
|
42
|
+
'supplied multiple times and each directory will be included. This allows for workspaces spanning multiple projects'
|
|
43
|
+
})
|
|
44
|
+
.option('exclude-node-modules', {
|
|
45
|
+
default: true,
|
|
46
|
+
type: 'boolean',
|
|
47
|
+
describe: 'whether or not to exclude all node_module folders (i.e. **/node_modules/**) by default'
|
|
48
|
+
})
|
|
49
|
+
.option('include', {
|
|
50
|
+
alias: 'n',
|
|
51
|
+
default: [],
|
|
52
|
+
group: 'Reporting options',
|
|
53
|
+
describe: 'a list of specific files that should be covered (glob patterns are supported)'
|
|
54
|
+
})
|
|
24
55
|
.option('exclude', {
|
|
25
56
|
alias: 'x',
|
|
26
57
|
default: defaultExclude,
|
|
58
|
+
group: 'Reporting options',
|
|
27
59
|
describe: 'a list of specific files and directories that should be excluded from coverage (glob patterns are supported)'
|
|
28
60
|
})
|
|
29
61
|
.option('exclude-after-remap', {
|
|
30
62
|
alias: 'a',
|
|
31
63
|
type: 'boolean',
|
|
32
64
|
default: false,
|
|
65
|
+
group: 'Reporting options',
|
|
33
66
|
describe: 'apply exclude logic to files after they are remapped by a source-map'
|
|
34
67
|
})
|
|
35
|
-
.
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
68
|
+
.options('skip-full', {
|
|
69
|
+
default: false,
|
|
70
|
+
type: 'boolean',
|
|
71
|
+
group: 'Reporting options',
|
|
72
|
+
describe: 'do not show files with 100% statement, branch, and function coverage'
|
|
39
73
|
})
|
|
40
74
|
.option('check-coverage', {
|
|
41
75
|
default: false,
|
|
42
76
|
type: 'boolean',
|
|
77
|
+
group: 'Coverage thresholds',
|
|
43
78
|
description: 'check whether coverage is within thresholds provided'
|
|
44
79
|
})
|
|
45
80
|
.option('branches', {
|
|
46
81
|
default: 0,
|
|
82
|
+
group: 'Coverage thresholds',
|
|
47
83
|
description: 'what % of branches must be covered?',
|
|
48
84
|
type: 'number'
|
|
49
85
|
})
|
|
50
86
|
.option('functions', {
|
|
51
87
|
default: 0,
|
|
88
|
+
group: 'Coverage thresholds',
|
|
52
89
|
description: 'what % of functions must be covered?',
|
|
53
90
|
type: 'number'
|
|
54
91
|
})
|
|
55
92
|
.option('lines', {
|
|
56
93
|
default: 90,
|
|
94
|
+
group: 'Coverage thresholds',
|
|
57
95
|
description: 'what % of lines must be covered?',
|
|
58
96
|
type: 'number'
|
|
59
97
|
})
|
|
60
98
|
.option('statements', {
|
|
61
99
|
default: 0,
|
|
100
|
+
group: 'Coverage thresholds',
|
|
62
101
|
description: 'what % of statements must be covered?',
|
|
63
102
|
type: 'number'
|
|
64
103
|
})
|
|
65
104
|
.option('per-file', {
|
|
66
105
|
default: false,
|
|
106
|
+
group: 'Coverage thresholds',
|
|
67
107
|
description: 'check thresholds per file',
|
|
68
108
|
type: 'boolean'
|
|
69
109
|
})
|
|
110
|
+
.option('100', {
|
|
111
|
+
default: false,
|
|
112
|
+
group: 'Coverage thresholds',
|
|
113
|
+
description: 'shortcut for --check-coverage --lines 100 --functions 100 --branches 100 --statements 100',
|
|
114
|
+
type: 'boolean'
|
|
115
|
+
})
|
|
70
116
|
.option('temp-directory', {
|
|
71
117
|
describe: 'directory V8 coverage data is written to and read from',
|
|
72
118
|
default: process.env.NODE_V8_COVERAGE
|
|
73
119
|
})
|
|
120
|
+
.option('clean', {
|
|
121
|
+
default: true,
|
|
122
|
+
type: 'boolean',
|
|
123
|
+
describe: 'should temp files be deleted before script execution'
|
|
124
|
+
})
|
|
74
125
|
.option('resolve', {
|
|
75
126
|
default: '',
|
|
76
127
|
describe: 'resolve paths to alternate base directory'
|
|
@@ -84,36 +135,13 @@ function buildYargs (withCommands = false) {
|
|
|
84
135
|
type: 'boolean',
|
|
85
136
|
describe: 'omit any paths that are not absolute, e.g., internal/net.js'
|
|
86
137
|
})
|
|
87
|
-
.option('clean', {
|
|
88
|
-
default: true,
|
|
89
|
-
type: 'boolean',
|
|
90
|
-
describe: 'should temp files be deleted before script execution'
|
|
91
|
-
})
|
|
92
|
-
.options('all', {
|
|
93
|
-
default: false,
|
|
94
|
-
type: 'boolean',
|
|
95
|
-
describe: 'supplying --all will cause c8 to consider all src files in the current working directory ' +
|
|
96
|
-
'when the determining coverage. Respects include/exclude.'
|
|
97
|
-
})
|
|
98
138
|
.options('allowExternal', {
|
|
99
139
|
default: false,
|
|
100
140
|
type: 'boolean',
|
|
101
141
|
describe: 'supplying --allowExternal will cause c8 to allow files from outside of your cwd. This applies both to ' +
|
|
102
142
|
'files discovered in coverage temp files and also src files discovered if using the --all flag.'
|
|
103
143
|
})
|
|
104
|
-
.options('src', {
|
|
105
|
-
default: undefined,
|
|
106
|
-
type: 'string',
|
|
107
|
-
describe: 'supplying --src will override cwd as the default location where --all looks for src files. --src can be ' +
|
|
108
|
-
'supplied multiple times and each directory will be included. This allows for workspaces spanning multiple projects'
|
|
109
|
-
})
|
|
110
|
-
.options('skip-full', {
|
|
111
|
-
default: false,
|
|
112
|
-
type: 'boolean',
|
|
113
|
-
describe: 'do not show files with 100% statement, branch, and function coverage'
|
|
114
|
-
})
|
|
115
144
|
.pkgConf('c8')
|
|
116
|
-
.config(config)
|
|
117
145
|
.demandCommand(1)
|
|
118
146
|
.check((argv) => {
|
|
119
147
|
if (!argv.tempDirectory) {
|
|
@@ -123,6 +151,19 @@ function buildYargs (withCommands = false) {
|
|
|
123
151
|
})
|
|
124
152
|
.epilog('visit https://git.io/vHysA for list of available reporters')
|
|
125
153
|
|
|
154
|
+
// TODO: enable once yargs upgraded to v17: https://github.com/bcoe/c8/pull/332#discussion_r721636191
|
|
155
|
+
// yargs.middleware((argv) => {
|
|
156
|
+
// if (!argv['100']) return argv
|
|
157
|
+
|
|
158
|
+
// return {
|
|
159
|
+
// ...argv,
|
|
160
|
+
// branches: 100,
|
|
161
|
+
// functions: 100,
|
|
162
|
+
// lines: 100,
|
|
163
|
+
// statements: 100,
|
|
164
|
+
// }
|
|
165
|
+
// })
|
|
166
|
+
|
|
126
167
|
const checkCoverage = require('./commands/check-coverage')
|
|
127
168
|
const report = require('./commands/report')
|
|
128
169
|
if (withCommands) {
|
package/lib/report.js
CHANGED
|
@@ -27,7 +27,8 @@ class Report {
|
|
|
27
27
|
all,
|
|
28
28
|
src,
|
|
29
29
|
allowExternal = false,
|
|
30
|
-
skipFull
|
|
30
|
+
skipFull,
|
|
31
|
+
excludeNodeModules
|
|
31
32
|
}) {
|
|
32
33
|
this.reporter = reporter
|
|
33
34
|
this.reportsDirectory = reportsDirectory
|
|
@@ -37,7 +38,8 @@ class Report {
|
|
|
37
38
|
this.exclude = new Exclude({
|
|
38
39
|
exclude: exclude,
|
|
39
40
|
include: include,
|
|
40
|
-
relativePath: !allowExternal
|
|
41
|
+
relativePath: !allowExternal,
|
|
42
|
+
excludeNodeModules: excludeNodeModules
|
|
41
43
|
})
|
|
42
44
|
this.excludeAfterRemap = excludeAfterRemap
|
|
43
45
|
this.omitRelative = omitRelative
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "c8",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.10.0",
|
|
4
4
|
"description": "output coverage reports using Node.js' built in coverage",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"types": "./index.d.ts",
|
|
@@ -37,21 +37,22 @@
|
|
|
37
37
|
"@istanbuljs/schema": "^0.1.2",
|
|
38
38
|
"find-up": "^5.0.0",
|
|
39
39
|
"foreground-child": "^2.0.0",
|
|
40
|
-
"istanbul-lib-coverage": "^3.0.
|
|
40
|
+
"istanbul-lib-coverage": "^3.0.1",
|
|
41
41
|
"istanbul-lib-report": "^3.0.0",
|
|
42
42
|
"istanbul-reports": "^3.0.2",
|
|
43
43
|
"rimraf": "^3.0.0",
|
|
44
44
|
"test-exclude": "^6.0.0",
|
|
45
|
-
"v8-to-istanbul": "^
|
|
45
|
+
"v8-to-istanbul": "^8.0.0",
|
|
46
46
|
"yargs": "^16.2.0",
|
|
47
47
|
"yargs-parser": "^20.2.7"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
+
"@types/node": "^16.9.1",
|
|
50
51
|
"chai": "^4.2.0",
|
|
51
52
|
"chai-jest-snapshot": "^2.0.0",
|
|
52
|
-
"mocha": "^
|
|
53
|
+
"mocha": "^9.0.0",
|
|
53
54
|
"standard": "^16.0.3",
|
|
54
|
-
"ts-node": "^
|
|
55
|
+
"ts-node": "^10.0.0",
|
|
55
56
|
"typescript": "^4.0.0"
|
|
56
57
|
},
|
|
57
58
|
"engines": {
|