monocart-coverage-reports 2.7.1 → 2.7.3
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 +14 -8
- package/lib/cli.js +74 -88
- package/lib/converter/collect-source-maps.js +12 -1
- package/lib/converter/find-original-range.js +97 -94
- package/lib/generate.js +130 -1
- package/lib/index.d.ts +6 -0
- package/lib/index.js +20 -6
- package/lib/packages/monocart-coverage-v8.js +1 -1
- package/lib/register/hooks.js +58 -0
- package/lib/register/hooks.mjs +3 -0
- package/lib/register/register.js +4 -0
- package/lib/register/register.mjs +3 -0
- package/lib/utils/source-path.js +30 -14
- package/package.json +97 -83
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const Util = require('../utils/util.js');
|
|
4
|
+
const { convertSourceMap } = require('../packages/monocart-coverage-vendor.js');
|
|
5
|
+
|
|
6
|
+
function saveFile(url, source, dir) {
|
|
7
|
+
if (!fs.existsSync(dir)) {
|
|
8
|
+
fs.mkdirSync(dir, {
|
|
9
|
+
recursive: true
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const id = Util.calculateSha1(url + source);
|
|
14
|
+
const filePath = path.resolve(dir, `source-${id}.json`);
|
|
15
|
+
if (!fs.existsSync(filePath)) {
|
|
16
|
+
fs.writeFileSync(filePath, JSON.stringify({
|
|
17
|
+
url,
|
|
18
|
+
source
|
|
19
|
+
}));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function saveSource(url, loaded, dir) {
|
|
25
|
+
|
|
26
|
+
// filter node modules
|
|
27
|
+
if (url.startsWith('node:')) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const { source, format } = loaded;
|
|
32
|
+
if (typeof source !== 'string' || !['module', 'commonjs'].includes(format)) {
|
|
33
|
+
// no source or wrong format
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (!convertSourceMap.mapFileCommentRegex.test(source)) {
|
|
38
|
+
// no sourcemap
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
saveFile(url, source, dir);
|
|
43
|
+
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async function load(url, context, nextLoad) {
|
|
47
|
+
const loaded = await nextLoad(url, context);
|
|
48
|
+
const dir = process.env.NODE_V8_COVERAGE;
|
|
49
|
+
if (dir) {
|
|
50
|
+
// only for coverage enabled
|
|
51
|
+
saveSource(url, loaded, dir);
|
|
52
|
+
}
|
|
53
|
+
return loaded;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
module.exports = {
|
|
57
|
+
load
|
|
58
|
+
};
|
package/lib/utils/source-path.js
CHANGED
|
@@ -141,27 +141,43 @@ const initIstanbulSourcePath = (coverageData, fileSources, sourcePathHandler) =>
|
|
|
141
141
|
|
|
142
142
|
// ========================================================================================================
|
|
143
143
|
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
144
|
+
const resolveSourceUrl = (sourceName, sourceRoot) => {
|
|
145
|
+
|
|
146
|
+
// could be absolute path
|
|
147
|
+
// c:\\workspace\test\\selenium.spec.js
|
|
148
|
+
// a.js false
|
|
149
|
+
// c://a.js true
|
|
150
|
+
// ws://a.js false
|
|
151
|
+
|
|
152
|
+
if (path.isAbsolute(sourceName)) {
|
|
153
|
+
return pathToFileURL(sourceName).toString();
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// webpack://coverage-v8/./test/mock/src/branch/branch.js
|
|
157
|
+
// webpack://monocart-v8/../starfall-cli/node_modules/css-loader/dist/runtime/api.js
|
|
158
|
+
|
|
159
|
+
// as url
|
|
160
|
+
const urlObj = Util.resolveUrl(sourceName);
|
|
161
|
+
if (urlObj) {
|
|
162
|
+
return urlObj.toString();
|
|
147
163
|
}
|
|
148
|
-
|
|
164
|
+
|
|
165
|
+
// as relative path, join sourceRoot
|
|
166
|
+
if (sourceRoot && !sourceName.startsWith(sourceRoot)) {
|
|
167
|
+
sourceName = path.join(sourceRoot, sourceName);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
sourceName = path.normalize(sourceName);
|
|
171
|
+
const sourceUrl = pathToFileURL(sourceName).toString();
|
|
172
|
+
|
|
173
|
+
return sourceUrl;
|
|
149
174
|
};
|
|
150
175
|
|
|
151
176
|
const initSourceMapSourcePath = (sourceMap, fileUrls, distFile, sourcePathHandler) => {
|
|
152
|
-
// reset sourceRoot
|
|
153
|
-
const sourceRoot = sourceMap.sourceRoot || '';
|
|
154
|
-
sourceMap.sourceRoot = '';
|
|
155
177
|
|
|
156
178
|
sourceMap.sources = sourceMap.sources.map((sourceName, i) => {
|
|
157
179
|
|
|
158
|
-
|
|
159
|
-
// c:\\workspace\test\\selenium.spec.js
|
|
160
|
-
// console.log(sourceName);
|
|
161
|
-
sourceName = Util.formatPath(sourceName);
|
|
162
|
-
// console.log(sourceName);
|
|
163
|
-
|
|
164
|
-
const sourceUrl = mergeSourceRoot(sourceRoot, sourceName);
|
|
180
|
+
const sourceUrl = resolveSourceUrl(sourceName, sourceMap.sourceRoot);
|
|
165
181
|
|
|
166
182
|
let sourcePath = getSourcePath(sourceUrl, i + 1);
|
|
167
183
|
if (sourcePathHandler) {
|
package/package.json
CHANGED
|
@@ -1,83 +1,97 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "monocart-coverage-reports",
|
|
3
|
-
"version": "2.7.
|
|
4
|
-
"description": "
|
|
5
|
-
"main": "./lib/index.js",
|
|
6
|
-
"bin": {
|
|
7
|
-
"mcr": "./lib/cli.js"
|
|
8
|
-
},
|
|
9
|
-
"exports": {
|
|
10
|
-
".": {
|
|
11
|
-
"types": "./lib/index.d.ts",
|
|
12
|
-
"import": "./lib/index.mjs",
|
|
13
|
-
"require": "./lib/index.js",
|
|
14
|
-
"default": "./lib/index.js"
|
|
15
|
-
},
|
|
16
|
-
"./
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
"
|
|
28
|
-
"test
|
|
29
|
-
"
|
|
30
|
-
"test-node-
|
|
31
|
-
"test-
|
|
32
|
-
"test-
|
|
33
|
-
"test-
|
|
34
|
-
"test-
|
|
35
|
-
"test-
|
|
36
|
-
"test-
|
|
37
|
-
"test-
|
|
38
|
-
"test-
|
|
39
|
-
"test-
|
|
40
|
-
"test-
|
|
41
|
-
"test-
|
|
42
|
-
"test": "
|
|
43
|
-
"test
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
"
|
|
50
|
-
"test"
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
"
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
},
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
"
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
"
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
"
|
|
79
|
-
"
|
|
80
|
-
"
|
|
81
|
-
"
|
|
82
|
-
}
|
|
83
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "monocart-coverage-reports",
|
|
3
|
+
"version": "2.7.3",
|
|
4
|
+
"description": "A code coverage tool to generate native V8 reports or Istanbul reports.",
|
|
5
|
+
"main": "./lib/index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"mcr": "./lib/cli.js"
|
|
8
|
+
},
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./lib/index.d.ts",
|
|
12
|
+
"import": "./lib/index.mjs",
|
|
13
|
+
"require": "./lib/index.js",
|
|
14
|
+
"default": "./lib/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./register": {
|
|
17
|
+
"import": "./lib/register/register.mjs",
|
|
18
|
+
"require": "./lib/register/register.js",
|
|
19
|
+
"default": "./lib/register/register.js"
|
|
20
|
+
},
|
|
21
|
+
"./converter": "./lib/converter/converter.js",
|
|
22
|
+
"./util": "./lib/utils/util.js",
|
|
23
|
+
"./package.json": "./package.json"
|
|
24
|
+
},
|
|
25
|
+
"types": "./lib/index.d.ts",
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build-docs": "node ./scripts/build-docs.js",
|
|
28
|
+
"build-test": "node ./scripts/build-test.js",
|
|
29
|
+
"build": "sf lint && sf b -p && npm run build-test",
|
|
30
|
+
"test-node-env": "cross-env NODE_V8_COVERAGE=.temp/v8-coverage-env node ./test/test-node-env.js && node ./test/generate-report.js",
|
|
31
|
+
"test-node-api": "cross-env NODE_V8_COVERAGE=.temp/v8-coverage-api node ./test/test-node-api.js",
|
|
32
|
+
"test-node-ins": "node ./test/test-node-ins.js",
|
|
33
|
+
"test-node-cdp": "node --inspect=9229 ./test/test-node-cdp.js",
|
|
34
|
+
"test-node-vm": "node ./test/test-node-vm.js",
|
|
35
|
+
"test-node-koa": "node ./test/test-node-koa.js",
|
|
36
|
+
"test-node-fgc": "node ./test/test-node-fgc.js",
|
|
37
|
+
"test-node": "npm run test-node-env && npm run test-node-api && npm run test-node-ins && npm run test-node-cdp && npm run test-node-vm && npm run test-node-koa",
|
|
38
|
+
"test-istanbul": "node ./test/test-istanbul.js",
|
|
39
|
+
"test-v8": "node ./test/test-v8.js",
|
|
40
|
+
"test-puppeteer": "node ./test/test-puppeteer.js",
|
|
41
|
+
"test-anonymous": "node ./test/test-anonymous.js",
|
|
42
|
+
"test-css": "node ./test/test-css.js",
|
|
43
|
+
"test-minify": "node ./test/test-minify.js",
|
|
44
|
+
"test-esbuild": "node ./test/test-esbuild.js",
|
|
45
|
+
"test-rollup": "node ./test/test-rollup.js",
|
|
46
|
+
"test-v8-and-istanbul": "node ./test/test-v8-and-istanbul.js",
|
|
47
|
+
"test-browser": "npm run test-istanbul && npm run test-v8 && npm run test-puppeteer && npm run test-anonymous && npm run test-css && npm run test-minify && npm run test-esbuild && npm run test-rollup && npm run test-v8-and-istanbul",
|
|
48
|
+
"test-cli": "npx mcr node ./test/specs/node.test.js -c test/mcr.config.cli.js",
|
|
49
|
+
"test-tsx": "npx mcr tsx ./test/specs/tsx.test.ts -c test/mcr.config.tsx.js",
|
|
50
|
+
"test-merge": "node ./test/test-merge.js",
|
|
51
|
+
"test-merge-istanbul": "node ./test/test-merge-istanbul.js",
|
|
52
|
+
"test-client": "node ./test/test-client.js",
|
|
53
|
+
"test-all": "npm run test-node && npm run test-browser && npm run test-cli && npm run test-tsx && npm run test-merge && npm run build-docs",
|
|
54
|
+
"test": "npx mcr npm run test-all -c test/mcr.config.mcr.js",
|
|
55
|
+
"test:snap": "cross-env TEST_SNAPSHOT=true npm run test",
|
|
56
|
+
"dev": "sf d v8",
|
|
57
|
+
"open": "node ./scripts/open.js",
|
|
58
|
+
"patch": "npm run build && npm run test && sf publish patch -r"
|
|
59
|
+
},
|
|
60
|
+
"workspaces": [
|
|
61
|
+
"packages/*",
|
|
62
|
+
"test"
|
|
63
|
+
],
|
|
64
|
+
"files": [
|
|
65
|
+
"lib"
|
|
66
|
+
],
|
|
67
|
+
"license": "MIT",
|
|
68
|
+
"repository": {
|
|
69
|
+
"type": "git",
|
|
70
|
+
"url": "git+https://github.com/cenfun/monocart-coverage-reports.git"
|
|
71
|
+
},
|
|
72
|
+
"dependencies": {
|
|
73
|
+
"console-grid": "^2.2.2",
|
|
74
|
+
"eight-colors": "^1.3.0",
|
|
75
|
+
"istanbul-lib-coverage": "^3.2.2",
|
|
76
|
+
"istanbul-lib-report": "^3.0.1",
|
|
77
|
+
"istanbul-reports": "^3.1.7",
|
|
78
|
+
"lz-utils": "^2.0.2",
|
|
79
|
+
"monocart-code-viewer": "^1.1.2",
|
|
80
|
+
"monocart-formatter": "^2.3.2",
|
|
81
|
+
"turbogrid": "^3.0.13"
|
|
82
|
+
},
|
|
83
|
+
"devDependencies": {
|
|
84
|
+
"commander": "^12.0.0",
|
|
85
|
+
"esbuild": "^0.20.2",
|
|
86
|
+
"eslint": "^8.57.0",
|
|
87
|
+
"eslint-config-plus": "^1.0.6",
|
|
88
|
+
"eslint-plugin-html": "^8.0.0",
|
|
89
|
+
"eslint-plugin-vue": "^9.23.0",
|
|
90
|
+
"minimatch": "^9.0.3",
|
|
91
|
+
"stylelint": "^16.2.1",
|
|
92
|
+
"stylelint-config-plus": "^1.1.0",
|
|
93
|
+
"supports-color": "^9.4.0",
|
|
94
|
+
"tsx": "^4.7.1",
|
|
95
|
+
"ws": "^8.16.0"
|
|
96
|
+
}
|
|
97
|
+
}
|