c8 7.7.3 → 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 CHANGED
@@ -2,6 +2,13 @@
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
+
5
12
  ### [7.7.3](https://www.github.com/bcoe/c8/compare/v7.7.2...v7.7.3) (2021-06-03)
6
13
 
7
14
 
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` 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.
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/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
- .option('include', {
36
- alias: 'n',
37
- default: [],
38
- describe: 'a list of specific files that should be covered (glob patterns are supported)'
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c8",
3
- "version": "7.7.3",
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",
@@ -49,7 +49,7 @@
49
49
  "devDependencies": {
50
50
  "chai": "^4.2.0",
51
51
  "chai-jest-snapshot": "^2.0.0",
52
- "mocha": "^8.1.3",
52
+ "mocha": "^9.0.0",
53
53
  "standard": "^16.0.3",
54
54
  "ts-node": "^9.0.0",
55
55
  "typescript": "^4.0.0"