monocart-coverage-reports 2.0.7 → 2.0.9

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.
@@ -62,11 +62,6 @@ const dedupeRanges = (ranges) => {
62
62
  // apply to js count ranges
63
63
  const dedupeCountRanges = (ranges) => {
64
64
 
65
- // v8 ranges format
66
- // { startOffset: 0, endOffset: 6, count: 0 },
67
- // { startOffset: 0, endOffset: 6, count: 1 },
68
- // { startOffset: 0, endOffset: 297, count: 1 }
69
-
70
65
  // count ranges format
71
66
  // { start: 0, end: 6, count: 0 }
72
67
 
package/lib/utils/util.js CHANGED
@@ -243,6 +243,19 @@ const Util = {
243
243
  visitor(rootNode);
244
244
  },
245
245
 
246
+ updateOffsetToLocation: (locator, loc) => {
247
+ const sLoc = locator.offsetToLocation(loc.start);
248
+ loc.start = {
249
+ line: sLoc.line,
250
+ column: sLoc.column
251
+ };
252
+ const eLoc = locator.offsetToLocation(loc.end);
253
+ loc.end = {
254
+ line: eLoc.line,
255
+ column: eLoc.column
256
+ };
257
+ },
258
+
246
259
  forEachFile: function(dir, extList, callback) {
247
260
  if (!fs.existsSync(dir)) {
248
261
  return;
@@ -1,32 +1,7 @@
1
- // https://playwright.dev/docs/api/class-coverage
2
-
3
- // url, text, ranges: [ {start, end} ]
4
- const getCssSummaryBytes = (item) => {
5
-
6
- const source = item.source;
7
- const total = source.length;
8
-
9
- let covered = 0;
10
- const bytes = item.data.bytes;
11
- if (bytes) {
12
- bytes.forEach((range) => {
13
- if (range.count > 0) {
14
- covered += range.end - range.start;
15
- }
16
- });
17
- }
18
-
19
- // no functions for css
20
- return {
21
- total,
22
- covered
23
- };
24
-
25
- };
26
-
27
- // url, source, ranges:[{start,end, count}]
28
- const getJsSummaryBytes = (item) => {
1
+ const Util = require('../utils/util.js');
29
2
 
3
+ // both css and js
4
+ const getV8SummaryBytes = (item) => {
30
5
  const source = item.source;
31
6
  const total = source.length;
32
7
 
@@ -36,6 +11,10 @@ const getJsSummaryBytes = (item) => {
36
11
 
37
12
  let endPos = 0;
38
13
  uncoveredBytes.forEach((range) => {
14
+ if (range.ignored) {
15
+ return;
16
+ }
17
+
39
18
  const { start, end } = range;
40
19
 
41
20
  if (start > endPos) {
@@ -63,13 +42,85 @@ const getJsSummaryBytes = (item) => {
63
42
  };
64
43
  };
65
44
 
66
- const getV8SummaryBytes = (item) => {
67
- if (item.type === 'css') {
68
- return getCssSummaryBytes(item);
69
- }
70
- return getJsSummaryBytes(item);
45
+ // calculate uncovered, pct, status
46
+ const calculatePctAndStatus = (item, watermarks) => {
47
+ Object.keys(item).forEach((k) => {
48
+ const indicateData = item[k];
49
+ indicateData.uncovered = indicateData.total - indicateData.covered;
50
+
51
+ let pct = '';
52
+ let status = 'unknown';
53
+
54
+ if (indicateData.total) {
55
+ pct = Util.PNF(indicateData.covered, indicateData.total, 2);
56
+ status = Util.getStatus(pct, watermarks[k]);
57
+ }
58
+
59
+ indicateData.pct = pct;
60
+ indicateData.status = status;
61
+
62
+ });
63
+ };
64
+
65
+ const getV8Summary = (v8list, watermarks) => {
66
+
67
+ // get bytes summary
68
+ v8list.forEach((entry) => {
69
+ entry.summary.bytes = getV8SummaryBytes(entry);
70
+ });
71
+
72
+ // overall summary
73
+ const summary = {
74
+ bytes: {
75
+ total: 0,
76
+ covered: 0
77
+ },
78
+ functions: {
79
+ total: 0,
80
+ covered: 0
81
+ },
82
+ branches: {
83
+ total: 0,
84
+ covered: 0
85
+ },
86
+ lines: {
87
+ total: 0,
88
+ covered: 0,
89
+ blank: 0,
90
+ comment: 0
91
+ }
92
+ };
93
+
94
+ v8list.forEach((entry) => {
95
+ const entrySummary = entry.summary;
96
+ calculatePctAndStatus(entrySummary, watermarks);
97
+
98
+ // do NOT add debug file
99
+ if (entry.debug) {
100
+ return;
101
+ }
102
+
103
+ Object.keys(entrySummary).forEach((k) => {
104
+ const indicateData = entrySummary[k];
105
+ if (!indicateData) {
106
+ return;
107
+ }
108
+ summary[k].total += indicateData.total;
109
+ summary[k].covered += indicateData.covered;
110
+
111
+ if (k === 'lines') {
112
+ summary[k].blank += indicateData.blank;
113
+ summary[k].comment += indicateData.comment;
114
+ }
115
+ });
116
+ });
117
+
118
+ // calculate overall summary
119
+ calculatePctAndStatus(summary, watermarks);
120
+
121
+ return summary;
71
122
  };
72
123
 
73
124
  module.exports = {
74
- getV8SummaryBytes
125
+ getV8Summary
75
126
  };
package/lib/v8/v8.js CHANGED
@@ -1,6 +1,6 @@
1
1
  const path = require('path');
2
2
  const Util = require('../utils/util.js');
3
- const { getV8SummaryBytes } = require('./v8-summary.js');
3
+ const { getV8Summary } = require('./v8-summary.js');
4
4
  const { dedupeRanges } = require('../utils/dedupe.js');
5
5
  const { getSourcePath } = require('../utils/source-path.js');
6
6
  const { mergeScriptCovs } = require('../packages/monocart-coverage-vendor.js');
@@ -221,27 +221,8 @@ const saveV8HtmlReport = async (reportData, options, v8HtmlOptions) => {
221
221
  return htmlPath;
222
222
  };
223
223
 
224
- // calculate uncovered, pct, status
225
- const calculatePctAndStatus = (item, watermarks) => {
226
- Object.keys(item).forEach((k) => {
227
- const indicateData = item[k];
228
- indicateData.uncovered = indicateData.total - indicateData.covered;
229
-
230
- let pct = '';
231
- let status = 'unknown';
232
-
233
- if (indicateData.total) {
234
- pct = Util.PNF(indicateData.covered, indicateData.total, 2);
235
- status = Util.getStatus(pct, watermarks[k]);
236
- }
237
-
238
- indicateData.pct = pct;
239
- indicateData.status = status;
240
-
241
- });
242
- };
243
-
244
224
  const saveV8Report = async (v8list, options) => {
225
+
245
226
  const defaultWatermarks = {
246
227
  bytes: [50, 80],
247
228
  functions: [50, 80],
@@ -250,51 +231,7 @@ const saveV8Report = async (v8list, options) => {
250
231
  };
251
232
  const watermarks = Util.resolveWatermarks(defaultWatermarks, options.watermarks);
252
233
 
253
- // init summary
254
- v8list.forEach((entry) => {
255
- entry.summary.bytes = getV8SummaryBytes(entry);
256
- });
257
-
258
- // overall summary
259
- const summaryList = v8list.map((entry) => entry.summary);
260
- const summary = {
261
- bytes: {
262
- total: 0,
263
- covered: 0
264
- },
265
- functions: {
266
- total: 0,
267
- covered: 0
268
- },
269
- branches: {
270
- total: 0,
271
- covered: 0
272
- },
273
- lines: {
274
- total: 0,
275
- covered: 0,
276
- blank: 0,
277
- comment: 0
278
- }
279
- };
280
- summaryList.forEach((item) => {
281
- calculatePctAndStatus(item, watermarks);
282
- Object.keys(item).forEach((k) => {
283
- const indicateData = item[k];
284
- if (!indicateData) {
285
- return;
286
- }
287
- summary[k].total += indicateData.total;
288
- summary[k].covered += indicateData.covered;
289
-
290
- if (k === 'lines') {
291
- summary[k].blank += indicateData.blank;
292
- summary[k].comment += indicateData.comment;
293
- }
294
- });
295
- });
296
-
297
- calculatePctAndStatus(summary, watermarks);
234
+ const summary = getV8Summary(v8list, watermarks);
298
235
 
299
236
  const reportData = {
300
237
  name: options.name,
@@ -338,7 +275,9 @@ const saveV8Report = async (v8list, options) => {
338
275
  return outputPath;
339
276
  });
340
277
 
341
- const report = {
278
+ const summaryList = v8list.map((entry) => entry.summary);
279
+
280
+ const coverageResults = {
342
281
  type: 'v8',
343
282
  reportPath,
344
283
  name: options.name,
@@ -347,7 +286,7 @@ const saveV8Report = async (v8list, options) => {
347
286
  files: summaryList
348
287
  };
349
288
 
350
- return report;
289
+ return coverageResults;
351
290
  };
352
291
 
353
292
  module.exports = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "monocart-coverage-reports",
3
- "version": "2.0.7",
3
+ "version": "2.0.9",
4
4
  "description": "Monocart coverage reports",
5
5
  "main": "lib/index.js",
6
6
  "exports": {
@@ -17,10 +17,11 @@
17
17
  "build-docs": "node ./scripts/build-docs.js",
18
18
  "build-test": "node ./scripts/build-test.js",
19
19
  "build": "sf lint && sf b -p && npm run build-test",
20
- "test-node": "npm run test-node-env && npm run test-node-ins && npm run test-node-api && npm run test-node-cdp",
21
- "test-node-env": "cross-env NODE_V8_COVERAGE=.temp/v8-coverage node ./test/test-node-env.js && node ./test/generate-node-report.js",
20
+ "test-node": "npm run test-node-env && npm run test-node-api && npm run test-node-fgc && npm run test-node-ins && npm run test-node-cdp",
21
+ "test-node-env": "cross-env NODE_V8_COVERAGE=.temp/v8-coverage-env node ./test/test-node-env.js && node ./test/generate-node-report.js",
22
+ "test-node-api": "cross-env NODE_V8_COVERAGE=.temp/v8-coverage-api node ./test/test-node-api.js",
23
+ "test-node-fgc": "node ./test/test-node-fgc.js",
22
24
  "test-node-ins": "node ./test/test-node-ins.js",
23
- "test-node-api": "cross-env NODE_V8_COVERAGE=.temp/v8-coverage node ./test/test-node-api.js",
24
25
  "test-node-cdp": "node --inspect=9229 ./test/test-node-cdp.js",
25
26
  "test-browser": "node ./test/test.js",
26
27
  "test": "npm run test-browser && npm run test-node && npm run build-docs",