monocart-coverage-reports 2.7.0 → 2.7.2

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.
@@ -0,0 +1,40 @@
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
+ async function load(url, context, nextLoad) {
7
+
8
+ const loaded = await nextLoad(url, context);
9
+ const { source, format } = loaded;
10
+ const dir = process.env.NODE_V8_COVERAGE;
11
+
12
+ if (dir && typeof source === 'string' && (format === 'module' || format === 'commonjs')) {
13
+
14
+ if (convertSourceMap.mapFileCommentRegex.test(source)) {
15
+
16
+ if (!fs.existsSync(dir)) {
17
+ fs.mkdirSync(dir, {
18
+ recursive: true
19
+ });
20
+ }
21
+
22
+ const id = Util.calculateSha1(url + source);
23
+ const filePath = path.resolve(dir, `source-${id}.json`);
24
+ if (!fs.existsSync(filePath)) {
25
+ fs.writeFileSync(filePath, JSON.stringify({
26
+ url,
27
+ source
28
+ }));
29
+ }
30
+
31
+ }
32
+
33
+ }
34
+
35
+ return loaded;
36
+ }
37
+
38
+ module.exports = {
39
+ load
40
+ };
@@ -0,0 +1,3 @@
1
+ import { load } from './hooks.js';
2
+
3
+ export { load };
@@ -0,0 +1,4 @@
1
+ const { register } = require('module');
2
+ const { pathToFileURL } = require('url');
3
+
4
+ register('./hooks.js', pathToFileURL(__filename));
@@ -0,0 +1,3 @@
1
+ import { register } from 'module';
2
+
3
+ register('./hooks.mjs', import.meta.url);
@@ -119,7 +119,7 @@ const initIstanbulSourcePath = (coverageData, fileSources, sourcePathHandler) =>
119
119
  }
120
120
 
121
121
  // new source path, second is source url
122
- const newSourcePath = sourcePathHandler(sourcePath, '');
122
+ const newSourcePath = sourcePathHandler(sourcePath, item);
123
123
  if (typeof newSourcePath === 'string' && newSourcePath) {
124
124
  sourcePath = newSourcePath;
125
125
  }
@@ -141,31 +141,51 @@ const initIstanbulSourcePath = (coverageData, fileSources, sourcePathHandler) =>
141
141
 
142
142
  // ========================================================================================================
143
143
 
