monocart-coverage-reports 2.11.6 → 2.12.1

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.
@@ -1,123 +1,123 @@
1
- class RangeTree {
2
-
3
- constructor(
4
- start,
5
- end,
6
- delta,
7
- children
8
- ) {
9
- this.start = start;
10
- this.end = end;
11
- this.delta = delta;
12
- this.children = children;
13
- }
14
-
15
- // eslint-disable-next-line complexity
16
- normalize() {
17
- const children = [];
18
- let curEnd;
19
- let head;
20
- const tail = [];
21
- for (const child of this.children) {
22
- if (!head) {
23
- head = child;
24
- } else if (child.delta === head.delta && child.start === curEnd) {
25
- tail.push(child);
26
- } else {
27
- endChain();
28
- head = child;
29
- }
30
- curEnd = child.end;
31
- }
32
- if (head) {
33
- endChain();
34
- }
35
-
36
- if (children.length === 1) {
37
- const child = children[0];
38
- if (child.start === this.start && child.end === this.end) {
39
- this.delta += child.delta;
40
- this.children = child.children;
41
- // `.lazyCount` is zero for both (both are after normalization)
42
- return;
43
- }
44
- }
45
-
46
- this.children = children;
47
-
48
- function endChain() {
49
- if (tail.length !== 0) {
50
- head.end = tail[tail.length - 1].end;
51
- for (const tailTree of tail) {
52
- for (const subChild of tailTree.children) {
53
- subChild.delta += tailTree.delta - head.delta;
54
- head.children.push(subChild);
55
- }
56
- }
57
- tail.length = 0;
58
- }
59
- head.normalize();
60
- children.push(head);
61
- }
62
- }
63
-
64
- /**
65
- * @precondition `tree.start < value && value < tree.end`
66
- * @return RangeTree Right part
67
- */
68
- split(value) {
69
- let leftChildLen = this.children.length;
70
- let mid;
71
-
72
- // TODO(perf): Binary search (check overhead)
73
- for (let i = 0; i < this.children.length; i++) {
74
- const child = this.children[i];
75
- if (child.start < value && value < child.end) {
76
- mid = child.split(value);
77
- leftChildLen = i + 1;
78
- break;
79
- } else if (child.start >= value) {
80
- leftChildLen = i;
81
- break;
82
- }
83
- }
84
-
85
- const rightLen = this.children.length - leftChildLen;
86
- const rightChildren = this.children.splice(leftChildLen, rightLen);
87
- if (mid) {
88
- rightChildren.unshift(mid);
89
- }
90
- const result = new RangeTree(
91
- value,
92
- this.end,
93
- this.delta,
94
- rightChildren
95
- );
96
- this.end = value;
97
- return result;
98
- }
99
-
100
- /**
101
- * Get the range coverages corresponding to the tree.
102
- *
103
- * The ranges are pre-order sorted.
104
- */
105
- toRanges() {
106
- const ranges = [];
107
- // Stack of parent trees and counts.
108
- const stack = [[this, 0]];
109
- while (stack.length > 0) {
110
- const [cur, parentCount] = stack.pop();
111
- const count = parentCount + cur.delta;
112
- ranges.push({
113
- startOffset: cur.start, endOffset: cur.end, count
114
- });
115
- for (let i = cur.children.length - 1; i >= 0; i--) {
116
- stack.push([cur.children[i], count]);
117
- }
118
- }
119
- return ranges;
120
- }
121
- }
122
-
123
- module.exports = RangeTree;
1
+ class RangeTree {
2
+
3
+ constructor(
4
+ start,
5
+ end,
6
+ delta,
7
+ children
8
+ ) {
9
+ this.start = start;
10
+ this.end = end;
11
+ this.delta = delta;
12
+ this.children = children;
13
+ }
14
+
15
+ // eslint-disable-next-line complexity
16
+ normalize() {
17
+ const children = [];
18
+ let curEnd;
19
+ let head;
20
+ const tail = [];
21
+ for (const child of this.children) {
22
+ if (!head) {
23
+ head = child;
24
+ } else if (child.delta === head.delta && child.start === curEnd) {
25
+ tail.push(child);
26
+ } else {
27
+ endChain();
28
+ head = child;
29
+ }
30
+ curEnd = child.end;
31
+ }
32
+ if (head) {
33
+ endChain();
34
+ }
35
+
36
+ if (children.length === 1) {
37
+ const child = children[0];
38
+ if (child.start === this.start && child.end === this.end) {
39
+ this.delta += child.delta;
40
+ this.children = child.children;
41
+ // `.lazyCount` is zero for both (both are after normalization)
42
+ return;
43
+ }
44
+ }
45
+
46
+ this.children = children;
47
+
48
+ function endChain() {
49
+ if (tail.length !== 0) {
50
+ head.end = tail[tail.length - 1].end;
51
+ for (const tailTree of tail) {
52
+ for (const subChild of tailTree.children) {
53
+ subChild.delta += tailTree.delta - head.delta;
54
+ head.children.push(subChild);
55
+ }
56
+ }
57
+ tail.length = 0;
58
+ }
59
+ head.normalize();
60
+ children.push(head);
61
+ }
62
+ }
63
+
64
+ /**
65
+ * @precondition `tree.start < value && value < tree.end`
66
+ * @return RangeTree Right part
67
+ */
68
+ split(value) {
69
+ let leftChildLen = this.children.length;
70
+ let mid;
71
+
72
+ // TODO(perf): Binary search (check overhead)
73
+ for (let i = 0; i < this.children.length; i++) {
74
+ const child = this.children[i];
75
+ if (child.start < value && value < child.end) {
76
+ mid = child.split(value);
77
+ leftChildLen = i + 1;
78
+ break;
79
+ } else if (child.start >= value) {
80
+ leftChildLen = i;
81
+ break;
82
+ }
83
+ }
84
+
85
+ const rightLen = this.children.length - leftChildLen;
86
+ const rightChildren = this.children.splice(leftChildLen, rightLen);
87
+ if (mid) {
88
+ rightChildren.unshift(mid);
89
+ }
90
+ const result = new RangeTree(
91
+ value,
92
+ this.end,
93
+ this.delta,
94
+ rightChildren
95
+ );
96
+ this.end = value;
97
+ return result;
98
+ }
99
+
100
+ /**
101
+ * Get the range coverages corresponding to the tree.
102
+ *
103
+ * The ranges are pre-order sorted.
104
+ */
105
+ toRanges() {
106
+ const ranges = [];
107
+ // Stack of parent trees and counts.
108
+ const stack = [[this, 0]];
109
+ while (stack.length > 0) {
110
+ const [cur, parentCount] = stack.pop();
111
+ const count = parentCount + cur.delta;
112
+ ranges.push({
113
+ startOffset: cur.start, endOffset: cur.end, count
114
+ });
115
+ for (let i = cur.children.length - 1; i >= 0; i--) {
116
+ stack.push([cur.children[i], count]);
117
+ }
118
+ }
119
+ return ranges;
120
+ }
121
+ }
122
+
123
+ module.exports = RangeTree;
@@ -35,19 +35,11 @@ const filterPath = (str) => {
35
35
  // src/images/icons/sync-.svg$
36
36
 
37
37
  str = str.replace(/\\\\/g, '/');
38
- str = str.replace(/\?/g, '/');
39
38
 
40
39
  // decodeURI("%20") to space
41
40
  str = decodeURI(str);
42
41
  // remove / of start, end or double, ./ ../
43
- const ls = str.split('/').map((it) => {
44
- it = it.trim();
45
- // remove illegal characters except /
46
- it = it.replace(/[\\:*?"<>|]/g, '');
47
- // space
48
- it = it.replace(/\s+/g, '-');
49
- return it;
50
- }).filter((item) => {
42
+ const ls = str.split('/').filter((item) => {
51
43
  if (!item || item === '.' || item === '..') {
52
44
  return false;
53
45
  }
@@ -103,14 +95,14 @@ const normalizeSourcePath = (sourceUrl, baseDir) => {
103
95
  // url http/https/webpack
104
96
  const urlObj = Util.resolveUrl(sourceUrl);
105
97
  if (urlObj) {
106
- const host = [urlObj.hostname, urlObj.port].filter((it) => it).join('-');
98
+ const host = urlObj.host;
107
99
  // always start with '/'
108
100
  const pathname = urlObj.pathname;
109
101
 
110
102
  let p = host + pathname;
111
103
  // webpack://monocart-v8/packages/v8/src/app.vue?5cc4
112
104
  if (urlObj.search) {
113
- p += `/${urlObj.search}`;
105
+ p += urlObj.search;
114
106
  }
115
107
 
116
108
  return filterPath(p);
@@ -159,14 +151,31 @@ const getSourcePathReplacer = (options) => {
159
151
 
160
152
  // ========================================================================================================
161
153
 
154
+ const normalizeIstanbulFilePath = (sourcePath) => {
155
+
156
+ // decodeURI("%20") to space
157
+ let str = decodeURI(`${sourcePath}`);
158
+ str = str.replace(/\\/g, '/');
159
+
160
+ // remove / of start, end or double, ./ ../
161
+ return str.split('/').map((it) => {
162
+ it = it.trim();
163
+ // remove illegal characters except /
164
+ it = it.replace(/[\\:*?"<>|]/g, '');
165
+ // space
166
+ it = it.replace(/\s+/g, '-');
167
+ return it;
168
+ }).filter((item) => {
169
+ if (!item || item === '.' || item === '..') {
170
+ return false;
171
+ }
172
+ return true;
173
+ }).join('/');
174
+ };
175
+
162
176
  const initIstanbulSourcePath = (coverageData, fileSources, options) => {
163
177
 
164
178
  const sourcePathReplacer = getSourcePathReplacer(options);
165
- if (!sourcePathReplacer) {
166
- return coverageData;
167
- }
168
-
169
- // console.log(fileSources);
170
179
 
171
180
  const newCoverage = {};
172
181
  Object.keys(coverageData).forEach((sourcePath) => {
@@ -184,13 +193,25 @@ const initIstanbulSourcePath = (coverageData, fileSources, options) => {
184
193
  }
185
194
 
186
195
  // new source path, second is source url
187
- const newSourcePath = sourcePathReplacer(sourcePath, item);
188
- if (typeof newSourcePath === 'string' && newSourcePath) {
189
- sourcePath = newSourcePath;
196
+ if (sourcePathReplacer) {
197
+ const newSourcePath = sourcePathReplacer(sourcePath, item);
198
+ if (typeof newSourcePath === 'string' && newSourcePath) {
199
+ sourcePath = newSourcePath;
200
+ }
190
201
  }
191
202
 
203
+ sourcePath = normalizeIstanbulFilePath(sourcePath);
204
+
205
+ // console.log(item);
206
+
192
207
  // update source path
193
- item.data.path = sourcePath;
208
+ if (item.data) {
209
+ item.data.path = sourcePath;
210
+ } else {
211
+ // from v8
212
+ item.path = sourcePath;
213
+ }
214
+
194
215
  newCoverage[sourcePath] = item;
195
216
  // update source for the new path
196
217
  if (typeof source === 'string') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "monocart-coverage-reports",
3
- "version": "2.11.6",
3
+ "version": "2.12.1",
4
4
  "description": "A code coverage tool to generate native V8 reports or Istanbul reports.",
5
5
  "main": "./lib/index.js",
6
6
  "bin": {
@@ -46,7 +46,6 @@
46
46
  "test-v8-and-istanbul": "node ./test/test-v8-and-istanbul.js",
47
47
  "test-browser": "node ./test/test.js --browser",
48
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
49
  "test-demo": "node ./test/test-demo.js",
51
50
  "test-merge": "node ./test/test-merge.js",
52
51
  "test-merge-istanbul": "node ./test/test-merge-istanbul.js",
@@ -79,7 +78,7 @@
79
78
  "acorn": "^8.14.0",
80
79
  "acorn-loose": "^8.4.0",
81
80
  "acorn-walk": "^8.3.4",
82
- "commander": "^13.0.0",
81
+ "commander": "^13.1.0",
83
82
  "console-grid": "^2.2.3",
84
83
  "eight-colors": "^1.3.1",
85
84
  "foreground-child": "^3.3.0",
@@ -95,22 +94,21 @@
95
94
  "convert-source-map": "^2.0.0",
96
95
  "diff-sequences": "^29.6.3",
97
96
  "esbuild": "^0.24.2",
98
- "eslint": "~9.18.0",
97
+ "eslint": "~9.19.0",
99
98
  "eslint-config-plus": "^2.0.2",
100
99
  "eslint-plugin-html": "^8.1.2",
101
100
  "eslint-plugin-vue": "^9.32.0",
102
101
  "find-up": "^7.0.0",
103
102
  "minimatch": "^9.0.5",
104
- "mocha": "^11.0.1",
103
+ "mocha": "^11.1.0",
105
104
  "monocart-code-viewer": "^1.1.4",
106
105
  "monocart-formatter": "^3.0.0",
107
106
  "node-stream-zip": "^1.15.0",
108
- "postcss": "^8.4.49",
107
+ "postcss": "^8.5.1",
109
108
  "starfall-cli": "^2.0.20",
110
- "stylelint": "^16.13.0",
109
+ "stylelint": "^16.14.1",
111
110
  "stylelint-config-plus": "^1.1.3",
112
111
  "supports-color": "^10.0.0",
113
- "tsx": "^4.19.2",
114
112
  "turbogrid": "^3.2.0",
115
113
  "vine-ui": "^3.1.16",
116
114
  "ws": "^8.18.0",