monocart-coverage-reports 2.3.4 → 2.4.0

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/lib/utils/util.js CHANGED
@@ -12,10 +12,12 @@ const { deflateSync } = require('lz-utils');
12
12
  const { acornWalk } = require('../packages/monocart-coverage-vendor.js');
13
13
 
14
14
  const Util = {
15
+ ... Share,
15
16
 
16
- root: process.cwd(),
17
+ EC,
18
+ CG,
17
19
 
18
- ... Share,
20
+ root: process.cwd(),
19
21
 
20
22
  relativePath: function(p, root) {
21
23
  p = `${p}`;
@@ -416,6 +418,10 @@ const Util = {
416
418
  debug: 30
417
419
  },
418
420
 
421
+ isDebug: () => {
422
+ return Util.loggingType === 'debug';
423
+ },
424
+
419
425
  initLoggingLevel: (level) => {
420
426
 
421
427
  const types = {
@@ -75,7 +75,7 @@ const getV8Summary = (v8list, watermarks) => {
75
75
  total: 0,
76
76
  covered: 0
77
77
  },
78
- functions: {
78
+ statements: {
79
79
  total: 0,
80
80
  covered: 0
81
81
  },
@@ -83,6 +83,10 @@ const getV8Summary = (v8list, watermarks) => {
83
83
  total: 0,
84
84
  covered: 0
85
85
  },
86
+ functions: {
87
+ total: 0,
88
+ covered: 0
89
+ },
86
90
  lines: {
87
91
  total: 0,
88
92
  covered: 0,
package/lib/v8/v8.js CHANGED
@@ -79,6 +79,8 @@ const initV8ListAndSourcemap = async (v8list, options) => {
79
79
  scriptOffset,
80
80
  // Manually Resolve the Sourcemap
81
81
  sourceMap: item.sourceMap,
82
+ // fake source with `lineLengths`
83
+ fake: item.fake,
82
84
  // empty coverage
83
85
  empty: item.empty,
84
86
  // match source if using empty coverage
@@ -319,8 +321,9 @@ const saveV8Report = async (v8list, options) => {
319
321
 
320
322
  const defaultWatermarks = {
321
323
  bytes: [50, 80],
322
- functions: [50, 80],
324
+ statements: [50, 80],
323
325
  branches: [50, 80],
326
+ functions: [50, 80],
324
327
  lines: [50, 80]
325
328
  };
326
329
  const watermarks = Util.resolveWatermarks(defaultWatermarks, options.watermarks);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "monocart-coverage-reports",
3
- "version": "2.3.4",
3
+ "version": "2.4.0",
4
4
  "description": "Monocart coverage reports",
5
5
  "main": "./lib/index.js",
6
6
  "bin": {
@@ -65,11 +65,11 @@
65
65
  "turbogrid": "^3.0.13"
66
66
  },
67
67
  "devDependencies": {
68
- "commander": "^11.1.0",
68
+ "commander": "^12.0.0",
69
69
  "eslint": "^8.56.0",
70
70
  "eslint-config-plus": "^1.0.6",
71
71
  "eslint-plugin-html": "^7.1.0",
72
- "eslint-plugin-vue": "^9.20.1",
72
+ "eslint-plugin-vue": "^9.21.1",
73
73
  "stylelint": "^15.11.0",
74
74
  "stylelint-config-plus": "^1.0.4"
75
75
  }
@@ -1,440 +0,0 @@
1
- const Util = require('../utils/util.js');
2
-
3
- const findBranchBlock = (start, end, functionInfo) => {
4
- const { range } = functionInfo;
5
- if (range) {
6
- const { blockMap, blockRanges } = range;
7
- if (blockMap) {
8
- // exact matched a block
9
- const block = blockMap.get(start);
10
- if (block) {
11
- return block;
12
- }
13
-
14
- // support for tf2 || a || 1;
15
- // "a" is in "|| a"
16
- const blockItem = Util.findInRanges(start, end, blockRanges, 'startOffset', 'endOffset');
17
- if (blockItem) {
18
- return blockItem;
19
- }
20
- }
21
- }
22
-
23
- };
24
-
25
- // =======================================================================================
26
-
27
- const createBranchGroup = (type, branchStart, parents, branchMap, functionInfo) => {
28
- // clone and reverse parents
29
- const reverseParents = [].concat(parents).reverse();
30
- const group = {
31
- type,
32
-
33
- start: branchStart,
34
- // could be updated if multiple locations
35
- end: branchStart,
36
-
37
- locations: [],
38
- reverseParents,
39
- functionInfo
40
- };
41
- branchMap.set(branchStart, group);
42
- return group;
43
- };
44
-
45
- const addBranch = (group, node, locationMap, functionInfo) => {
46
- const { start, end } = node;
47
-
48
- const branchStart = group.start;
49
-
50
- // the block is not exact correct, if there is a block wrapped
51
- // [x8]{ var a = b || [x4]c }, b is no block, but it can be found in x8 block
52
- const block = findBranchBlock(start, end, functionInfo);
53
-
54
- const branchInfo = {
55
- // for get previous group for LogicalExpression
56
- branchStart,
57
- start,
58
- end,
59
- // cache block
60
- block,
61
- // branch count default to 0
62
- count: 0
63
- };
64
-
65
- group.locations.push(branchInfo);
66
-
67
- // update group end
68
- group.end = end;
69
-
70
- locationMap.set(start, branchInfo);
71
-
72
- return branchInfo;
73
- };
74
-
75
- const addNoneBranch = (group) => {
76
- group.locations.push({
77
- none: true,
78
- count: 0
79
- });
80
- };
81
-
82
- // =======================================================================================
83
-
84
- const hasFunctionBlock = (functionInfo) => {
85
- const { range } = functionInfo;
86
- if (range) {
87
- const { blockMap } = range;
88
- if (blockMap) {
89
- return true;
90
- }
91
- }
92
- return false;
93
- };
94
-
95
- const addNodeCount = (node, parents, functionInfo) => {
96
-
97
- const { start, end } = node;
98
-
99
- if (hasFunctionBlock(functionInfo)) {
100
- const { range } = functionInfo;
101
- const { blockMap, blockRanges } = range;
102
- const block = blockMap.get(start);
103
- if (block) {
104
- node._state = {
105
- count: block.count
106
- };
107
- return;
108
- }
109
-
110
- const blockItem = Util.findInRanges(start, end, blockRanges, 'startOffset', 'endOffset');
111
- if (blockItem) {
112
- node._state = {
113
- count: blockItem.count
114
- };
115
- return;
116
- }
117
-
118
- // continue find in reverseParents
119
-
120
- } else {
121
-
122
- // default to 1 if no function block
123
- node._state = {
124
- count: 1
125
- };
126
- return;
127
- }
128
-
129
- const reverseParents = [].concat(parents).reverse();
130
- for (const parent of reverseParents) {
131
- if (parent._state) {
132
- node._state = {
133
- count: parent._state.count
134
- };
135
- return;
136
- }
137
- }
138
-
139
- // function count
140
- node._state = {
141
- count: functionInfo.count
142
- };
143
-
144
- };
145
-
146
- // =======================================================================================
147
-
148
- const addAssignmentPattern = (params, parents, functionInfo, branchMap, locationMap) => {
149
- if (!Util.isList(params)) {
150
- return;
151
- }
152
-
153
- params.forEach((param) => {
154
- if (param.type !== 'AssignmentPattern') {
155
- return;
156
- }
157
- const start = param.start;
158
- const group = createBranchGroup('AssignmentPattern', start, parents, branchMap, functionInfo);
159
- addBranch(group, param, locationMap, functionInfo);
160
- });
161
- };
162
-
163
- const createBranches = (functionInfo, branchMap, body, params, functionParents = []) => {
164
-
165
- // locationMap for chain LogicalExpression locations
166
- const locationMap = new Map();
167
-
168
- // function's arguments
169
- addAssignmentPattern(params, functionParents, functionInfo, branchMap, locationMap);
170
-
171
- Util.visitAst(body, {
172
-
173
- Function() {
174
- return 'break';
175
- },
176
-
177
- Statement: (node, parents) => {
178
- addNodeCount(node, parents, functionInfo);
179
- },
180
-
181
- // cond-expr Ternary
182
- // var b = a ? 'consequent' : 'alternate';
183
- ConditionalExpression: (node, parents) => {
184
- addNodeCount(node, parents, functionInfo);
185
- const { consequent, alternate } = node;
186
- const start = consequent.start;
187
- const group = createBranchGroup('ConditionalExpression', start, parents, branchMap, functionInfo);
188
- addBranch(group, consequent, locationMap, functionInfo);
189
- addBranch(group, alternate, locationMap, functionInfo);
190
- },
191
-
192
- // if
193
- // An IF statement always has exactly two branches:
194
- // one where the condition is FALSE and one where the condition is TRUE
195
- IfStatement: (node, parents) => {
196
- addNodeCount(node, parents, functionInfo);
197
- const { consequent, alternate } = node;
198
- const start = consequent.start;
199
- const group = createBranchGroup('IfStatement', start, parents, branchMap, functionInfo);
200
- addBranch(group, consequent, locationMap, functionInfo);
201
-
202
- // console.log('if type', consequent.type);
203
-
204
- if (alternate) {
205
- addBranch(group, alternate, locationMap, functionInfo);
206
- } else {
207
- // add none branch
208
- addNoneBranch(group);
209
- // no need update group end, there is no end
210
- }
211
- },
212
-
213
- // binary-expr
214
- // var b = a || b || c;
215
- // do not use BinaryExpression
216
- LogicalExpression: (node, parents) => {
217
- addNodeCount(node, parents, functionInfo);
218
-
219
- const { left, right } = node;
220
- const start = left.start;
221
-
222
- // console.log(left.start, right.start);
223
-
224
- let group;
225
- // link to same branch start if LogicalExpression
226
- const prevLocation = locationMap.get(start);
227
- if (prevLocation) {
228
- // console.log('link branch ==================', type);
229
- group = branchMap.get(prevLocation.branchStart);
230
- } else {
231
- group = createBranchGroup('LogicalExpression', start, parents, branchMap, functionInfo);
232
- addBranch(group, left, locationMap, functionInfo);
233
- }
234
-
235
- addBranch(group, right, locationMap, functionInfo);
236
-
237
- // console.log(group.locations.map((it) => it.start));
238
-
239
- // sort branch locations
240
- // a || b || c
241
- // first, left a and right c
242
- // then, left a and right b
243
- if (prevLocation) {
244
- const { locations } = group;
245
- locations.sort((a, b) => {
246
- return a.start - b.start;
247
- });
248
- // update group end after sorted
249
- group.end = locations[locations.length - 1].end;
250
- }
251
- },
252
-
253
- // switch
254
- SwitchStatement: (node, parents) => {
255
- addNodeCount(node, parents, functionInfo);
256
- const start = node.start;
257
- const group = createBranchGroup('SwitchStatement', start, parents, branchMap, functionInfo);
258
- const cases = node.cases;
259
- cases.forEach((switchCase) => {
260
- // console.log('switchCase', switchCase.start);
261
- addBranch(group, switchCase, locationMap, functionInfo);
262
- });
263
- }
264
-
265
- });
266
-
267
- };
268
-
269
-
270
- // =======================================================================================
271
-
272
- const updateBlockLocations = (locations) => {
273
- const noBlockList = [];
274
- let blockCount = 0;
275
- locations.forEach((item) => {
276
- if (item.block) {
277
- item.count = item.block.count;
278
- blockCount += item.count;
279
- return;
280
- }
281
- noBlockList.push(item);
282
- });
283
-
284
- return {
285
- noBlockList,
286
- blockCount
287
- };
288
- };
289
-
290
- // const a = tf1 ? 'true' : 'false';
291
- const ConditionalExpression = (locations, parentCount) => {
292
- const { noBlockList, blockCount } = updateBlockLocations(locations);
293
- if (!noBlockList.length) {
294
- return;
295
- }
296
- let count = parentCount - blockCount;
297
- noBlockList.forEach((item) => {
298
- item.count = count;
299
- count = 0;
300
- });
301
- };
302
-
303
- const IfStatement = (locations, parentCount) => {
304
- const { noBlockList, blockCount } = updateBlockLocations(locations);
305
- if (!noBlockList.length) {
306
- return;
307
- }
308
- // console.log(parentCount, 'uncovered list', noBlockList.length, group.start);
309
- let count = parentCount - blockCount;
310
- noBlockList.forEach((item) => {
311
- item.count = count;
312
- count = 0;
313
- });
314
-
315
- };
316
-
317
- // const b = tf2 || tf1 || a;
318
- const LogicalExpression = (locations, parentCount) => {
319
- const { noBlockList, blockCount } = updateBlockLocations(locations);
320
- if (!noBlockList.length) {
321
- return;
322
- }
323
- const count = parentCount - blockCount;
324
- noBlockList.forEach((item) => {
325
- item.count = count;
326
- });
327
- };
328
-
329
- const SwitchStatement = (locations, parentCount) => {
330
- const { noBlockList, blockCount } = updateBlockLocations(locations);
331
- if (!noBlockList.length) {
332
- return;
333
- }
334
- const count = parentCount - blockCount;
335
- noBlockList.forEach((item) => {
336
- item.count = count;
337
- });
338
- };
339
-
340
- const AssignmentPattern = (locations, parentCount) => {
341
- locations.forEach((item) => {
342
- item.count = parentCount;
343
- });
344
- };
345
-
346
- // =======================================================================================
347
-
348
- const getBranchParentCount = (reverseParents, functionCount) => {
349
- // parent count
350
- for (const parent of reverseParents) {
351
- if (parent._state) {
352
- return parent._state.count;
353
- }
354
- }
355
-
356
- // root function count
357
- return functionCount;
358
- };
359
-
360
- const updateBranchCount = (group) => {
361
-
362
- const {
363
- type, locations, reverseParents, functionInfo
364
- } = group;
365
-
366
- const functionCount = functionInfo.count;
367
-
368
- // default is 0, no need continue
369
- if (functionCount === 0) {
370
- return;
371
- }
372
-
373
- const parentCount = getBranchParentCount(reverseParents, functionCount);
374
- // console.log(functionInfo.start, 'function count', functionCount, 'parent count', parentCount);
375
-
376
- if (!hasFunctionBlock(functionInfo)) {
377
- // default to parent if no function range
378
- locations.forEach((item) => {
379
- item.count = parentCount;
380
- });
381
- return;
382
- }
383
-
384
- // calculate branches count
385
- // > 1
386
-
387
- const handlers = {
388
- ConditionalExpression,
389
- IfStatement,
390
- LogicalExpression,
391
- SwitchStatement,
392
- AssignmentPattern
393
- };
394
-
395
- const handler = handlers[type];
396
- if (handler) {
397
- handler(locations, parentCount);
398
- }
399
-
400
- };
401
-
402
- const collectBranches = (branchMap) => {
403
-
404
- // calculate count for all branches
405
- branchMap.forEach((group) => {
406
- updateBranchCount(group);
407
- });
408
-
409
- // init branches
410
- const branches = [];
411
- branchMap.forEach((group) => {
412
-
413
- // add start/end for none with group start/end
414
- group.locations.forEach((item) => {
415
- if (item.none) {
416
- item.start = group.start;
417
- item.end = group.end;
418
- }
419
- });
420
-
421
- branches.push({
422
- type: group.type,
423
- start: group.start,
424
- end: group.end,
425
- locations: group.locations
426
- });
427
- });
428
-
429
- // sort branches
430
- branches.sort((a, b) => {
431
- return a.start - b.start;
432
- });
433
-
434
- return branches;
435
- };
436
-
437
- module.exports = {
438
- createBranches,
439
- collectBranches
440
- };
@@ -1,23 +0,0 @@
1
- module.exports = class InfoLine {
2
- constructor(line, column, count, covered) {
3
- // 1 based
4
- this.line = line;
5
- this.column = column;
6
- this.count = count;
7
- // covered full line, could be false even count > 0
8
- this.covered = covered;
9
- }
10
-
11
- generate() {
12
- return {
13
- start: {
14
- line: this.line,
15
- column: 0
16
- },
17
- end: {
18
- line: this.line,
19
- column: this.column
20
- }
21
- };
22
- }
23
- };