monocart-coverage-reports 2.13.2 → 3.0.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/README.md +267 -114
- package/README.zh-Hans.md +268 -115
- package/lib/assets.js +6 -6
- package/lib/cli.js +191 -95
- package/lib/client/cdp-client.js +74 -43
- package/lib/client/coverage-client.js +24 -8
- package/lib/client/ws-session.js +115 -37
- package/lib/converter/ast-visitor.js +5 -7
- package/lib/converter/ast.js +6 -6
- package/lib/converter/collect-source-maps.js +9 -9
- package/lib/converter/converter.js +41 -115
- package/lib/converter/fake-source-coverage.js +64 -0
- package/lib/converter/find-original-range.js +3 -3
- package/lib/converter/flatten-source-maps.js +2 -4
- package/lib/converter/ignore.js +2 -4
- package/lib/converter/info-branch.js +5 -3
- package/lib/converter/info-function.js +5 -3
- package/lib/converter/info-statement.js +5 -3
- package/lib/converter/range-index.js +78 -0
- package/lib/converter/source-range-merge.js +103 -0
- package/lib/converter/untested.js +27 -55
- package/lib/default/options.js +13 -1
- package/lib/generate.js +44 -26
- package/lib/index.d.ts +52 -4
- package/lib/index.js +35 -41
- package/lib/istanbul/istanbul-summary.js +2 -2
- package/lib/istanbul/istanbul.js +35 -13
- package/lib/packages/chunks/chunk-RVOSNMVU.js +2 -0
- package/lib/packages/monocart-coverage-assets.js +4 -3
- package/lib/packages/monocart-coverage-converter.js +27 -0
- package/lib/packages/monocart-coverage-vendor.js +2 -41
- package/lib/packages/monocart-coverage-vendor.js.LICENSE +3 -221
- package/lib/platform/concurrency.js +47 -43
- package/lib/platform/share.js +1 -1
- package/lib/register/hooks.js +19 -13
- package/lib/register/register.js +5 -3
- package/lib/reports/codacy.js +3 -5
- package/lib/reports/codecov.js +3 -5
- package/lib/reports/console-details.js +5 -5
- package/lib/reports/console-summary.js +4 -4
- package/lib/reports/custom.js +8 -24
- package/lib/reports/markdown-details.js +4 -6
- package/lib/reports/markdown-summary.js +4 -6
- package/lib/reports/raw.js +10 -12
- package/lib/reports/v8-json.js +3 -5
- package/lib/reports/v8.js +3 -5
- package/lib/utils/dedupe.js +1 -1
- package/lib/utils/gc.js +30 -14
- package/lib/utils/markdown.js +2 -2
- package/lib/utils/merge/merge.js +2 -4
- package/lib/utils/merge/range-tree.js +1 -1
- package/lib/utils/request.js +85 -73
- package/lib/utils/snapshot.js +4 -4
- package/lib/utils/source-path.js +5 -5
- package/lib/utils/util.js +61 -41
- package/lib/v8/v8-summary.js +2 -4
- package/lib/v8/v8.js +11 -11
- package/migrate-to-3.md +175 -0
- package/package.json +153 -149
- package/skills/monocart-coverage-reports/SKILL.md +106 -0
- package/skills/monocart-coverage-reports/references/cli.md +108 -0
- package/skills/monocart-coverage-reports/references/collection.md +152 -0
- package/skills/monocart-coverage-reports/references/filtering-and-sourcemaps.md +170 -0
- package/skills/monocart-coverage-reports/references/reports-and-ci.md +219 -0
- package/skills/monocart-coverage-reports/references/repository-map.md +55 -0
- package/lib/index.mjs +0 -9
- package/lib/register/hooks.mjs +0 -3
- package/lib/register/register.mjs +0 -3
package/lib/index.js
CHANGED
|
@@ -1,46 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { pathToFileURL } from 'node:url';
|
|
4
|
+
import EC from 'eight-colors';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
import { defaultOptions } from './default/options.js';
|
|
7
|
+
import { Util } from './utils/util.js';
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
import { initV8ListAndSourcemap } from './v8/v8.js';
|
|
10
|
+
import {
|
|
11
11
|
getInputData, readFromDir, generateCoverageReports
|
|
12
|
-
}
|
|
13
|
-
|
|
12
|
+
} from './generate.js';
|
|
13
|
+
import { getSnapshot, diffSnapshot } from './utils/snapshot.js';
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
import { WSSession } from './client/ws-session.js';
|
|
16
|
+
import { CDPClient } from './client/cdp-client.js';
|
|
17
|
+
import { CoverageClient } from './client/coverage-client.js';
|
|
17
18
|
|
|
18
19
|
const resolveConfigOptions = async (configPath) => {
|
|
19
|
-
// json format
|
|
20
|
-
const ext = path.extname(configPath);
|
|
21
|
-
if (ext === '.json' || configPath.slice(-2) === 'rc') {
|
|
22
|
-
return JSON.parse(Util.readFileSync(configPath));
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
let configOptions;
|
|
26
|
-
let err;
|
|
27
20
|
try {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if (err) {
|
|
34
|
-
Util.logError(`ERROR: failed to load config "${configPath}": ${err && err.message} `);
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
21
|
+
// json format
|
|
22
|
+
const ext = path.extname(configPath);
|
|
23
|
+
if (ext === '.json' || configPath.slice(-2) === 'rc') {
|
|
24
|
+
return JSON.parse(Util.readFileSync(configPath));
|
|
25
|
+
}
|
|
37
26
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
configOptions
|
|
27
|
+
let configOptions = await import(pathToFileURL(configPath));
|
|
28
|
+
// could be multiple level default
|
|
29
|
+
while (configOptions && configOptions.default) {
|
|
30
|
+
configOptions = configOptions.default;
|
|
31
|
+
}
|
|
32
|
+
return configOptions;
|
|
33
|
+
} catch (error) {
|
|
34
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
35
|
+
throw new Error(`Failed to load config file "${configPath}": ${message}`, {
|
|
36
|
+
cause: error
|
|
37
|
+
});
|
|
41
38
|
}
|
|
42
|
-
|
|
43
|
-
return configOptions;
|
|
44
39
|
};
|
|
45
40
|
|
|
46
41
|
class CoverageReport {
|
|
@@ -237,7 +232,7 @@ class CoverageReport {
|
|
|
237
232
|
const configPath = Util.findUpConfig(customConfigFile);
|
|
238
233
|
if (!configPath) {
|
|
239
234
|
if (customConfigFile) {
|
|
240
|
-
|
|
235
|
+
throw new Error(`The config file does not exist: ${customConfigFile}`);
|
|
241
236
|
}
|
|
242
237
|
// not found config
|
|
243
238
|
return;
|
|
@@ -245,11 +240,7 @@ class CoverageReport {
|
|
|
245
240
|
|
|
246
241
|
const configOptions = await resolveConfigOptions(configPath);
|
|
247
242
|
if (!configOptions) {
|
|
248
|
-
|
|
249
|
-
if (customConfigFile) {
|
|
250
|
-
Util.logError(`Failed to load config file: ${customConfigFile}`);
|
|
251
|
-
}
|
|
252
|
-
return;
|
|
243
|
+
throw new Error(`Failed to load config file: ${configPath}`);
|
|
253
244
|
}
|
|
254
245
|
|
|
255
246
|
Util.logInfo(`Loaded: ${EC.cyan(Util.relativePath(configPath))}`);
|
|
@@ -271,10 +262,13 @@ const MCR = function(options) {
|
|
|
271
262
|
return new CoverageReport(options);
|
|
272
263
|
};
|
|
273
264
|
MCR.CoverageReport = CoverageReport;
|
|
265
|
+
MCR.CoverageClient = CoverageClient;
|
|
274
266
|
MCR.getSnapshot = getSnapshot;
|
|
275
267
|
MCR.diffSnapshot = diffSnapshot;
|
|
276
268
|
MCR.WSSession = WSSession;
|
|
277
269
|
MCR.CDPClient = CDPClient;
|
|
278
270
|
MCR.Util = Util;
|
|
279
271
|
|
|
280
|
-
|
|
272
|
+
export {
|
|
273
|
+
MCR as default, MCR, CoverageReport, CoverageClient, getSnapshot, diffSnapshot, WSSession, CDPClient, Util
|
|
274
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import istanbulLibReport from 'istanbul-lib-report';
|
|
2
2
|
|
|
3
3
|
const ReportBase = istanbulLibReport.ReportBase;
|
|
4
4
|
class IstanbulSummary extends ReportBase {
|
|
@@ -70,4 +70,4 @@ class IstanbulSummary extends ReportBase {
|
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
export { IstanbulSummary };
|
package/lib/istanbul/istanbul.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { pathToFileURL } from 'node:url';
|
|
4
|
+
import istanbulLibCoverage from 'istanbul-lib-coverage';
|
|
5
|
+
import istanbulLibReport from 'istanbul-lib-report';
|
|
6
|
+
import EC from 'eight-colors';
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
import { Util } from '../utils/util.js';
|
|
9
|
+
import { IstanbulSummary } from './istanbul-summary.js';
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
import { initIstanbulSourcePath } from '../utils/source-path.js';
|
|
12
|
+
import { getUntestedList } from '../converter/untested.js';
|
|
13
13
|
|
|
14
14
|
const findHtmlPath = (outputDir) => {
|
|
15
15
|
const defaultHtml = path.resolve(outputDir, 'index.html');
|
|
@@ -35,7 +35,29 @@ const findHtmlPath = (outputDir) => {
|
|
|
35
35
|
|
|
36
36
|
};
|
|
37
37
|
|
|
38
|
-
const
|
|
38
|
+
const createIstanbulReport = async (name, options) => {
|
|
39
|
+
let reporter;
|
|
40
|
+
const isFile = path.isAbsolute(name) || name.startsWith('.');
|
|
41
|
+
// Built-in reports remain CommonJS dependencies; custom reports may be ESM.
|
|
42
|
+
if (!isFile) {
|
|
43
|
+
try {
|
|
44
|
+
reporter = await import(`istanbul-reports/lib/${name}/index.js`);
|
|
45
|
+
} catch (error) {
|
|
46
|
+
if (error.code !== 'ERR_MODULE_NOT_FOUND') {
|
|
47
|
+
throw error;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (!reporter) {
|
|
52
|
+
// Native import() also handles CJS reporters without a separate loader.
|
|
53
|
+
const specifier = isFile ? pathToFileURL(path.resolve(name)).href : name;
|
|
54
|
+
reporter = await import(specifier);
|
|
55
|
+
}
|
|
56
|
+
const Reporter = reporter.default || reporter;
|
|
57
|
+
return new Reporter(options);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const saveIstanbulReports = async (coverageData, fileSources, options) => {
|
|
39
61
|
|
|
40
62
|
coverageData = initIstanbulSourcePath(coverageData, fileSources, options);
|
|
41
63
|
|
|
@@ -96,7 +118,7 @@ const saveIstanbulReports = (coverageData, fileSources, options) => {
|
|
|
96
118
|
if (istanbulGroup) {
|
|
97
119
|
for (const [reportName, reportOptions] of istanbulGroup) {
|
|
98
120
|
const t1 = Date.now();
|
|
99
|
-
const report =
|
|
121
|
+
const report = await createIstanbulReport(reportName, reportOptions);
|
|
100
122
|
report.execute(context);
|
|
101
123
|
Util.logTime(`${EC.magenta('├')} [generate] saved report: ${reportName}`, t1);
|
|
102
124
|
}
|
|
@@ -163,7 +185,7 @@ const mergeIstanbulCoverage = async (dataList, options) => {
|
|
|
163
185
|
return istanbulData;
|
|
164
186
|
};
|
|
165
187
|
|
|
166
|
-
|
|
188
|
+
export {
|
|
167
189
|
saveIstanbulReports,
|
|
168
190
|
mergeIstanbulDataList,
|
|
169
191
|
mergeIstanbulCoverage
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
|
|
2
|
+
var g=Object.create;var f=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var i=Object.getOwnPropertyNames;var j=Object.getPrototypeOf,k=Object.prototype.hasOwnProperty;var m=(a=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(a,{get:(b,c)=>(typeof require<"u"?require:b)[c]}):a)(function(a){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+a+'" is not supported')});var n=(a,b)=>()=>{try{return b||a((b={exports:{}}).exports,b),b.exports}catch(c){throw b=0,c}};var l=(a,b,c,e)=>{if(b&&typeof b=="object"||typeof b=="function")for(let d of i(b))!k.call(a,d)&&d!==c&&f(a,d,{get:()=>b[d],enumerable:!(e=h(b,d))||e.enumerable});return a};var o=(a,b,c)=>(c=a!=null?g(j(a)):{},l(b||!a||!a.__esModule?f(c,"default",{value:a,enumerable:!0}):c,a));export{m as a,n as b,o as c};
|