monocart-coverage-reports 2.10.0 → 2.10.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.
@@ -338,6 +338,12 @@ const Util = {
338
338
  return lines;
339
339
  },
340
340
 
341
+ initLineCoverage: (lineItem) => {
342
+ lineItem.coveredCount = 1;
343
+ lineItem.uncoveredEntire = null;
344
+ lineItem.uncoveredPieces = [];
345
+ },
346
+
341
347
  updateLinesCoverage: (lines, count, lineMap) => {
342
348
  lines.forEach((it) => {
343
349
  const lineItem = lineMap.get(it.line);
@@ -0,0 +1,34 @@
1
+ const { pathToFileURL } = require('url');
2
+ const Util = require('../utils/util.js');
3
+
4
+ const customReport = async (reportName, reportData, reportOptions, globalOptions) => {
5
+ let CustomReporter;
6
+ let err;
7
+ try {
8
+ CustomReporter = await import(reportName);
9
+ } catch (e) {
10
+ err = e;
11
+ try {
12
+ CustomReporter = await import(pathToFileURL(reportName));
13
+ } catch (ee) {
14
+ err = ee;
15
+ }
16
+ }
17
+
18
+ if (!CustomReporter) {
19
+ Util.logError(err.message);
20
+ return;
21
+ }
22
+
23
+ CustomReporter = CustomReporter.default || CustomReporter;
24
+
25
+ const reporter = new CustomReporter(reportOptions, globalOptions);
26
+
27
+ const results = await reporter.generate(reportData);
28
+
29
+ return results;
30
+ };
31
+
32
+ module.exports = {
33
+ customReport
34
+ };
@@ -1,5 +1,4 @@
1
1
  const path = require('path');
2
- const generateMarkdownGrid = require('../utils/markdown.js');
3
2
  const Util = require('../utils/util.js');
4
3
 
5
4
  const { getRowData, getFilteredFiles } = require('./console-details.js');
@@ -103,7 +102,7 @@ const markdownDetailsReport = async (reportData, reportOptions, options) => {
103
102
  name: 'Uncovered Lines'
104
103
  }];
105
104
 
106
- const markdownGrid = generateMarkdownGrid({
105
+ const markdownGrid = Util.markdownGrid({
107
106
  options: {
108
107
  name: reportData.name
109
108
  },
@@ -1,5 +1,4 @@
1
1
  const path = require('path');
2
- const generateMarkdownGrid = require('../utils/markdown.js');
3
2
  const Util = require('../utils/util.js');
4
3
 
5
4
  const { getSummaryColumns } = require('./console-summary.js');
@@ -28,7 +27,7 @@ const markdownSummaryReport = async (reportData, reportOptions, options) => {
28
27
 
29
28
  const columns = getSummaryColumns(color);
30
29
 
31
- const markdownGrid = generateMarkdownGrid({
30
+ const markdownGrid = Util.markdownGrid({
32
31
  options: {
33
32
  name: reportData.name
34
33
  },
@@ -52,7 +52,7 @@ const renderHyphen = (column) => {
52
52
  return ':'.padEnd(width, '-');
53
53
  };
54
54
 
55
- const generateMarkdownGrid = (data) => {
55
+ const markdownGrid = (data) => {
56
56
 
57
57
  const options = {
58
58
  name: '',
@@ -129,4 +129,4 @@ const generateMarkdownGrid = (data) => {
129
129
  };
130
130
 
131
131
 
132
- module.exports = generateMarkdownGrid;
132
+ module.exports = markdownGrid;
package/lib/utils/util.js CHANGED
@@ -1,15 +1,17 @@
1
1
  const fs = require('fs');
2
2
  const { writeFile, readFile } = require('fs/promises');
3
3
  const path = require('path');
4
- const { pathToFileURL } = require('url');
5
4
  const os = require('os');
6
5
  const crypto = require('crypto');
7
6
  const EC = require('eight-colors');
8
7
  const CG = require('console-grid');
8
+ const acornWalk = require('acorn-walk');
9
+
9
10
  const Share = require('../platform/share.js');
10
11
  const request = require('./request.js');
11
12
  const version = require('../../package.json').version;
12
- const acornWalk = require('acorn-walk');
13
+ const markdownGrid = require('./markdown.js');
14
+
13
15
  const { findUpSync, supportsColor } = require('../packages/monocart-coverage-vendor.js');
14
16
 
15
17
  // https://github.com/chalk/supports-color
@@ -29,6 +31,7 @@ const Util = {
29
31
  root: process.cwd(),
30
32
 
31
33
  request,
34
+ markdownGrid,
32
35
 
33
36
  relativePath: function(p, root) {
34
37
  p = `${p}`;
@@ -183,34 +186,6 @@ const Util = {
183
186
  // default config not found
184
187
  },
185
188
 
186
- runCustomReporter: async (reportName, reportData, reportOptions, globalOptions) => {
187
- let CustomReporter;
188
- let err;
189
- try {
190
- CustomReporter = await import(reportName);
191
- } catch (e) {
192
- err = e;
193
- try {
194
- CustomReporter = await import(pathToFileURL(reportName));
195
- } catch (ee) {
196
- err = ee;
197
- }
198
- }
199
-
200
- if (!CustomReporter) {
201
- Util.logError(err.message);
202
- return;
203
- }
204
-
205
- CustomReporter = CustomReporter.default || CustomReporter;
206
-
207
- const reporter = new CustomReporter(reportOptions, globalOptions);
208
-
209
- const results = await reporter.generate(reportData);
210
-
211
- return results;
212
- },
213
-
214
189
  getEOL: function(content) {
215
190
  if (!content) {
216
191
  return os.EOL;
@@ -557,6 +532,87 @@ const Util = {
557
532
  return lines.join(',');
558
533
  },
559
534
 
535
+ // skip \s and comments
536
+ fixSourceRange: (locator, start, end) => {
537
+
538
+ let fixedStart = start;
539
+ let fixedEnd = end;
540
+
541
+ const rangeText = locator.getSlice(start, end);
542
+
543
+ let text = rangeText;
544
+
545
+ // =======================================
546
+ // handle end first
547
+ const oldLen = text.length;
548
+ text = text.trimEnd();
549
+ const newLen = text.length;
550
+ if (newLen < oldLen) {
551
+ fixedEnd -= oldLen - newLen;
552
+ }
553
+
554
+ // =======================================
555
+ // handle start
556
+
557
+ const comments = locator.lineParser.commentParser.comments;
558
+
559
+ let startOffset = 0;
560
+
561
+ // never start in a comment, skip to comment end
562
+ const inComment = comments.find((it) => start > it.start && start < it.end);
563
+ if (inComment) {
564
+ startOffset = inComment.end - start;
565
+ // next text
566
+ text = text.slice(startOffset);
567
+ }
568
+
569
+ while (startOffset < newLen) {
570
+
571
+ const beforeLen = text.length;
572
+ text = text.trimStart();
573
+ const afterLen = text.length;
574
+ if (afterLen === beforeLen) {
575
+ // no indent
576
+ break;
577
+ }
578
+
579
+ const indentLen = beforeLen - afterLen;
580
+
581
+ startOffset += indentLen;
582
+
583
+ // no comments
584
+ if (!comments.length) {
585
+ break;
586
+ }
587
+
588
+ const nextPos = start + startOffset;
589
+ const comment = comments.find((it) => it.start === nextPos);
590
+ if (!comment) {
591
+ break;
592
+ }
593
+
594
+ const commentLen = comment.end - comment.start;
595
+
596
+ startOffset += commentLen;
597
+
598
+ // next text
599
+ text = text.slice(commentLen);
600
+
601
+ }
602
+
603
+ // It should never be possible to start with }
604
+ if (rangeText[startOffset] === '}') {
605
+ startOffset += 1;
606
+ }
607
+
608
+ fixedStart = start + startOffset;
609
+
610
+ return {
611
+ fixedStart,
612
+ fixedEnd
613
+ };
614
+ },
615
+
560
616
  cmpVersion: (v1, v2) => {
561
617
  const [strMajor1, strMinor1, strPatch1] = `${v1}`.split('.');
562
618
  const [strMajor2, strMinor2, strPatch2] = `${v2}`.split('.');
package/lib/v8/v8.js CHANGED
@@ -11,6 +11,7 @@ const { minimatch } = require('../packages/monocart-coverage-vendor.js');
11
11
 
12
12
  const { v8Report } = require('../reports/v8.js');
13
13
  const { v8JsonReport } = require('../reports/v8-json.js');
14
+ const { customReport } = require('../reports/custom.js');
14
15
 
15
16
  const getWrapperSource = (offset, source) => {
16
17
  // NO \n because it break line number in mappings
@@ -353,7 +354,7 @@ const saveV8Report = async (v8list, options, istanbulReportPath) => {
353
354
  if (buildInHandler) {
354
355
  outputs[reportName] = await buildInHandler(reportData, reportOptions, options);
355
356
  } else {
356
- outputs[reportName] = await Util.runCustomReporter(reportName, reportData, reportOptions, options);
357
+ outputs[reportName] = await customReport(reportName, reportData, reportOptions, options);
357
358
  }
358
359
  Util.logTime(`┌ [generate] saved report: ${reportName}`, t1);
359
360
  }
package/package.json CHANGED
@@ -1,116 +1,116 @@
1
- {
2
- "name": "monocart-coverage-reports",
3
- "version": "2.10.0",
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": "npx sf lint && npx 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-sections": "node ./test/test-sections.js",
47
- "test-swc": "node ./test/test-swc.js",
48
- "test-v8-and-istanbul": "node ./test/test-v8-and-istanbul.js",
49
- "test-browser": "node ./test/test.js --browser",
50
- "test-cli": "npx mcr node ./test/specs/node.test.js -c test/mcr.config.cli.js",
51
- "test-tsx": "npx mcr tsx ./test/specs/tsx.test.ts -c test/mcr.config.tsx.js",
52
- "test-demo": "node ./test/test-demo.js",
53
- "test-merge": "node ./test/test-merge.js",
54
- "test-merge-istanbul": "node ./test/test-merge-istanbul.js",
55
- "test-client": "node ./test/test-client.js",
56
- "test-all": "node ./test/test.js && node ./scripts/docs.js",
57
- "test-pr": "node --inspect=9230 ./test/test-pr.js",
58
- "test": "npm run test-unit && npx mcr npm run test-all -c test/mcr.config.mcr.js",
59
- "test:snap": "cross-env TEST_SNAPSHOT=true npm run test",
60
- "dev": "npx sf d app",
61
- "open": "node ./scripts/open.js",
62
- "eol": "git rm -rf --cached . && git reset --hard HEAD",
63
- "patch": "npm run build && npm run test && npx sf publish patch -r"
64
- },
65
- "workspaces": [
66
- "test"
67
- ],
68
- "files": [
69
- "lib",
70
- "README.zh-Hans.md"
71
- ],
72
- "license": "MIT",
73
- "repository": {
74
- "type": "git",
75
- "url": "git+https://github.com/cenfun/monocart-coverage-reports.git"
76
- },
77
- "dependencies": {
78
- "@bcoe/v8-coverage": "^0.2.3",
79
- "@jridgewell/sourcemap-codec": "^1.5.0",
80
- "acorn": "^8.12.1",
81
- "acorn-loose": "^8.4.0",
82
- "acorn-walk": "^8.3.3",
83
- "commander": "^12.1.0",
84
- "console-grid": "^2.2.2",
85
- "eight-colors": "^1.3.0",
86
- "foreground-child": "^3.2.1",
87
- "istanbul-lib-coverage": "^3.2.2",
88
- "istanbul-lib-report": "^3.0.1",
89
- "istanbul-reports": "^3.1.7",
90
- "lz-utils": "^2.1.0",
91
- "monocart-locator": "^1.0.2"
92
- },
93
- "devDependencies": {
94
- "async-tick": "^1.0.0",
95
- "convert-source-map": "^2.0.0",
96
- "diff-sequences": "^29.6.3",
97
- "esbuild": "^0.23.0",
98
- "eslint": "~9.8.0",
99
- "eslint-config-plus": "^2.0.2",
100
- "eslint-plugin-html": "^8.1.1",
101
- "eslint-plugin-vue": "^9.27.0",
102
- "find-up": "^7.0.0",
103
- "minimatch": "^9.0.5",
104
- "monocart-code-viewer": "^1.1.4",
105
- "monocart-formatter": "^3.0.0",
106
- "postcss": "^8.4.40",
107
- "starfall-cli": "^2.0.20",
108
- "stylelint": "^16.7.0",
109
- "stylelint-config-plus": "^1.1.2",
110
- "supports-color": "^9.4.0",
111
- "tsx": "^4.16.2",
112
- "turbogrid": "^3.2.0",
113
- "vine-ui": "^3.1.16",
114
- "ws": "^8.18.0"
115
- }
116
- }
1
+ {
2
+ "name": "monocart-coverage-reports",
3
+ "version": "2.10.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-test": "node ./test/build/build-test.js",
28
+ "build": "npx sf lint && npx 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-sections": "node ./test/test-sections.js",
47
+ "test-swc": "node ./test/test-swc.js",
48
+ "test-v8-and-istanbul": "node ./test/test-v8-and-istanbul.js",
49
+ "test-browser": "node ./test/test.js --browser",
50
+ "test-cli": "npx mcr node ./test/specs/node.test.js -c test/mcr.config.cli.js",
51
+ "test-tsx": "npx mcr tsx ./test/specs/tsx.test.ts -c test/mcr.config.tsx.js",
52
+ "test-demo": "node ./test/test-demo.js",
53
+ "test-merge": "node ./test/test-merge.js",
54
+ "test-merge-istanbul": "node ./test/test-merge-istanbul.js",
55
+ "test-client": "node ./test/test-client.js",
56
+ "test-all": "node ./test/test.js",
57
+ "test-pr": "node --inspect=9230 ./test/test-pr.js",
58
+ "test": "npm run test-unit && npx mcr npm run test-all -c test/mcr.config.mcr.js && node ./scripts/docs.js",
59
+ "test:snap": "cross-env TEST_SNAPSHOT=true npm run test",
60
+ "dev": "npx sf d app",
61
+ "open": "node ./scripts/open.js",
62
+ "eol": "git rm -rf --cached . && git reset --hard HEAD",
63
+ "patch": "npm run build && npm run test && npx sf publish patch -r"
64
+ },
65
+ "workspaces": [
66
+ "test"
67
+ ],
68
+ "files": [
69
+ "lib",
70
+ "README.zh-Hans.md"
71
+ ],
72
+ "license": "MIT",
73
+ "repository": {
74
+ "type": "git",
75
+ "url": "git+https://github.com/cenfun/monocart-coverage-reports.git"
76
+ },
77
+ "dependencies": {
78
+ "@bcoe/v8-coverage": "^0.2.3",
79
+ "@jridgewell/sourcemap-codec": "^1.5.0",
80
+ "acorn": "^8.12.1",
81
+ "acorn-loose": "^8.4.0",
82
+ "acorn-walk": "^8.3.3",
83
+ "commander": "^12.1.0",
84
+ "console-grid": "^2.2.2",
85
+ "eight-colors": "^1.3.0",
86
+ "foreground-child": "^3.2.1",
87
+ "istanbul-lib-coverage": "^3.2.2",
88
+ "istanbul-lib-report": "^3.0.1",
89
+ "istanbul-reports": "^3.1.7",
90
+ "lz-utils": "^2.1.0",
91
+ "monocart-locator": "^1.0.2"
92
+ },
93
+ "devDependencies": {
94
+ "async-tick": "^1.0.0",
95
+ "convert-source-map": "^2.0.0",
96
+ "diff-sequences": "^29.6.3",
97
+ "esbuild": "^0.23.0",
98
+ "eslint": "~9.8.0",
99
+ "eslint-config-plus": "^2.0.2",
100
+ "eslint-plugin-html": "^8.1.1",
101
+ "eslint-plugin-vue": "^9.27.0",
102
+ "find-up": "^7.0.0",
103
+ "minimatch": "^9.0.5",
104
+ "monocart-code-viewer": "^1.1.4",
105
+ "monocart-formatter": "^3.0.0",
106
+ "postcss": "^8.4.41",
107
+ "starfall-cli": "^2.0.20",
108
+ "stylelint": "^16.8.1",
109
+ "stylelint-config-plus": "^1.1.2",
110
+ "supports-color": "^9.4.0",
111
+ "tsx": "^4.16.5",
112
+ "turbogrid": "^3.2.0",
113
+ "vine-ui": "^3.1.16",
114
+ "ws": "^8.18.0"
115
+ }
116
+ }