144
- const mergeSourceRoot = (sourceRoot, sourceName) => {
145
- if (sourceName.startsWith(sourceRoot)) {
146
- return sourceName;
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
- return sourceRoot + sourceName;
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
- const initSourceMapSourcePath = (sourceMap, fileUrls, sourcePathHandler) => {
152
- // reset sourceRoot
153
- const sourceRoot = sourceMap.sourceRoot || '';
154
- sourceMap.sourceRoot = '';
176
+ const initSourceMapSourcePath = (sourceMap, fileUrls, distFile, sourcePathHandler) => {
155
177
 
156
178
  sourceMap.sources = sourceMap.sources.map((sourceName, i) => {
157
179
 
158
- // the sourceName could be absolute path
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) {
168
- const newSourcePath = sourcePathHandler(sourcePath, sourceUrl);
184
+ // sourcePath could be a filename only, may using distFile to get full path
185
+ const newSourcePath = sourcePathHandler(sourcePath, {
186
+ url: sourceUrl,
187
+ distFile
188
+ });
169
189
  if (typeof newSourcePath === 'string' && newSourcePath) {
170
190
  sourcePath = newSourcePath;
171
191
  }
package/lib/v8/v8.js CHANGED
@@ -144,7 +144,7 @@ const initV8ListAndSourcemap = async (v8list, options) => {
144
144
  // resolve source path
145
145
  let sourcePath = getSourcePath(data.url, i + 1, data.type);
146
146
  if (sourcePathHandler) {
147
- const newSourcePath = sourcePathHandler(sourcePath, data.url);
147
+ const newSourcePath = sourcePathHandler(sourcePath, data);
148
148
  if (typeof newSourcePath === 'string' && newSourcePath) {
149
149
  sourcePath = newSourcePath;
150
150
  }
package/package.json CHANGED
@@ -1,83 +1,91 @@
1
- {
2
- "name": "monocart-coverage-reports",
3
- "version": "2.7.0",
4
- "description": "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
- "./package.json": "./package.json"
17
- },
18
- "types": "./lib/index.d.ts",
19
- "scripts": {
20
- "build-docs": "node ./scripts/build-docs.js",
21
- "build-test": "node ./scripts/build-test.js",
22
- "build": "sf lint && sf b -p && npm run build-test",
23
- "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-koa && npm run test-node-vm",
24
- "test-node-env": "cross-env NODE_V8_COVERAGE=.temp/v8-coverage-env node ./test/test-node-env.js && node ./test/generate-report.js",
25
- "test-node-api": "cross-env NODE_V8_COVERAGE=.temp/v8-coverage-api node ./test/test-node-api.js",
26
- "test-node-fgc": "node ./test/test-node-fgc.js",
27
- "test-node-ins": "node ./test/test-node-ins.js",
28
- "test-node-cdp": "node --inspect=9229 ./test/test-node-cdp.js",
29
- "test-node-koa": "node ./test/test-node-koa.js",
30
- "test-node-vm": "node ./test/test-node-vm.js",
31
- "test-istanbul": "node ./test/test-istanbul.js",
32
- "test-v8": "node ./test/test-v8.js",
33
- "test-puppeteer": "node ./test/test-puppeteer.js",
34
- "test-browser": "node ./test/test-browser.js && npm run test-istanbul && npm run test-v8 && npm run test-puppeteer && npm run test-anonymous && npm run test-css",
35
- "test-anonymous": "node ./test/test-anonymous.js",
36
- "test-css": "node ./test/test-css.js",
37
- "test-client": "node ./test/test-client.js",
38
- "test-cli": "npx mcr node ./test/specs/node.test.js -c test/mcr.config.cli.js",
39
- "test-merge": "node ./test/test-merge.js",
40
- "test-merge-istanbul": "node ./test/test-merge-istanbul.js",
41
- "test-all": "npm run test-browser && npm run test-node && npm run test-cli && npm run test-merge && npm run build-docs",
42
- "test": "npx mcr npm run test-all -c test/mcr.config.mcr.js",
43
- "test:snap": "cross-env TEST_SNAPSHOT=true npm run test",
44
- "dev": "sf d v8",
45
- "open": "node ./scripts/open.js",
46
- "patch": "npm run build && npm run test && sf publish patch -r"
47
- },
48
- "workspaces": [
49
- "packages/*",
50
- "test"
51
- ],
52
- "files": [
53
- "lib"
54
- ],
55
- "license": "MIT",
56
- "repository": {
57
- "type": "git",
58
- "url": "git+https://github.com/cenfun/monocart-coverage-reports.git"
59
- },
60
- "dependencies": {
61
- "console-grid": "~2.2.2",
62
- "eight-colors": "~1.3.0",
63
- "istanbul-lib-coverage": "~3.2.2",
64
- "istanbul-lib-report": "~3.0.1",
65
- "istanbul-reports": "~3.1.7",
66
- "lz-utils": "~2.0.2",
67
- "monocart-code-viewer": "~1.1.2",
68
- "monocart-formatter": "~2.3.2",
69
- "turbogrid": "~3.0.13"
70
- },
71
- "devDependencies": {
72
- "commander": "^12.0.0",
73
- "eslint": "^8.57.0",
74
- "eslint-config-plus": "^1.0.6",
75
- "eslint-plugin-html": "^8.0.0",
76
- "eslint-plugin-vue": "^9.22.0",
77
- "minimatch": "^9.0.3",
78
- "stylelint": "^16.2.1",
79
- "stylelint-config-plus": "^1.1.0",
80
- "supports-color": "^9.4.0",
81
- "ws": "^8.16.0"
82
- }
83
- }
1
+ {
2
+ "name": "monocart-coverage-reports",
3
+ "version": "2.7.2",
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": "npm run test-node-env && npm run test-node-api && npm run test-node-ins && npm run test-node-cdp && npm run test-node-koa && npm run test-node-vm",
31
+ "test-node-env": "cross-env NODE_V8_COVERAGE=.temp/v8-coverage-env node ./test/test-node-env.js && node ./test/generate-report.js",
32
+ "test-node-api": "cross-env NODE_V8_COVERAGE=.temp/v8-coverage-api node ./test/test-node-api.js",
33
+ "test-node-fgc": "node ./test/test-node-fgc.js",
34
+ "test-node-ins": "node ./test/test-node-ins.js",
35
+ "test-node-cdp": "node --inspect=9229 ./test/test-node-cdp.js",
36
+ "test-node-koa": "node ./test/test-node-koa.js",
37
+ "test-node-vm": "node ./test/test-node-vm.js",
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-browser": "node ./test/test-browser.js && npm run test-istanbul && npm run test-v8 && npm run test-puppeteer && npm run test-anonymous && npm run test-css",
42
+ "test-anonymous": "node ./test/test-anonymous.js",
43
+ "test-css": "node ./test/test-css.js",
44
+ "test-client": "node ./test/test-client.js",
45
+ "test-cli": "npx mcr node ./test/specs/node.test.js -c test/mcr.config.cli.js",
46
+ "test-merge": "node ./test/test-merge.js",
47
+ "test-merge-istanbul": "node ./test/test-merge-istanbul.js",
48
+ "test-all": "npm run test-browser && npm run test-node && npm run test-cli && npm run test-merge && npm run build-docs",
49
+ "test": "npx mcr npm run test-all -c test/mcr.config.mcr.js",
50
+ "test:snap": "cross-env TEST_SNAPSHOT=true npm run test",
51
+ "dev": "sf d v8",
52
+ "open": "node ./scripts/open.js",
53
+ "patch": "npm run build && npm run test && sf publish patch -r"
54
+ },
55
+ "workspaces": [
56
+ "packages/*",
57
+ "test"
58
+ ],
59
+ "files": [
60
+ "lib"
61
+ ],
62
+ "license": "MIT",
63
+ "repository": {
64
+ "type": "git",
65
+ "url": "git+https://github.com/cenfun/monocart-coverage-reports.git"
66
+ },
67
+ "dependencies": {
68
+ "console-grid": "^2.2.2",
69
+ "eight-colors": "^1.3.0",
70
+ "istanbul-lib-coverage": "^3.2.2",
71
+ "istanbul-lib-report": "^3.0.1",
72
+ "istanbul-reports": "^3.1.7",
73
+ "lz-utils": "^2.0.2",
74
+ "monocart-code-viewer": "^1.1.2",
75
+ "monocart-formatter": "^2.3.2",
76
+ "turbogrid": "^3.0.13"
77
+ },
78
+ "devDependencies": {
79
+ "commander": "^12.0.0",
80
+ "eslint": "^8.57.0",
81
+ "eslint-config-plus": "^1.0.6",
82
+ "eslint-plugin-html": "^8.0.0",
83
+ "eslint-plugin-vue": "^9.23.0",
84
+ "minimatch": "^9.0.3",
85
+ "stylelint": "^16.2.1",
86
+ "stylelint-config-plus": "^1.1.0",
87
+ "supports-color": "^9.4.0",
88
+ "tsx": "^4.7.1",
89
+ "ws": "^8.16.0"
90
+ }
91
+ }