c8 7.7.0 → 7.8.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 +28 -2
- package/index.d.ts +4 -3
- package/lib/parse-args.js +47 -30
- package/lib/report.js +23 -6
- package/package.json +3 -4
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.8.0](https://www.github.com/bcoe/c8/compare/v7.7.3...v7.8.0) (2021-07-10)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* 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))
|
|
11
|
+
|
|
12
|
+
### [7.7.3](https://www.github.com/bcoe/c8/compare/v7.7.2...v7.7.3) (2021-06-03)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
17
|
+
* **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))
|
|
18
|
+
|
|
19
|
+
### [7.7.2](https://www.github.com/bcoe/c8/compare/v7.7.1...v7.7.2) (2021-05-02)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Bug Fixes
|
|
23
|
+
|
|
24
|
+
* address bugs with source remapping on Windows ([#301](https://www.github.com/bcoe/c8/issues/301)) ([c817902](https://www.github.com/bcoe/c8/commit/c81790262f843c01b3d14390fde81dbdbcf2226f))
|
|
25
|
+
|
|
26
|
+
### [7.7.1](https://www.github.com/bcoe/c8/compare/v7.7.0...v7.7.1) (2021-04-07)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
### Bug Fixes
|
|
30
|
+
|
|
31
|
+
* **types:** add excludeAfterRemap and allowExternal ([#297](https://www.github.com/bcoe/c8/issues/297)) ([e32a53f](https://www.github.com/bcoe/c8/commit/e32a53ff050b5faf740da4e9c3fb08e70e29d60d))
|
|
32
|
+
|
|
5
33
|
## [7.7.0](https://www.github.com/bcoe/c8/compare/v7.6.0...v7.7.0) (2021-03-30)
|
|
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/master/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
|
|
package/index.d.ts
CHANGED
|
@@ -2,8 +2,9 @@ export type Watermark = [number, number];
|
|
|
2
2
|
|
|
3
3
|
export declare class Report {
|
|
4
4
|
constructor(opts: {
|
|
5
|
-
exclude?:
|
|
6
|
-
|
|
5
|
+
exclude?: string | string[],
|
|
6
|
+
excludeAfterRemap?: boolean,
|
|
7
|
+
include?: string | string[],
|
|
7
8
|
reporter: string[],
|
|
8
9
|
reportsDirectory?: string,
|
|
9
10
|
tempDirectory?: string,
|
|
@@ -18,7 +19,7 @@ export declare class Report {
|
|
|
18
19
|
resolve?: string,
|
|
19
20
|
all?: boolean,
|
|
20
21
|
src?: Array<string>,
|
|
21
|
-
allowExternal
|
|
22
|
+
allowExternal?: boolean
|
|
22
23
|
})
|
|
23
24
|
run(): Promise<void>;
|
|
24
25
|
}
|
package/lib/parse-args.js
CHANGED
|
@@ -5,65 +5,100 @@ 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('include', {
|
|
45
|
+
alias: 'n',
|
|
46
|
+
default: [],
|
|
47
|
+
group: 'Reporting options',
|
|
48
|
+
describe: 'a list of specific files that should be covered (glob patterns are supported)'
|
|
49
|
+
})
|
|
24
50
|
.option('exclude', {
|
|
25
51
|
alias: 'x',
|
|
26
52
|
default: defaultExclude,
|
|
53
|
+
group: 'Reporting options',
|
|
27
54
|
describe: 'a list of specific files and directories that should be excluded from coverage (glob patterns are supported)'
|
|
28
55
|
})
|
|
29
56
|
.option('exclude-after-remap', {
|
|
30
57
|
alias: 'a',
|
|
31
58
|
type: 'boolean',
|
|
32
59
|
default: false,
|
|
60
|
+
group: 'Reporting options',
|
|
33
61
|
describe: 'apply exclude logic to files after they are remapped by a source-map'
|
|
34
62
|
})
|
|
35
|
-
.
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
63
|
+
.options('skip-full', {
|
|
64
|
+
default: false,
|
|
65
|
+
type: 'boolean',
|
|
66
|
+
group: 'Reporting options',
|
|
67
|
+
describe: 'do not show files with 100% statement, branch, and function coverage'
|
|
39
68
|
})
|
|
40
69
|
.option('check-coverage', {
|
|
41
70
|
default: false,
|
|
42
71
|
type: 'boolean',
|
|
72
|
+
group: 'Coverage thresholds',
|
|
43
73
|
description: 'check whether coverage is within thresholds provided'
|
|
44
74
|
})
|
|
45
75
|
.option('branches', {
|
|
46
76
|
default: 0,
|
|
77
|
+
group: 'Coverage thresholds',
|
|
47
78
|
description: 'what % of branches must be covered?',
|
|
48
79
|
type: 'number'
|
|
49
80
|
})
|
|
50
81
|
.option('functions', {
|
|
51
82
|
default: 0,
|
|
83
|
+
group: 'Coverage thresholds',
|
|
52
84
|
description: 'what % of functions must be covered?',
|
|
53
85
|
type: 'number'
|
|
54
86
|
})
|
|
55
87
|
.option('lines', {
|
|
56
88
|
default: 90,
|
|
89
|
+
group: 'Coverage thresholds',
|
|
57
90
|
description: 'what % of lines must be covered?',
|
|
58
91
|
type: 'number'
|
|
59
92
|
})
|
|
60
93
|
.option('statements', {
|
|
61
94
|
default: 0,
|
|
95
|
+
group: 'Coverage thresholds',
|
|
62
96
|
description: 'what % of statements must be covered?',
|
|
63
97
|
type: 'number'
|
|
64
98
|
})
|
|
65
99
|
.option('per-file', {
|
|
66
100
|
default: false,
|
|
101
|
+
group: 'Coverage thresholds',
|
|
67
102
|
description: 'check thresholds per file',
|
|
68
103
|
type: 'boolean'
|
|
69
104
|
})
|
|
@@ -71,6 +106,11 @@ function buildYargs (withCommands = false) {
|
|
|
71
106
|
describe: 'directory V8 coverage data is written to and read from',
|
|
72
107
|
default: process.env.NODE_V8_COVERAGE
|
|
73
108
|
})
|
|
109
|
+
.option('clean', {
|
|
110
|
+
default: true,
|
|
111
|
+
type: 'boolean',
|
|
112
|
+
describe: 'should temp files be deleted before script execution'
|
|
113
|
+
})
|
|
74
114
|
.option('resolve', {
|
|
75
115
|
default: '',
|
|
76
116
|
describe: 'resolve paths to alternate base directory'
|
|
@@ -84,36 +124,13 @@ function buildYargs (withCommands = false) {
|
|
|
84
124
|
type: 'boolean',
|
|
85
125
|
describe: 'omit any paths that are not absolute, e.g., internal/net.js'
|
|
86
126
|
})
|
|
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
127
|
.options('allowExternal', {
|
|
99
128
|
default: false,
|
|
100
129
|
type: 'boolean',
|
|
101
130
|
describe: 'supplying --allowExternal will cause c8 to allow files from outside of your cwd. This applies both to ' +
|
|
102
131
|
'files discovered in coverage temp files and also src files discovered if using the --all flag.'
|
|
103
132
|
})
|
|
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
133
|
.pkgConf('c8')
|
|
116
|
-
.config(config)
|
|
117
134
|
.demandCommand(1)
|
|
118
135
|
.check((argv) => {
|
|
119
136
|
if (!argv.tempDirectory) {
|
package/lib/report.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
const Exclude = require('test-exclude')
|
|
2
|
-
const furi = require('furi')
|
|
3
2
|
const libCoverage = require('istanbul-lib-coverage')
|
|
4
3
|
const libReport = require('istanbul-lib-report')
|
|
5
4
|
const reports = require('istanbul-reports')
|
|
6
5
|
const { readdirSync, readFileSync, statSync } = require('fs')
|
|
7
6
|
const { isAbsolute, resolve, extname } = require('path')
|
|
7
|
+
const { pathToFileURL, fileURLToPath } = require('url')
|
|
8
8
|
const getSourceMapFromFile = require('./source-map-from-file')
|
|
9
9
|
// TODO: switch back to @c88/v8-coverage once patch is landed.
|
|
10
10
|
const v8toIstanbul = require('v8-to-istanbul')
|
|
@@ -139,8 +139,8 @@ class Report {
|
|
|
139
139
|
*/
|
|
140
140
|
_getSourceMap (v8ScriptCov) {
|
|
141
141
|
const sources = {}
|
|
142
|
-
|
|
143
|
-
|
|
142
|
+
const sourceMapAndLineLengths = this.sourceMapCache[pathToFileURL(v8ScriptCov.url).href]
|
|
143
|
+
if (sourceMapAndLineLengths) {
|
|
144
144
|
// See: https://github.com/nodejs/node/pull/34305
|
|
145
145
|
if (!sourceMapAndLineLengths.data) return
|
|
146
146
|
sources.sourceMap = {
|
|
@@ -173,7 +173,7 @@ class Report {
|
|
|
173
173
|
for (const v8ProcessCov of this._loadReports()) {
|
|
174
174
|
if (this._isCoverageObject(v8ProcessCov)) {
|
|
175
175
|
if (v8ProcessCov['source-map-cache']) {
|
|
176
|
-
Object.assign(this.sourceMapCache, v8ProcessCov['source-map-cache'])
|
|
176
|
+
Object.assign(this.sourceMapCache, this._normalizeSourceMapCache(v8ProcessCov['source-map-cache']))
|
|
177
177
|
}
|
|
178
178
|
v8ProcessCovs.push(this._normalizeProcessCov(v8ProcessCov, fileIndex))
|
|
179
179
|
}
|
|
@@ -194,7 +194,7 @@ class Report {
|
|
|
194
194
|
const stat = statSync(fullPath)
|
|
195
195
|
const sourceMap = getSourceMapFromFile(fullPath)
|
|
196
196
|
if (sourceMap) {
|
|
197
|
-
this.sourceMapCache[
|
|
197
|
+
this.sourceMapCache[pathToFileURL(fullPath)] = { data: sourceMap }
|
|
198
198
|
}
|
|
199
199
|
emptyReports.push({
|
|
200
200
|
scriptId: 0,
|
|
@@ -275,7 +275,7 @@ class Report {
|
|
|
275
275
|
}
|
|
276
276
|
if (/^file:\/\//.test(v8ScriptCov.url)) {
|
|
277
277
|
try {
|
|
278
|
-
v8ScriptCov.url =
|
|
278
|
+
v8ScriptCov.url = fileURLToPath(v8ScriptCov.url)
|
|
279
279
|
fileIndex.add(v8ScriptCov.url)
|
|
280
280
|
} catch (err) {
|
|
281
281
|
debuglog(`${err.stack}`)
|
|
@@ -290,6 +290,23 @@ class Report {
|
|
|
290
290
|
}
|
|
291
291
|
return { result }
|
|
292
292
|
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Normalizes a V8 source map cache.
|
|
296
|
+
*
|
|
297
|
+
* This function normalizes file URLs to a system-independent format.
|
|
298
|
+
*
|
|
299
|
+
* @param v8SourceMapCache V8 source map cache to normalize.
|
|
300
|
+
* @return {v8SourceMapCache} Normalized V8 source map cache.
|
|
301
|
+
* @private
|
|
302
|
+
*/
|
|
303
|
+
_normalizeSourceMapCache (v8SourceMapCache) {
|
|
304
|
+
const cache = {}
|
|
305
|
+
for (const fileURL of Object.keys(v8SourceMapCache)) {
|
|
306
|
+
cache[pathToFileURL(fileURLToPath(fileURL)).href] = v8SourceMapCache[fileURL]
|
|
307
|
+
}
|
|
308
|
+
return cache
|
|
309
|
+
}
|
|
293
310
|
}
|
|
294
311
|
|
|
295
312
|
module.exports = function (opts) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "c8",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.8.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,20 +37,19 @@
|
|
|
37
37
|
"@istanbuljs/schema": "^0.1.2",
|
|
38
38
|
"find-up": "^5.0.0",
|
|
39
39
|
"foreground-child": "^2.0.0",
|
|
40
|
-
"furi": "^2.0.0",
|
|
41
40
|
"istanbul-lib-coverage": "^3.0.0",
|
|
42
41
|
"istanbul-lib-report": "^3.0.0",
|
|
43
42
|
"istanbul-reports": "^3.0.2",
|
|
44
43
|
"rimraf": "^3.0.0",
|
|
45
44
|
"test-exclude": "^6.0.0",
|
|
46
|
-
"v8-to-istanbul": "^
|
|
45
|
+
"v8-to-istanbul": "^8.0.0",
|
|
47
46
|
"yargs": "^16.2.0",
|
|
48
47
|
"yargs-parser": "^20.2.7"
|
|
49
48
|
},
|
|
50
49
|
"devDependencies": {
|
|
51
50
|
"chai": "^4.2.0",
|
|
52
51
|
"chai-jest-snapshot": "^2.0.0",
|
|
53
|
-
"mocha": "^
|
|
52
|
+
"mocha": "^9.0.0",
|
|
54
53
|
"standard": "^16.0.3",
|
|
55
54
|
"ts-node": "^9.0.0",
|
|
56
55
|
"typescript": "^4.0.0"
|