monocart-coverage-reports 2.6.3 → 2.6.4
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/README.md +36 -16
- package/lib/cli.js +27 -97
- package/lib/converter/ast.js +3 -1
- package/lib/default/options.js +28 -24
- package/lib/generate.js +5 -2
- package/lib/index.d.ts +71 -40
- package/lib/index.js +86 -11
- package/lib/packages/monocart-coverage-v8.js +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
- [Using `v8-to-istanbul`](#using-v8-to-istanbul)
|
|
34
34
|
- [How Monocart Works](#how-monocart-works)
|
|
35
35
|
* [Debug for Coverage and Sourcemap](#debug-for-coverage-and-sourcemap)
|
|
36
|
+
* [Common issues](#common-issues)
|
|
36
37
|
* [Integration](#integration)
|
|
37
38
|
- [Playwright](#playwright)
|
|
38
39
|
- [Jest](#jest)
|
|
@@ -282,10 +283,11 @@ Arguments:
|
|
|
282
283
|
|
|
283
284
|
Options:
|
|
284
285
|
-V, --version output the version number
|
|
285
|
-
-c, --config <path> custom config path
|
|
286
|
-
|
|
287
|
-
-r, --reports <name[,name]> coverage reports to use
|
|
286
|
+
-c, --config <path> custom config file path
|
|
287
|
+
--logging <logging> off, error, info, debug
|
|
288
288
|
-n, --name <name> report name for title
|
|
289
|
+
-r, --reports <name[,name]> coverage reports to use
|
|
290
|
+
-o, --outputDir <dir> output dir for reports
|
|
289
291
|
-i, --inputDir <dir> input dir for merging raw files
|
|
290
292
|
--entryFilter <pattern> entry url filter
|
|
291
293
|
--sourceFilter <pattern> source path filter
|
|
@@ -293,24 +295,20 @@ Options:
|
|
|
293
295
|
--inline inline html for v8 report
|
|
294
296
|
--assetsPath <path> assets path if not inline
|
|
295
297
|
--lcov generate lcov.info file
|
|
296
|
-
--logging <logging> off, error, info, debug
|
|
297
298
|
-h, --help display help for command
|
|
298
299
|
```
|
|
299
300
|
|
|
300
|
-
- Loading
|
|
301
|
-
-
|
|
302
|
-
- `mcr.config.json`
|
|
303
|
-
- `mcr.config.mjs`
|
|
304
|
-
- `mcr.config.cjs`
|
|
301
|
+
- Loading config file by priority:
|
|
302
|
+
- custom config file with `-c` or `--config`
|
|
305
303
|
- `mcr.config.js`
|
|
306
|
-
- `mcr.config.
|
|
307
|
-
|
|
308
|
-
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
304
|
+
- `mcr.config.cjs`
|
|
305
|
+
- `mcr.config.mjs`
|
|
306
|
+
- `mcr.config.json` - json format
|
|
307
|
+
- `.mcrrc.js`
|
|
308
|
+
- `.mcrrc` - json format
|
|
309
|
+
- `mcr.config.ts` - it requires `NODE_OPTIONS="--loader ts-node/esm"`
|
|
312
310
|
|
|
313
|
-
-
|
|
311
|
+
- Working with `ts-node`, see [mcr-ts-node](https://github.com/cenfun/mcr-ts-node)
|
|
314
312
|
|
|
315
313
|
## Compare Reports
|
|
316
314
|
| | Istanbul | V8 | V8 to Istanbul |
|
|
@@ -707,6 +705,28 @@ When `logging` is `debug`, the raw report data will be preserved in `[outputDir]
|
|
|
707
705
|
|
|
708
706
|

|
|
709
707
|
|
|
708
|
+
## Common issues
|
|
709
|
+
- `Unparsable source`
|
|
710
|
+
|
|
711
|
+
It happens during the parsing of the source code into AST, if the source code is not in the standard ECMAScript. For example `ts`, `jsx` and so on. There is a option to fix it, which is to manually compile the source code for these files.
|
|
712
|
+
```js
|
|
713
|
+
import * as fs from "fs";
|
|
714
|
+
import * as path from "path";
|
|
715
|
+
import { fileURLToPath } from "url";
|
|
716
|
+
import * as TsNode from 'ts-node';
|
|
717
|
+
const coverageOptions = {
|
|
718
|
+
onEntry: async (entry) => {
|
|
719
|
+
const filePath = fileURLToPath(entry.url)
|
|
720
|
+
const originalSource = fs.readFileSync(filePath).toString("utf-8");
|
|
721
|
+
const fileName = path.basename(filePath);
|
|
722
|
+
const tn = TsNode.create({});
|
|
723
|
+
const source = tn.compile(originalSource, fileName);
|
|
724
|
+
entry.fake = false;
|
|
725
|
+
entry.source = source;
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
```
|
|
729
|
+
|
|
710
730
|
## Integration
|
|
711
731
|
|
|
712
732
|
### [Playwright](https://github.com/microsoft/playwright)
|
package/lib/cli.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const fs = require('fs');
|
|
4
4
|
const path = require('path');
|
|
5
5
|
const EC = require('eight-colors');
|
|
6
|
-
const { fileURLToPath
|
|
6
|
+
const { fileURLToPath } = require('url');
|
|
7
7
|
|
|
8
8
|
const {
|
|
9
9
|
foregroundChild,
|
|
@@ -12,86 +12,10 @@ const {
|
|
|
12
12
|
|
|
13
13
|
const MCR = require('./index.js');
|
|
14
14
|
const Util = require('./utils/util.js');
|
|
15
|
-
const defaultOptions = require('./default/options.js');
|
|
16
15
|
const { resolveSourceMap } = require('./converter/collect-source-maps.js');
|
|
17
16
|
|
|
18
17
|
const version = require('../package.json').version;
|
|
19
18
|
|
|
20
|
-
const resolveConfigPath = (customConfigPath) => {
|
|
21
|
-
|
|
22
|
-
const configList = [
|
|
23
|
-
'.mcrrc',
|
|
24
|
-
'mcr.config.json',
|
|
25
|
-
'mcr.config.mjs',
|
|
26
|
-
'mcr.config.cjs',
|
|
27
|
-
'mcr.config.js',
|
|
28
|
-
'mcr.config.ts'
|
|
29
|
-
];
|
|
30
|
-
|
|
31
|
-
if (customConfigPath) {
|
|
32
|
-
configList.push(customConfigPath);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const existsList = configList.filter((p) => fs.existsSync(p));
|
|
36
|
-
if (!existsList.length) {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// last one
|
|
41
|
-
const configPath = existsList.pop();
|
|
42
|
-
Util.logInfo(`Config: ${EC.cyan(configPath)}`);
|
|
43
|
-
|
|
44
|
-
return configPath;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
const resolveConfigOptions = async (configPath) => {
|
|
48
|
-
|
|
49
|
-
// json format
|
|
50
|
-
const ext = path.extname(configPath);
|
|
51
|
-
if (ext === '.json' || configPath.slice(-2) === 'rc') {
|
|
52
|
-
return JSON.parse(Util.readFileSync(configPath));
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
let configOptions;
|
|
56
|
-
let err;
|
|
57
|
-
try {
|
|
58
|
-
configOptions = await import(pathToFileURL(configPath));
|
|
59
|
-
} catch (ee) {
|
|
60
|
-
err = ee;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (err || !configOptions) {
|
|
64
|
-
Util.logError(`ERROR: failed to import "${configPath}": ${err && err.message} `);
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
configOptions = configOptions.default || configOptions;
|
|
69
|
-
|
|
70
|
-
return configOptions;
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
const initOptions = async (cliOptions) => {
|
|
74
|
-
|
|
75
|
-
const configPath = resolveConfigPath(cliOptions.config);
|
|
76
|
-
if (configPath) {
|
|
77
|
-
const configOptions = await resolveConfigOptions(configPath);
|
|
78
|
-
if (configOptions) {
|
|
79
|
-
cliOptions = {
|
|
80
|
-
... configOptions,
|
|
81
|
-
... cliOptions
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// report options
|
|
87
|
-
const options = {
|
|
88
|
-
... defaultOptions,
|
|
89
|
-
... cliOptions
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
return options;
|
|
93
|
-
};
|
|
94
|
-
|
|
95
19
|
const resolveEntrySource = (entry, sourceMapCache = {}) => {
|
|
96
20
|
let source;
|
|
97
21
|
const filePath = fileURLToPath(entry.url);
|
|
@@ -100,7 +24,7 @@ const resolveEntrySource = (entry, sourceMapCache = {}) => {
|
|
|
100
24
|
source = fs.readFileSync(filePath).toString('utf8');
|
|
101
25
|
}
|
|
102
26
|
|
|
103
|
-
// not for typescript
|
|
27
|
+
// not for typescript, but it could be jsx even it is `.js`
|
|
104
28
|
if (source && !['.ts', '.tsx'].includes(extname)) {
|
|
105
29
|
entry.source = source;
|
|
106
30
|
return;
|
|
@@ -111,7 +35,6 @@ const resolveEntrySource = (entry, sourceMapCache = {}) => {
|
|
|
111
35
|
|
|
112
36
|
// for fake source file (can not parse to AST)
|
|
113
37
|
if (lineLengths) {
|
|
114
|
-
// get runtime code with ts-node
|
|
115
38
|
let fakeSource = '';
|
|
116
39
|
sourcemapData.lineLengths.forEach((length) => {
|
|
117
40
|
fakeSource += `${''.padEnd(length, '*')}\n`;
|
|
@@ -188,25 +111,25 @@ const addCoverageData = async (coverageReport, nodeV8CoverageDir) => {
|
|
|
188
111
|
|
|
189
112
|
const executeCommand = async (command, cliOptions) => {
|
|
190
113
|
|
|
191
|
-
const options = await initOptions(cliOptions);
|
|
192
|
-
|
|
193
114
|
Util.logInfo(`Execute: ${EC.cyan(command)}`);
|
|
115
|
+
|
|
194
116
|
// console.log(options);
|
|
117
|
+
const coverageReport = MCR(cliOptions);
|
|
118
|
+
await coverageReport.loadConfig(cliOptions.config);
|
|
119
|
+
coverageReport.cleanCache();
|
|
195
120
|
|
|
196
|
-
const
|
|
197
|
-
process.env.NODE_V8_COVERAGE = nodeV8CoverageDir;
|
|
121
|
+
const coverageOptions = coverageReport.options;
|
|
198
122
|
|
|
123
|
+
// dir for node v8 coverage
|
|
124
|
+
const nodeV8CoverageDir = Util.relativePath(path.resolve(coverageOptions.outputDir, '.v8-coverage'));
|
|
125
|
+
process.env.NODE_V8_COVERAGE = nodeV8CoverageDir;
|
|
199
126
|
// clean v8 cache before running
|
|
200
127
|
Util.rmSync(nodeV8CoverageDir);
|
|
201
|
-
|
|
202
|
-
// console.log('nodeV8CoverageDir', nodeV8CoverageDir);
|
|
203
|
-
|
|
204
|
-
const coverageReport = MCR(options);
|
|
205
|
-
coverageReport.cleanCache();
|
|
128
|
+
// Util.logInfo(`V8 coverage dir: ${EC.cyan(nodeV8CoverageDir)}`);
|
|
206
129
|
|
|
207
130
|
// =========================================
|
|
208
131
|
// onStart hook
|
|
209
|
-
const onStart =
|
|
132
|
+
const onStart = coverageOptions.onStart;
|
|
210
133
|
if (typeof onStart === 'function') {
|
|
211
134
|
await onStart(coverageReport);
|
|
212
135
|
}
|
|
@@ -214,17 +137,19 @@ const executeCommand = async (command, cliOptions) => {
|
|
|
214
137
|
|
|
215
138
|
const subprocess = foregroundChild(command, {
|
|
216
139
|
shell: true
|
|
217
|
-
}, async () => {
|
|
140
|
+
}, async (code, signal) => {
|
|
141
|
+
|
|
142
|
+
// generate coverage even it is failed. code != 0
|
|
218
143
|
|
|
219
144
|
if (!fs.existsSync(nodeV8CoverageDir)) {
|
|
220
|
-
EC.logRed(`Not found coverage
|
|
145
|
+
EC.logRed(`Not found V8 coverage dir: ${Util.relativePath(nodeV8CoverageDir)}`);
|
|
221
146
|
return 1;
|
|
222
147
|
}
|
|
223
148
|
|
|
224
149
|
// =========================================
|
|
225
150
|
// onReady hook before adding coverage data.
|
|
226
151
|
// Sometimes, the child process has not yet finished writing the coverage data, and it needs to wait here.
|
|
227
|
-
const onReady =
|
|
152
|
+
const onReady = coverageOptions.onReady;
|
|
228
153
|
if (typeof onReady === 'function') {
|
|
229
154
|
await onReady(coverageReport, nodeV8CoverageDir, subprocess);
|
|
230
155
|
}
|
|
@@ -243,16 +168,23 @@ const executeCommand = async (command, cliOptions) => {
|
|
|
243
168
|
|
|
244
169
|
};
|
|
245
170
|
|
|
171
|
+
process.on('uncaughtException', function(err) {
|
|
172
|
+
Util.logError(`ERROR: ${err.message || err}`);
|
|
173
|
+
});
|
|
174
|
+
|
|
246
175
|
program
|
|
247
176
|
.name('mcr')
|
|
248
177
|
.description('CLI to generate coverage reports')
|
|
249
178
|
.version(version)
|
|
250
179
|
.argument('<command>', 'command to execute')
|
|
251
180
|
.allowUnknownOption()
|
|
252
|
-
.option('-c, --config <path>', 'custom config path')
|
|
253
|
-
.option('
|
|
254
|
-
|
|
181
|
+
.option('-c, --config <path>', 'custom config file path')
|
|
182
|
+
.option('--logging <logging>', 'off, error, info, debug')
|
|
183
|
+
|
|
255
184
|
.option('-n, --name <name>', 'report name for title')
|
|
185
|
+
.option('-r, --reports <name[,name]>', 'coverage reports to use')
|
|
186
|
+
|
|
187
|
+
.option('-o, --outputDir <dir>', 'output dir for reports')
|
|
256
188
|
.option('-i, --inputDir <dir>', 'input dir for merging raw files')
|
|
257
189
|
|
|
258
190
|
.option('--entryFilter <pattern>', 'entry url filter')
|
|
@@ -264,8 +196,6 @@ program
|
|
|
264
196
|
|
|
265
197
|
.option('--lcov', 'generate lcov.info file')
|
|
266
198
|
|
|
267
|
-
.option('--logging <logging>', 'off, error, info, debug')
|
|
268
|
-
|
|
269
199
|
.action((_command, cliOptions) => {
|
|
270
200
|
const command = program.args.join(' ');
|
|
271
201
|
executeCommand(command, cliOptions);
|
package/lib/converter/ast.js
CHANGED
|
@@ -188,7 +188,9 @@ const getJsAstInfo = (item, coverageList) => {
|
|
|
188
188
|
}
|
|
189
189
|
|
|
190
190
|
// runtime code should be parsed successful
|
|
191
|
-
Util.logInfo(`
|
|
191
|
+
Util.logInfo(`Unparsable source: ${item.sourcePath} ${err.message}`);
|
|
192
|
+
|
|
193
|
+
// it could be jsx even it is `.js`
|
|
192
194
|
|
|
193
195
|
// https://github.com/acornjs/acorn/tree/master/acorn-loose
|
|
194
196
|
// It is recommended to always try a parse with the regular acorn parser first,
|
package/lib/default/options.js
CHANGED
|
@@ -3,11 +3,8 @@ module.exports = {
|
|
|
3
3
|
// {string} logging levels: off, error, info, debug
|
|
4
4
|
logging: 'info',
|
|
5
5
|
|
|
6
|
-
// {string}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
// {string|string[]} input raw dir(s)
|
|
10
|
-
inputDir: null,
|
|
6
|
+
// {string} Report name. Defaults to "Coverage Report".
|
|
7
|
+
name: 'Coverage Report',
|
|
11
8
|
|
|
12
9
|
// {string} v8 or html for istanbul by default
|
|
13
10
|
// {array} multiple reports with options
|
|
@@ -21,17 +18,11 @@ module.exports = {
|
|
|
21
18
|
// ],
|
|
22
19
|
reports: '',
|
|
23
20
|
|
|
24
|
-
// {string}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
// (V8 only) {string} Output [sub dir/]filename. Defaults to "index.html"
|
|
28
|
-
outputFile: 'index.html',
|
|
29
|
-
|
|
30
|
-
// (V8 only) {boolean} Inline all scripts to the single HTML file. Defaults to false.
|
|
31
|
-
inline: false,
|
|
21
|
+
// {string} output dir
|
|
22
|
+
outputDir: './coverage-reports',
|
|
32
23
|
|
|
33
|
-
//
|
|
34
|
-
|
|
24
|
+
// {string|string[]} input raw dir(s)
|
|
25
|
+
inputDir: null,
|
|
35
26
|
|
|
36
27
|
// (V8 only) {function} A filter function to execute for each element in the V8 list.
|
|
37
28
|
// entryFilter: (entry) => {
|
|
@@ -46,6 +37,24 @@ module.exports = {
|
|
|
46
37
|
// sourceFilter: (sourcePath) => sourcePath.search(/src\/.+/) !== -1,
|
|
47
38
|
sourceFilter: null,
|
|
48
39
|
|
|
40
|
+
// {function} Source path handler.
|
|
41
|
+
// sourcePath: (filePath) => `wwwroot/${filePath}`,
|
|
42
|
+
sourcePath: null,
|
|
43
|
+
|
|
44
|
+
// (V8 only) {string} Output [sub dir/]filename. Defaults to "index.html"
|
|
45
|
+
outputFile: 'index.html',
|
|
46
|
+
|
|
47
|
+
// (V8 only) {boolean} Inline all scripts to the single HTML file. Defaults to false.
|
|
48
|
+
inline: false,
|
|
49
|
+
|
|
50
|
+
// (V8 only) {string} Assets path if not inline. Defaults to "./assets"
|
|
51
|
+
assetsPath: './assets',
|
|
52
|
+
|
|
53
|
+
// (Istanbul only) defaultSummarizer, sourceFinder
|
|
54
|
+
|
|
55
|
+
// {boolean} Generate lcov.info file, same as lcovonly report. Defaults to false.
|
|
56
|
+
lcov: false,
|
|
57
|
+
|
|
49
58
|
// options for adding empty coverage for all files
|
|
50
59
|
// all: {
|
|
51
60
|
// dir: ['src'],
|
|
@@ -56,15 +65,6 @@ module.exports = {
|
|
|
56
65
|
// (V8 only) {boolean} Enable/Disable ignoring uncovered codes with the special comments: v8 ignore next/next N/start/stop
|
|
57
66
|
v8Ignore: true,
|
|
58
67
|
|
|
59
|
-
// (Istanbul only) defaultSummarizer, sourceFinder
|
|
60
|
-
|
|
61
|
-
// {boolean} Generate lcov.info file, same as lcovonly report. Defaults to false.
|
|
62
|
-
lcov: false,
|
|
63
|
-
|
|
64
|
-
// {function} Source path handler.
|
|
65
|
-
// sourcePath: (filePath) => `wwwroot/${filePath}`,
|
|
66
|
-
sourcePath: null,
|
|
67
|
-
|
|
68
68
|
// {string|function} Specify the report path, especially when there are multiple reports. Defaults to outputDir/index.html.
|
|
69
69
|
reportPath: null,
|
|
70
70
|
|
|
@@ -78,6 +78,10 @@ module.exports = {
|
|
|
78
78
|
// {boolean} Indicates whether to clean previous cache in output dir before generating report. Defaults to false.
|
|
79
79
|
cleanCache: false,
|
|
80
80
|
|
|
81
|
+
// {function} onEntry hook
|
|
82
|
+
// onEntry: async (entry) => {}
|
|
83
|
+
onEntry: null,
|
|
84
|
+
|
|
81
85
|
// {function} onEnd hook
|
|
82
86
|
// onEnd: async (reportData) => {}
|
|
83
87
|
onEnd: null
|
package/lib/generate.js
CHANGED
|
@@ -288,12 +288,15 @@ const handleConsoleDetailsReport = (reportData, reportOptions, options) => {
|
|
|
288
288
|
} = reportData;
|
|
289
289
|
|
|
290
290
|
if (name) {
|
|
291
|
-
EC.
|
|
291
|
+
Util.logInfo(EC.cyan(name));
|
|
292
292
|
}
|
|
293
293
|
|
|
294
294
|
const metrics = Util.getMetrics(cdOptions.metrics, type);
|
|
295
295
|
const rows = getDetailsRows(files, metrics, cdOptions);
|
|
296
296
|
const summaryRow = getRowData('Summary', summary, metrics);
|
|
297
|
+
if (summaryRow.nameStatus) {
|
|
298
|
+
summaryRow.name = Util.getColorStrByStatus(summaryRow.name, summaryRow.nameStatus);
|
|
299
|
+
}
|
|
297
300
|
// no rows if skipped all by skipPercent
|
|
298
301
|
if (rows.length) {
|
|
299
302
|
rows.push({
|
|
@@ -339,7 +342,7 @@ const handleConsoleSummaryReport = (reportData, reportOptions, options) => {
|
|
|
339
342
|
} = reportData;
|
|
340
343
|
|
|
341
344
|
if (name) {
|
|
342
|
-
EC.
|
|
345
|
+
Util.logInfo(EC.cyan(name));
|
|
343
346
|
}
|
|
344
347
|
|
|
345
348
|
const metrics = Util.getMetrics(csOptions.metrics, type);
|
package/lib/index.d.ts
CHANGED
|
@@ -185,10 +185,10 @@ declare namespace MCR {
|
|
|
185
185
|
js?: boolean;
|
|
186
186
|
/** V8 only */
|
|
187
187
|
data?: {
|
|
188
|
-
bytes
|
|
189
|
-
statements
|
|
190
|
-
branches
|
|
191
|
-
functions
|
|
188
|
+
bytes?: CoverageRange[];
|
|
189
|
+
statements?: CoverageRange[];
|
|
190
|
+
branches?: CoverageRange[];
|
|
191
|
+
functions?: CoverageRange[];
|
|
192
192
|
ignores?: IgnoredRange[];
|
|
193
193
|
/** codecov json format */
|
|
194
194
|
lines: {
|
|
@@ -211,11 +211,8 @@ declare namespace MCR {
|
|
|
211
211
|
/** {string} logging levels: off, error, info, debug */
|
|
212
212
|
logging?: string;
|
|
213
213
|
|
|
214
|
-
/** {string}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
/** {string|string[]} input raw dir(s) */
|
|
218
|
-
inputDir?: string | string[];
|
|
214
|
+
/** {string} Report name. Defaults to "Coverage Report". */
|
|
215
|
+
name?: string;
|
|
219
216
|
|
|
220
217
|
/**
|
|
221
218
|
*
|
|
@@ -224,25 +221,21 @@ declare namespace MCR {
|
|
|
224
221
|
* {array} ['v8'], ['v8', ['console-details', { skipPercent: 80 }]]
|
|
225
222
|
*
|
|
226
223
|
* By default, `v8` for V8 data, `html` for Istanbul data
|
|
227
|
-
|
|
228
|
-
reports?: string | ReportDescription[];
|
|
224
|
+
*/
|
|
225
|
+
reports?: string | string[] | ReportDescription[];
|
|
229
226
|
|
|
230
|
-
/** {string}
|
|
231
|
-
|
|
227
|
+
/** {string} output dir */
|
|
228
|
+
outputDir?: string;
|
|
232
229
|
|
|
233
|
-
/**
|
|
234
|
-
|
|
235
|
-
/** (V8 only) {boolean} Inline all scripts to the single HTML file. Defaults to false. */
|
|
236
|
-
inline?: boolean;
|
|
237
|
-
/** (V8 only) {string} Assets path if not inline. Defaults to "./assets" */
|
|
238
|
-
assetsPath?: string;
|
|
230
|
+
/** {string|string[]} input raw dir(s) */
|
|
231
|
+
inputDir?: string | string[];
|
|
239
232
|
|
|
240
233
|
/** (V8 only)
|
|
241
234
|
*
|
|
242
235
|
* {string} `minimatch` pattern for entry url; {object} multiple patterns;
|
|
243
236
|
*
|
|
244
237
|
* {function} A filter function for each entry file in the V8 list.
|
|
245
|
-
|
|
238
|
+
*/
|
|
246
239
|
entryFilter?: string | {
|
|
247
240
|
[pattern: string]: boolean;
|
|
248
241
|
} | ((entry: V8CoverageEntry) => boolean);
|
|
@@ -252,11 +245,33 @@ declare namespace MCR {
|
|
|
252
245
|
* {string} `minimatch` pattern for source path; {object} multiple patterns;
|
|
253
246
|
*
|
|
254
247
|
* {function} A filter function for each source path when the source is unpacked from the source map.
|
|
255
|
-
|
|
248
|
+
*/
|
|
256
249
|
sourceFilter?: string | {
|
|
257
250
|
[pattern: string]: boolean;
|
|
258
251
|
} | ((sourcePath: string) => boolean);
|
|
259
252
|
|
|
253
|
+
/**
|
|
254
|
+
* {function} Source path handler.
|
|
255
|
+
*
|
|
256
|
+
* {object} Replace key with value.
|
|
257
|
+
* */
|
|
258
|
+
sourcePath?: ((filePath: string) => string) | {
|
|
259
|
+
[key: string]: string;
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
/** (V8 only) {string} Output [sub dir/]filename. Defaults to "index.html" */
|
|
264
|
+
outputFile?: string;
|
|
265
|
+
/** (V8 only) {boolean} Inline all scripts to the single HTML file. Defaults to false. */
|
|
266
|
+
inline?: boolean;
|
|
267
|
+
/** (V8 only) {string} Assets path if not inline. Defaults to "./assets" */
|
|
268
|
+
assetsPath?: string;
|
|
269
|
+
|
|
270
|
+
/** (Istanbul only) defaultSummarizer, sourceFinder */
|
|
271
|
+
|
|
272
|
+
/** {boolean} Generate lcov.info file, same as lcovonly report. Defaults to false. */
|
|
273
|
+
lcov?: boolean;
|
|
274
|
+
|
|
260
275
|
/**
|
|
261
276
|
* options for adding empty coverage for all files
|
|
262
277
|
*/
|
|
@@ -278,20 +293,6 @@ declare namespace MCR {
|
|
|
278
293
|
/** (V8 only) {boolean} Enable/Disable ignoring uncovered codes with the special comments: v8 ignore next/next N/start/stop */
|
|
279
294
|
v8Ignore?: boolean;
|
|
280
295
|
|
|
281
|
-
/** (Istanbul only) defaultSummarizer, sourceFinder */
|
|
282
|
-
|
|
283
|
-
/** {boolean} Generate lcov.info file, same as lcovonly report. Defaults to false. */
|
|
284
|
-
lcov?: boolean;
|
|
285
|
-
|
|
286
|
-
/**
|
|
287
|
-
* {function} Source path handler.
|
|
288
|
-
*
|
|
289
|
-
* {object} Replace key with value.
|
|
290
|
-
* */
|
|
291
|
-
sourcePath?: ((filePath: string) => string) | {
|
|
292
|
-
[key: string]: string;
|
|
293
|
-
};
|
|
294
|
-
|
|
295
296
|
/** {string|function} Specify the report path, especially when there are multiple reports. Defaults to outputDir/index.html. */
|
|
296
297
|
reportPath?: string | (() => string);
|
|
297
298
|
|
|
@@ -299,11 +300,15 @@ declare namespace MCR {
|
|
|
299
300
|
* {object} { bytes:[50,80], statements:[50,80], branches:[50,80], functions:[50,80], lines:[50,80] } */
|
|
300
301
|
watermarks?: Watermarks;
|
|
301
302
|
|
|
302
|
-
/**
|
|
303
|
+
/**
|
|
304
|
+
* {boolean} Indicates whether to clean previous reports in output dir before generating new reports. Defaults to true.
|
|
305
|
+
*
|
|
306
|
+
* If true, the API `clean()` will execute automatically.
|
|
307
|
+
* */
|
|
303
308
|
clean?: boolean;
|
|
304
309
|
|
|
305
310
|
/**
|
|
306
|
-
* {boolean} Indicates whether to clean previous cache in output dir
|
|
311
|
+
* {boolean} Indicates whether to clean previous cache in output dir on start. Defaults to false.
|
|
307
312
|
*
|
|
308
313
|
* If true, the API `cleanCache()` will execute automatically.
|
|
309
314
|
*/
|
|
@@ -319,10 +324,10 @@ declare namespace MCR {
|
|
|
319
324
|
|
|
320
325
|
export interface McrCliOptions extends CoverageReportOptions {
|
|
321
326
|
|
|
322
|
-
/** (
|
|
327
|
+
/** (CLI only) {function} onStart hook */
|
|
323
328
|
onStart?: (coverageReport: CoverageReport) => Promise<void>;
|
|
324
329
|
|
|
325
|
-
/** (
|
|
330
|
+
/** (CLI only) {function} onReady hook before adding coverage data.
|
|
326
331
|
*
|
|
327
332
|
* Sometimes, the child process has not yet finished writing the coverage data, and it needs to wait here.
|
|
328
333
|
*/
|
|
@@ -332,9 +337,14 @@ declare namespace MCR {
|
|
|
332
337
|
|
|
333
338
|
export class CoverageReport {
|
|
334
339
|
|
|
340
|
+
/**
|
|
341
|
+
* @param options coverage report options
|
|
342
|
+
*/
|
|
335
343
|
constructor(options?: CoverageReportOptions);
|
|
336
344
|
|
|
337
|
-
/** add coverage data
|
|
345
|
+
/** add coverage data
|
|
346
|
+
*
|
|
347
|
+
* @param coverageData {array} V8 format, {object} Istanbul format */
|
|
338
348
|
add: (coverageData: any[] | any) => Promise<AddedResults>;
|
|
339
349
|
|
|
340
350
|
/** generate report */
|
|
@@ -345,6 +355,27 @@ declare namespace MCR {
|
|
|
345
355
|
|
|
346
356
|
/** clean previous cache, return `false` if no cache */
|
|
347
357
|
cleanCache: () => boolean;
|
|
358
|
+
|
|
359
|
+
/** clean previous reports except cache dir and v8 coverage dir */
|
|
360
|
+
clean: () => void;
|
|
361
|
+
|
|
362
|
+
/** get entry filter handler, it can be used to filter the coverage data list before adding it. */
|
|
363
|
+
getEntryFilter: () => ((entry: V8CoverageEntry) => boolean);
|
|
364
|
+
|
|
365
|
+
/** load config file.
|
|
366
|
+
*
|
|
367
|
+
* @param configFile custom config file path
|
|
368
|
+
*
|
|
369
|
+
* Supports loading default config file if no custom config specified:
|
|
370
|
+
'mcr.config.js',
|
|
371
|
+
'mcr.config.cjs',
|
|
372
|
+
'mcr.config.mjs',
|
|
373
|
+
'mcr.config.json',
|
|
374
|
+
'.mcrrc.js',
|
|
375
|
+
'.mcrrc',
|
|
376
|
+
'mcr.config.ts'
|
|
377
|
+
*/
|
|
378
|
+
loadConfig: (configFile?: string) => Promise<void>;
|
|
348
379
|
}
|
|
349
380
|
|
|
350
381
|
export interface CoverageSnapshot {
|