c8 7.7.3 → 7.11.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 CHANGED
@@ -2,6 +2,39 @@
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.11.0](https://github.com/bcoe/c8/compare/v7.10.0...v7.11.0) (2021-12-30)
6
+
7
+
8
+ ### Features
9
+
10
+ * add --extension option ([#331](https://github.com/bcoe/c8/issues/331)) ([ff01cd8](https://github.com/bcoe/c8/commit/ff01cd832a155494892b24c30c5a1c8f0169fd8e))
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * **config:** support configuration inheritance ([#343](https://github.com/bcoe/c8/issues/343)) ([e81ed5d](https://github.com/bcoe/c8/commit/e81ed5dd9ef5dac1a1f2f6dc26a07abb6c05d709))
16
+
17
+ ## [7.10.0](https://www.github.com/bcoe/c8/compare/v7.9.0...v7.10.0) (2021-10-06)
18
+
19
+
20
+ ### Features
21
+
22
+ * `--100` ([#332](https://www.github.com/bcoe/c8/issues/332)) ([4205f2f](https://www.github.com/bcoe/c8/commit/4205f2f33585693d82c2500d0d6850571965bb8b))
23
+
24
+ ## [7.9.0](https://www.github.com/bcoe/c8/compare/v7.8.0...v7.9.0) (2021-09-10)
25
+
26
+
27
+ ### Features
28
+
29
+ * add --exclude-node-modules option ([#321](https://www.github.com/bcoe/c8/issues/321)) ([a4733c6](https://www.github.com/bcoe/c8/commit/a4733c68abd778757bb6ed641e074be94b79c417))
30
+
31
+ ## [7.8.0](https://www.github.com/bcoe/c8/compare/v7.7.3...v7.8.0) (2021-07-10)
32
+
33
+
34
+ ### Features
35
+
36
+ * 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))
37
+
5
38
  ### [7.7.3](https://www.github.com/bcoe/c8/compare/v7.7.2...v7.7.3) (2021-06-03)
6
39
 
7
40
 
package/README.md CHANGED
@@ -16,6 +16,32 @@ 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
+ | `-e`, `--extension` | only files matching these extensions will show coverage | `string | Array<string>` | [list](https://github.com/istanbuljs/schema/blob/master/default-extension.js) |
40
+ | `--skip-full` | do not show files with 100% statement, branch, and function coverage | `boolean` | `false` |
41
+ | `--check-coverage` | check whether coverage is within thresholds provided | `boolean` | `false` |
42
+ | `--temp-directory` | directory V8 coverage data is written to and read from | `string` | `process.env.NODE_V8_COVERAGE` |
43
+ | `--clean` | should temp files be deleted before script execution | `boolean` | `true` |
44
+
19
45
  ## Checking for "full" source coverage using `--all`
20
46
 
21
47
  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 +49,9 @@ project that are flexed in production but not in your tests, your coverage numbe
23
49
  if your project's `main.js` loads `a.js` and `b.js` but your unit tests only load `a.js` your total coverage
24
50
  could show as `100%` for `a.js` when in fact both `main.js` and `b.js` are uncovered.
25
51
 
26
- By supplying `--all` to c8, all files in `cwd` that pass the `--include` and `--exclude` flag checks, will be loaded into the
27
- report. If any of those files remain uncovered they will be factored into the report with a default of 0% coverage.
52
+ By supplying `--all` to c8, all files in directories specified with `--src` (defaults to `cwd`) that pass the `--include`
53
+ and `--exclude` flag checks, will be loaded into the report. If any of those files remain uncovered they will be factored
54
+ into the report with a default of 0% coverage.
28
55
 
29
56
  ## c8 report
30
57
 
@@ -54,6 +81,24 @@ To check thresholds on a per-file basis run:
54
81
  c8 check-coverage --lines 95 --per-file
55
82
  ```
56
83
 
84
+ If you want to check for 100% coverage across all dimensions, use `--100`:
85
+
86
+ ```shell
87
+ c8 --100 npm test
88
+ ```
89
+
90
+ Is equivalent to
91
+
92
+ ```shell
93
+ c8 --check-coverage --lines 100 --functions 100 --branches 100 --statements 100 npm test
94
+ ```
95
+
96
+ The `--100` flag can be set for the `check-coverage` as well:
97
+
98
+ ```shell
99
+ c8 check-coverage --100
100
+ ```
101
+
57
102
  ## Ignoring Uncovered Lines, Functions, and Blocks
58
103
 
59
104
  Sometimes you might find yourself wanting to ignore uncovered portions of your
package/index.d.ts CHANGED
@@ -3,6 +3,7 @@ export type Watermark = [number, number];
3
3
  export declare class Report {
4
4
  constructor(opts: {
5
5
  exclude?: string | string[],
6
+ extension?: string | string[],
6
7
  excludeAfterRemap?: boolean,
7
8
  include?: string | string[],
8
9
  reporter: string[],
@@ -11,9 +11,18 @@ 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,
25
+ extension: argv.extension,
17
26
  reporter: Array.isArray(argv.reporter) ? argv.reporter : [argv.reporter],
18
27
  reportsDirectory: argv['reports-dir'],
19
28
  tempDirectory: argv.tempDirectory,
@@ -10,9 +10,18 @@ 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
+ extension: argv.extension,
16
25
  excludeAfterRemap: argv.excludeAfterRemap,
17
26
  reporter: Array.isArray(argv.reporter) ? argv.reporter : [argv.reporter],
18
27
  reportsDirectory: argv['reports-dir'],
@@ -24,7 +33,8 @@ exports.outputReport = async function (argv) {
24
33
  all: argv.all,
25
34
  allowExternal: argv.allowExternal,
26
35
  src: argv.src,
27
- skipFull: argv.skipFull
36
+ skipFull: argv.skipFull,
37
+ excludeNodeModules: argv.excludeNodeModules
28
38
  })
29
39
  await report.run()
30
40
  if (argv.checkCoverage) await checkCoverages(argv, report)
package/lib/parse-args.js CHANGED
@@ -1,76 +1,138 @@
1
1
  const defaultExclude = require('@istanbuljs/schema/default-exclude')
2
+ const defaultExtension = require('@istanbuljs/schema/default-extension')
2
3
  const findUp = require('find-up')
3
4
  const { readFileSync } = require('fs')
4
5
  const Yargs = require('yargs/yargs')
6
+ const { applyExtends } = require('yargs/helpers')
5
7
  const parser = require('yargs-parser')
6
8
  const { resolve } = require('path')
7
9
 
8
- const configPath = findUp.sync(['.c8rc', '.c8rc.json', '.nycrc', '.nycrc.json'])
9
- const config = configPath ? JSON.parse(readFileSync(configPath)) : {}
10
-
11
10
  function buildYargs (withCommands = false) {
12
11
  const yargs = Yargs([])
13
12
  .usage('$0 [opts] [script] [opts]')
13
+ .options('config', {
14
+ alias: 'c',
15
+ config: true,
16
+ describe: 'path to JSON configuration file',
17
+ configParser: (path) => {
18
+ const config = JSON.parse(readFileSync(path))
19
+ return applyExtends(config, process.cwd(), true)
20
+ },
21
+ default: () => findUp.sync(['.c8rc', '.c8rc.json', '.nycrc', '.nycrc.json'])
22
+ })
14
23
  .option('reporter', {
15
24
  alias: 'r',
25
+ group: 'Reporting options',
16
26
  describe: 'coverage reporter(s) to use',
17
27
  default: 'text'
18
28
  })
19
29
  .option('reports-dir', {
20
30
  alias: ['o', 'report-dir'],
31
+ group: 'Reporting options',
21
32
  describe: 'directory where coverage reports will be output to',
22
33
  default: './coverage'
23
34
  })
35
+ .options('all', {
36
+ default: false,
37
+ type: 'boolean',
38
+ group: 'Reporting options',
39
+ describe: 'supplying --all will cause c8 to consider all src files in the current working directory ' +
40
+ 'when the determining coverage. Respects include/exclude.'
41
+ })
42
+ .options('src', {
43
+ default: undefined,
44
+ type: 'string',
45
+ group: 'Reporting options',
46
+ describe: 'supplying --src will override cwd as the default location where --all looks for src files. --src can be ' +
47
+ 'supplied multiple times and each directory will be included. This allows for workspaces spanning multiple projects'
48
+ })
49
+ .option('exclude-node-modules', {
50
+ default: true,
51
+ type: 'boolean',
52
+ describe: 'whether or not to exclude all node_module folders (i.e. **/node_modules/**) by default'
53
+ })
54
+ .option('include', {
55
+ alias: 'n',
56
+ default: [],
57
+ group: 'Reporting options',
58
+ describe: 'a list of specific files that should be covered (glob patterns are supported)'
59
+ })
24
60
  .option('exclude', {
25
61
  alias: 'x',
26
62
  default: defaultExclude,
63
+ group: 'Reporting options',
27
64
  describe: 'a list of specific files and directories that should be excluded from coverage (glob patterns are supported)'
28
65
  })
66
+ .option('extension', {
67
+ alias: 'e',
68
+ default: defaultExtension,
69
+ group: 'Reporting options',
70
+ describe: 'a list of specific file extensions that should be covered'
71
+ })
29
72
  .option('exclude-after-remap', {
30
73
  alias: 'a',
31
74
  type: 'boolean',
32
75
  default: false,
76
+ group: 'Reporting options',
33
77
  describe: 'apply exclude logic to files after they are remapped by a source-map'
34
78
  })
35
- .option('include', {
36
- alias: 'n',
37
- default: [],
38
- describe: 'a list of specific files that should be covered (glob patterns are supported)'
79
+ .options('skip-full', {
80
+ default: false,
81
+ type: 'boolean',
82
+ group: 'Reporting options',
83
+ describe: 'do not show files with 100% statement, branch, and function coverage'
39
84
  })
40
85
  .option('check-coverage', {
41
86
  default: false,
42
87
  type: 'boolean',
88
+ group: 'Coverage thresholds',
43
89
  description: 'check whether coverage is within thresholds provided'
44
90
  })
45
91
  .option('branches', {
46
92
  default: 0,
93
+ group: 'Coverage thresholds',
47
94
  description: 'what % of branches must be covered?',
48
95
  type: 'number'
49
96
  })
50
97
  .option('functions', {
51
98
  default: 0,
99
+ group: 'Coverage thresholds',
52
100
  description: 'what % of functions must be covered?',
53
101
  type: 'number'
54
102
  })
55
103
  .option('lines', {
56
104
  default: 90,
105
+ group: 'Coverage thresholds',
57
106
  description: 'what % of lines must be covered?',
58
107
  type: 'number'
59
108
  })
60
109
  .option('statements', {
61
110
  default: 0,
111
+ group: 'Coverage thresholds',
62
112
  description: 'what % of statements must be covered?',
63
113
  type: 'number'
64
114
  })
65
115
  .option('per-file', {
66
116
  default: false,
117
+ group: 'Coverage thresholds',
67
118
  description: 'check thresholds per file',
68
119
  type: 'boolean'
69
120
  })
121
+ .option('100', {
122
+ default: false,
123
+ group: 'Coverage thresholds',
124
+ description: 'shortcut for --check-coverage --lines 100 --functions 100 --branches 100 --statements 100',
125
+ type: 'boolean'
126
+ })
70
127
  .option('temp-directory', {
71
128
  describe: 'directory V8 coverage data is written to and read from',
72
129
  default: process.env.NODE_V8_COVERAGE
73
130
  })
131
+ .option('clean', {
132
+ default: true,
133
+ type: 'boolean',
134
+ describe: 'should temp files be deleted before script execution'
135
+ })
74
136
  .option('resolve', {
75
137
  default: '',
76
138
  describe: 'resolve paths to alternate base directory'
@@ -84,36 +146,13 @@ function buildYargs (withCommands = false) {
84
146
  type: 'boolean',
85
147
  describe: 'omit any paths that are not absolute, e.g., internal/net.js'
86
148
  })
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
149
  .options('allowExternal', {
99
150
  default: false,
100
151
  type: 'boolean',
101
152
  describe: 'supplying --allowExternal will cause c8 to allow files from outside of your cwd. This applies both to ' +
102
153
  'files discovered in coverage temp files and also src files discovered if using the --all flag.'
103
154
  })
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
155
  .pkgConf('c8')
116
- .config(config)
117
156
  .demandCommand(1)
118
157
  .check((argv) => {
119
158
  if (!argv.tempDirectory) {
@@ -123,6 +162,19 @@ function buildYargs (withCommands = false) {
123
162
  })
124
163
  .epilog('visit https://git.io/vHysA for list of available reporters')
125
164
 
165
+ // TODO: enable once yargs upgraded to v17: https://github.com/bcoe/c8/pull/332#discussion_r721636191
166
+ // yargs.middleware((argv) => {
167
+ // if (!argv['100']) return argv
168
+
169
+ // return {
170
+ // ...argv,
171
+ // branches: 100,
172
+ // functions: 100,
173
+ // lines: 100,
174
+ // statements: 100,
175
+ // }
176
+ // })
177
+
126
178
  const checkCoverage = require('./commands/check-coverage')
127
179
  const report = require('./commands/report')
128
180
  if (withCommands) {
package/lib/report.js CHANGED
@@ -15,6 +15,7 @@ const debuglog = util.debuglog('c8')
15
15
  class Report {
16
16
  constructor ({
17
17
  exclude,
18
+ extension,
18
19
  excludeAfterRemap,
19
20
  include,
20
21
  reporter,
@@ -27,7 +28,8 @@ class Report {
27
28
  all,
28
29
  src,
29
30
  allowExternal = false,
30
- skipFull
31
+ skipFull,
32
+ excludeNodeModules
31
33
  }) {
32
34
  this.reporter = reporter
33
35
  this.reportsDirectory = reportsDirectory
@@ -37,7 +39,9 @@ class Report {
37
39
  this.exclude = new Exclude({
38
40
  exclude: exclude,
39
41
  include: include,
40
- relativePath: !allowExternal
42
+ extension: extension,
43
+ relativePath: !allowExternal,
44
+ excludeNodeModules: excludeNodeModules
41
45
  })
42
46
  this.excludeAfterRemap = excludeAfterRemap
43
47
  this.omitRelative = omitRelative
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c8",
3
- "version": "7.7.3",
3
+ "version": "7.11.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,7 +37,7 @@
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.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",
@@ -47,11 +47,12 @@
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": "^8.1.3",
53
+ "mocha": "^9.0.0",
53
54
  "standard": "^16.0.3",
54
- "ts-node": "^9.0.0",
55
+ "ts-node": "^10.0.0",
55
56
  "typescript": "^4.0.0"
56
57
  },
57
58
  "engines": {