monocart-coverage-reports 2.8.1 → 2.8.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.
@@ -2,7 +2,40 @@ const path = require('path');
2
2
  const { fileURLToPath, pathToFileURL } = require('url');
3
3
  const Util = require('./util.js');
4
4
 
5
+ const resolveSourceRootUrl = (sourceName, sourceRoot) => {
6
+ // prepend sourceRoot
7
+ if (sourceRoot && !sourceName.startsWith(sourceRoot)) {
8
+ if (!sourceRoot.endsWith('/')) {
9
+ sourceRoot += '/';
10
+ }
11
+ return sourceRoot + sourceName;
12
+ }
13
+ return sourceName;
14
+ };
15
+
16
+ const resolveAnonymousUrl = (url, index, type) => {
17
+ if (url) {
18
+ return url;
19
+ }
20
+ // anonymous scripts will have __playwright_evaluation_script__ as their URL.
21
+ const list = ['anonymous'];
22
+ if (index) {
23
+ list.push(`-${index}`);
24
+ }
25
+ if (type) {
26
+ list.push(`.${type}`);
27
+ }
28
+ return list.join('');
29
+ };
30
+
5
31
  const filterPath = (str) => {
32
+ // double \\ to /
33
+
34
+ // src/images/icons/ sync \.svg$
35
+ // src/images/icons/sync-.svg$
36
+
37
+ str = str.replace(/\\\\/g, '/');
38
+ // decodeURI("%20") to space
6
39
  str = decodeURI(str);
7
40
  // remove / of start, end or double, ./ ../
8
41
  const ls = str.split('/').map((it) => {
@@ -21,24 +54,42 @@ const filterPath = (str) => {
21
54
  return ls.join('/');
22
55
  };
23
56
 
24
- // eslint-disable-next-line complexity
25
- const normalizeSourcePath = (url, baseDir, index = '', type = '') => {
57
+ const normalizeSourcePath = (sourceUrl, baseDir) => {
58
+
59
+ // includes anonymous and everything
26
60
 
27
- // no url for anonymous
28
- if (!url) {
29
- // anonymous scripts will have __playwright_evaluation_script__ as their URL.
30
- url = ['anonymous', index ? `-${index}` : '', type ? `.${type}` : ''].join('');
31
- return filterPath(url);
61
+ // file url
62
+ if (sourceUrl.startsWith('file:')) {
63
+ const relPath = Util.relativePath(fileURLToPath(sourceUrl), baseDir);
64
+ return filterPath(relPath);
32
65
  }
33
66
 
34
- // already is file url
35
- if (url.startsWith('file:')) {
36
- const relPath = Util.relativePath(fileURLToPath(url), baseDir);
67
+ // absolute path
68
+ // c:\\workspace\test\\selenium.spec.js true
69
+ // c://a.js true
70
+ // c:\\a.js true
71
+ // C:/a.js true
72
+ // /a.js true
73
+
74
+ // a.js false
75
+ // ws://a.js false
76
+ // file://a.js false
77
+ // http://a.com/a.js false
78
+ // webpack://src/a.js false
79
+
80
+ if (path.isAbsolute(sourceUrl)) {
81
+ const relPath = Util.relativePath(sourceUrl, baseDir);
37
82
  return filterPath(relPath);
38
83
  }
39
84
 
40
- // http/https url, other url
41
- const urlObj = Util.resolveUrl(url);
85
+ // ws://a.js
86
+ // http://127.0.0:8080/a.js
87
+ // https://127.0.0:8080/a.js?v=1
88
+ // webpack://coverage-v8/./test/mock/src/branch/branch.js
89
+ // webpack://monocart-v8/../starfall-cli/node_modules/css-loader/dist/runtime/api.js
90
+
91
+ // url http/https/webpack
92
+ const urlObj = Util.resolveUrl(sourceUrl);
42
93
  if (urlObj) {
43
94
  const host = [urlObj.hostname, urlObj.port].filter((it) => it).join('-');
44
95
  // always start with '/'
@@ -53,11 +104,10 @@ const normalizeSourcePath = (url, baseDir, index = '', type = '') => {
53
104
  return filterPath(p);
54
105
  }
55
106
 
56
- // could be path
57
- const fileUrl = pathToFileURL(url).toString();
107
+ // relative path
108
+ const fileUrl = pathToFileURL(sourceUrl).toString();
58
109
  const relPath = Util.relativePath(fileURLToPath(fileUrl), baseDir);
59
110
  return filterPath(relPath);
60
-
61
111
  };
62
112
 
63
113
  const getSourceType = (sourcePath) => {
@@ -144,45 +194,6 @@ const initIstanbulSourcePath = (coverageData, fileSources, options) => {
144
194
 
145
195
  // ========================================================================================================
146
196
 
147
- const resolveSourceUrl = (sourceName, sourceRoot) => {
148
-
149
- // prepend sourceRoot
150
- if (sourceRoot && !sourceName.startsWith(sourceRoot)) {
151
- if (!sourceRoot.endsWith('/')) {
152
- sourceRoot += '/';
153
- }
154
- sourceName = sourceRoot + sourceName;
155
- }
156
-
157
- // could be absolute path
158
- // c:\\workspace\test\\selenium.spec.js
159
- // a.js false
160
- // c://a.js true
161
- // ws://a.js false
162
-
163
- if (path.isAbsolute(sourceName)) {
164
- return pathToFileURL(sourceName).toString();
165
- }
166
-
167
- // webpack://coverage-v8/./test/mock/src/branch/branch.js
168
- // webpack://monocart-v8/../starfall-cli/node_modules/css-loader/dist/runtime/api.js
169
-
170
- // as url
171
- const urlObj = Util.resolveUrl(sourceName);
172
- if (urlObj) {
173
- return urlObj.toString();
174
- }
175
-
176
- // console.log('sourceName', sourceName);
177
-
178
- // as relative path
179
- const sourceUrl = pathToFileURL(sourceName).toString();
180
-
181
- // console.log('sourceUrl', sourceUrl);
182
-
183
- return sourceUrl;
184
- };
185
-
186
197
  const initSourceMapSourcesPath = (fileUrls, sourceMap, distFile, options) => {
187
198
 
188
199
  const baseDir = options.baseDir;
@@ -190,9 +201,9 @@ const initSourceMapSourcesPath = (fileUrls, sourceMap, distFile, options) => {
190
201
 
191
202
  sourceMap.sources = sourceMap.sources.map((sourceName, i) => {
192
203
 
193
- const sourceUrl = resolveSourceUrl(sourceName, sourceMap.sourceRoot);
194
-
195
- let sourcePath = normalizeSourcePath(sourceUrl, baseDir, i + 1);
204
+ let sourceUrl = resolveSourceRootUrl(sourceName, sourceMap.sourceRoot);
205
+ sourceUrl = resolveAnonymousUrl(sourceUrl, i + 1, 'js');
206
+ let sourcePath = normalizeSourcePath(sourceUrl, baseDir);
196
207
  // console.log(sourceUrl, sourcePath);
197
208
 
198
209
  if (sourcePathReplacer) {
@@ -213,9 +224,7 @@ const initSourceMapSourcesPath = (fileUrls, sourceMap, distFile, options) => {
213
224
  };
214
225
 
215
226
  module.exports = {
216
- // for unit test
217
- resolveSourceUrl,
218
-
227
+ resolveAnonymousUrl,
219
228
  normalizeSourcePath,
220
229
  getSourceType,
221
230
  getSourcePathReplacer,
package/lib/v8/v8.js CHANGED
@@ -3,7 +3,9 @@ const EC = require('eight-colors');
3
3
  const Util = require('../utils/util.js');
4
4
  const { getV8Summary } = require('./v8-summary.js');
5
5
  const { dedupeFlatRanges } = require('../utils/dedupe.js');
6
- const { normalizeSourcePath, getSourcePathReplacer } = require('../utils/source-path.js');
6
+ const {
7
+ resolveAnonymousUrl, normalizeSourcePath, getSourcePathReplacer
8
+ } = require('../utils/source-path.js');
7
9
  const { mergeScriptCovs, minimatch } = require('../packages/monocart-coverage-vendor.js');
8
10
  const { collectSourceMaps } = require('../converter/collect-source-maps.js');
9
11
  const version = require('../../package.json').version;
@@ -151,7 +153,8 @@ const initV8ListAndSourcemap = async (v8list, options) => {
151
153
  }
152
154
 
153
155
  // resolve source path
154
- let sourcePath = normalizeSourcePath(data.url, baseDir, i + 1, data.type);
156
+ const sourceUrl = resolveAnonymousUrl(data.url, i + 1, data.type);
157
+ let sourcePath = normalizeSourcePath(sourceUrl, baseDir);
155
158
  if (sourcePathReplacer) {
156
159
  const newSourcePath = sourcePathReplacer(sourcePath, data);
157
160
  if (typeof newSourcePath === 'string' && newSourcePath) {
@@ -159,6 +162,7 @@ const initV8ListAndSourcemap = async (v8list, options) => {
159
162
  }
160
163
  }
161
164
  data.sourcePath = sourcePath;
165
+ // console.log(data.url, sourcePath);
162
166
 
163
167
  // calculate source id
164
168
  data.id = Util.calculateSha1(sourcePath + data.source);
@@ -331,8 +335,8 @@ const handleV8HtmlReport = async (reportData, reportOptions, options) => {
331
335
  return Util.resolveNodeModule(id);
332
336
  });
333
337
 
334
- // package v8 ui
335
- jsFiles.push(Util.resolvePackage('monocart-coverage-v8.js'));
338
+ // package app ui
339
+ jsFiles.push(Util.resolvePackage('monocart-coverage-app.js'));
336
340
 
337
341
  // console.log(jsFiles);
338
342
 
package/package.json CHANGED
@@ -1,101 +1,102 @@
1
- {
2
- "name": "monocart-coverage-reports",
3
- "version": "2.8.1",
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-test": "node ./test/build/build-test.js",
28
- "build": "sf lint && sf b -p && npm run build-test",
29
- "test-unit": "mocha --parallel test/unit/*.test.js",
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": "node ./test/test.js --node",
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-swc": "node ./test/test-swc.js",
47
- "test-v8-and-istanbul": "node ./test/test-v8-and-istanbul.js",
48
- "test-browser": "node ./test/test.js --browser",
49
- "test-cli": "npx mcr node ./test/specs/node.test.js -c test/mcr.config.cli.js",
50
- "test-tsx": "npx mcr tsx ./test/specs/tsx.test.ts -c test/mcr.config.tsx.js",
51
- "test-demo": "node ./test/test-demo.js",
52
- "test-merge": "node ./test/test-merge.js",
53
- "test-merge-istanbul": "node ./test/test-merge-istanbul.js",
54
- "test-client": "node ./test/test-client.js",
55
- "test-all": "node ./test/test.js && node ./scripts/docs.js",
56
- "test": "npm run test-unit && npx mcr npm run test-all -c test/mcr.config.mcr.js",
57
- "test:snap": "cross-env TEST_SNAPSHOT=true npm run test",
58
- "dev": "sf d v8",
59
- "open": "node ./scripts/open.js",
60
- "patch": "npm run build && npm run test && sf publish patch -r"
61
- },
62
- "workspaces": [
63
- "packages/*",
64
- "test"
65
- ],
66
- "files": [
67
- "lib",
68
- "README.zh-Hans.md"
69
- ],
70
- "license": "MIT",
71
- "repository": {
72
- "type": "git",
73
- "url": "git+https://github.com/cenfun/monocart-coverage-reports.git"
74
- },
75
- "dependencies": {
76
- "console-grid": "^2.2.2",
77
- "eight-colors": "^1.3.0",
78
- "istanbul-lib-coverage": "^3.2.2",
79
- "istanbul-lib-report": "^3.0.1",
80
- "istanbul-reports": "^3.1.7",
81
- "lz-utils": "^2.0.2",
82
- "monocart-code-viewer": "^1.1.3",
83
- "monocart-formatter": "^3.0.0",
84
- "monocart-locator": "^1.0.0",
85
- "turbogrid": "^3.0.13"
86
- },
87
- "devDependencies": {
88
- "commander": "^12.0.0",
89
- "esbuild": "^0.21.1",
90
- "eslint": "~9.2.0",
91
- "eslint-config-plus": "^2.0.0",
92
- "eslint-plugin-html": "^8.1.1",
93
- "eslint-plugin-vue": "^9.26.0",
94
- "minimatch": "^9.0.4",
95
- "stylelint": "^16.5.0",
96
- "stylelint-config-plus": "^1.1.2",
97
- "supports-color": "^9.4.0",
98
- "tsx": "^4.9.3",
99
- "ws": "^8.17.0"
100
- }
101
- }
1
+ {
2
+ "name": "monocart-coverage-reports",
3
+ "version": "2.8.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-test": "node ./test/build/build-test.js",
28
+ "build": "sf lint && sf b -p && npm run build-test",
29
+ "test-unit": "mocha --parallel test/unit/*.test.js",
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": "node ./test/test.js --node",
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-swc": "node ./test/test-swc.js",
47
+ "test-v8-and-istanbul": "node ./test/test-v8-and-istanbul.js",
48
+ "test-browser": "node ./test/test.js --browser",
49
+ "test-cli": "npx mcr node ./test/specs/node.test.js -c test/mcr.config.cli.js",
50
+ "test-tsx": "npx mcr tsx ./test/specs/tsx.test.ts -c test/mcr.config.tsx.js",
51
+ "test-demo": "node ./test/test-demo.js",
52
+ "test-merge": "node ./test/test-merge.js",
53
+ "test-merge-istanbul": "node ./test/test-merge-istanbul.js",
54
+ "test-client": "node ./test/test-client.js",
55
+ "test-all": "node ./test/test.js && node ./scripts/docs.js",
56
+ "test": "npm run test-unit && npx mcr npm run test-all -c test/mcr.config.mcr.js",
57
+ "test:snap": "cross-env TEST_SNAPSHOT=true npm run test",
58
+ "dev": "sf d v8",
59
+ "open": "node ./scripts/open.js",
60
+ "patch": "npm run build && npm run test && sf publish patch -r"
61
+ },
62
+ "workspaces": [
63
+ "packages/*",
64
+ "test"
65
+ ],
66
+ "files": [
67
+ "lib",
68
+ "README.zh-Hans.md"
69
+ ],
70
+ "license": "MIT",
71
+ "repository": {
72
+ "type": "git",
73
+ "url": "git+https://github.com/cenfun/monocart-coverage-reports.git"
74
+ },
75
+ "dependencies": {
76
+ "console-grid": "^2.2.2",
77
+ "eight-colors": "^1.3.0",
78
+ "istanbul-lib-coverage": "^3.2.2",
79
+ "istanbul-lib-report": "^3.0.1",
80
+ "istanbul-reports": "^3.1.7",
81
+ "lz-utils": "^2.0.2",
82
+ "monocart-code-viewer": "^1.1.3",
83
+ "monocart-formatter": "^3.0.0",
84
+ "monocart-locator": "^1.0.0",
85
+ "turbogrid": "^3.0.13"
86
+ },
87
+ "devDependencies": {
88
+ "commander": "^12.1.0",
89
+ "esbuild": "^0.21.4",
90
+ "eslint": "~9.3.0",
91
+ "eslint-config-plus": "^2.0.0",
92
+ "eslint-plugin-html": "^8.1.1",
93
+ "eslint-plugin-vue": "^9.26.0",
94
+ "find-up": "^7.0.0",
95
+ "minimatch": "^9.0.4",
96
+ "stylelint": "^16.6.0",
97
+ "stylelint-config-plus": "^1.1.2",
98
+ "supports-color": "^9.4.0",
99
+ "tsx": "^4.11.0",
100
+ "ws": "^8.17.0"
101
+ }
102
+ }