monocart-coverage-reports 2.9.3 → 2.10.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.
@@ -1,132 +1,132 @@
1
- const os = require('os');
2
-
3
- const renderLine = (ls, padding) => {
4
- const spacing = ''.padEnd(padding, ' ');
5
- const line = ls.join(`${spacing}|${spacing}`);
6
- return `|${spacing}${line}${spacing}|`;
7
- };
8
-
9
- const renderCell = (cellValue, column) => {
10
-
11
- // To include a pipe | as content within your cell, use a \ before the pipe:
12
- cellValue = cellValue.split(/\\?\|/g).join('\\|');
13
- const valueWidth = cellValue.length;
14
- const width = column.width;
15
-
16
- if (width <= valueWidth) {
17
- return cellValue;
18
- }
19
-
20
- const spacingWidth = width - valueWidth;
21
- const spacing = ''.padEnd(spacingWidth, ' ');
22
-
23
- const align = column.align;
24
-
25
- if (align === 'right') {
26
- return spacing + cellValue;
27
- }
28
-
29
- if (align === 'center') {
30
- const l = Math.round(spacingWidth * 0.5);
31
- const r = spacingWidth - l;
32
- const spacingL = ''.padEnd(l, ' ');
33
- const spacingR = ''.padEnd(r, ' ');
34
- return spacingL + cellValue + spacingR;
35
-
36
- }
37
-
38
- return cellValue + spacing;
39
- };
40
-
41
- const renderHyphen = (column) => {
42
- const width = column.width;
43
- const align = column.align;
44
- if (align === 'right') {
45
- return ':'.padStart(width, '-');
46
- }
47
- if (align === 'center') {
48
- const hyphen = ''.padEnd(width - 2, '-');
49
- return `:${hyphen}:`;
50
- }
51
- // default to left
52
- return ':'.padEnd(width, '-');
53
- };
54
-
55
- const generateMarkdownGrid = (data) => {
56
-
57
- const options = {
58
- name: '',
59
- padding: 1,
60
- nullPlaceholder: '',
61
- ... data.options
62
- };
63
-
64
- const padding = options.padding;
65
-
66
- // console.log(data, options);
67
-
68
- const lines = [];
69
-
70
- if (options.name) {
71
- lines.push(`## ${options.name}`);
72
- }
73
-
74
- // init columns
75
- const columns = data.columns.map((item) => {
76
- if (typeof item === 'string') {
77
- item = {
78
- name: item
79
- };
80
- }
81
- const column = {
82
- ... item
83
- };
84
- column.name = `${column.name}`;
85
- if (typeof column.width !== 'number') {
86
- column.width = column.name.length;
87
- }
88
- column.width = Math.max(column.width, 3);
89
- return column;
90
- });
91
-
92
- // header
93
- const headers = [];
94
- columns.forEach((column) => {
95
- headers.push(renderCell(column.name, column));
96
- });
97
- lines.push(renderLine(headers, padding));
98
-
99
- const hyphens = [];
100
- columns.forEach((column) => {
101
- hyphens.push(renderHyphen(column));
102
- });
103
- lines.push(renderLine(hyphens, padding));
104
-
105
- // rows
106
- data.rows.forEach((row) => {
107
- const cells = [];
108
- columns.forEach((column, i) => {
109
- let cellValue = '';
110
- if (Array.isArray(row)) {
111
- cellValue += row[i];
112
- } else {
113
- let v = row[column.id];
114
- if (typeof v === 'undefined' || v === null) {
115
- v = options.nullPlaceholder;
116
- }
117
- if (column.formatter) {
118
- v = column.formatter(v, row, column);
119
- }
120
- cellValue += v;
121
- }
122
- cells.push(renderCell(cellValue, column));
123
- });
124
- lines.push(renderLine(cells, padding));
125
- });
126
-
127
- return lines.join(os.EOL) + os.EOL;
128
-
129
- };
130
-
131
-
132
- module.exports = generateMarkdownGrid;
1
+ const os = require('os');
2
+
3
+ const renderLine = (ls, padding) => {
4
+ const spacing = ''.padEnd(padding, ' ');
5
+ const line = ls.join(`${spacing}|${spacing}`);
6
+ return `|${spacing}${line}${spacing}|`;
7
+ };
8
+
9
+ const renderCell = (cellValue, column) => {
10
+
11
+ // To include a pipe | as content within your cell, use a \ before the pipe:
12
+ cellValue = cellValue.split(/\\?\|/g).join('\\|');
13
+ const valueWidth = cellValue.length;
14
+ const width = column.width;
15
+
16
+ if (width <= valueWidth) {
17
+ return cellValue;
18
+ }
19
+
20
+ const spacingWidth = width - valueWidth;
21
+ const spacing = ''.padEnd(spacingWidth, ' ');
22
+
23
+ const align = column.align;
24
+
25
+ if (align === 'right') {
26
+ return spacing + cellValue;
27
+ }
28
+
29
+ if (align === 'center') {
30
+ const l = Math.round(spacingWidth * 0.5);
31
+ const r = spacingWidth - l;
32
+ const spacingL = ''.padEnd(l, ' ');
33
+ const spacingR = ''.padEnd(r, ' ');
34
+ return spacingL + cellValue + spacingR;
35
+
36
+ }
37
+
38
+ return cellValue + spacing;
39
+ };
40
+
41
+ const renderHyphen = (column) => {
42
+ const width = column.width;
43
+ const align = column.align;
44
+ if (align === 'right') {
45
+ return ':'.padStart(width, '-');
46
+ }
47
+ if (align === 'center') {
48
+ const hyphen = ''.padEnd(width - 2, '-');
49
+ return `:${hyphen}:`;
50
+ }
51
+ // default to left
52
+ return ':'.padEnd(width, '-');
53
+ };
54
+
55
+ const generateMarkdownGrid = (data) => {
56
+
57
+ const options = {
58
+ name: '',
59
+ padding: 1,
60
+ nullPlaceholder: '',
61
+ ... data.options
62
+ };
63
+
64
+ const padding = options.padding;
65
+
66
+ // console.log(data, options);
67
+
68
+ const lines = [];
69
+
70
+ if (options.name) {
71
+ lines.push(`## ${options.name}`);
72
+ }
73
+
74
+ // init columns
75
+ const columns = data.columns.map((item) => {
76
+ if (typeof item === 'string') {
77
+ item = {
78
+ name: item
79
+ };
80
+ }
81
+ const column = {
82
+ ... item
83
+ };
84
+ column.name = `${column.name}`;
85
+ if (typeof column.width !== 'number') {
86
+ column.width = column.name.length;
87
+ }
88
+ column.width = Math.max(column.width, 3);
89
+ return column;
90
+ });
91
+
92
+ // header
93
+ const headers = [];
94
+ columns.forEach((column) => {
95
+ headers.push(renderCell(column.name, column));
96
+ });
97
+ lines.push(renderLine(headers, padding));
98
+
99
+ const hyphens = [];
100
+ columns.forEach((column) => {
101
+ hyphens.push(renderHyphen(column));
102
+ });
103
+ lines.push(renderLine(hyphens, padding));
104
+
105
+ // rows
106
+ data.rows.forEach((row) => {
107
+ const cells = [];
108
+ columns.forEach((column, i) => {
109
+ let cellValue = '';
110
+ if (Array.isArray(row)) {
111
+ cellValue += row[i];
112
+ } else {
113
+ let v = row[column.id];
114
+ if (typeof v === 'undefined' || v === null) {
115
+ v = options.nullPlaceholder;
116
+ }
117
+ if (column.formatter) {
118
+ v = column.formatter(v, row, column);
119
+ }
120
+ cellValue += v;
121
+ }
122
+ cells.push(renderCell(cellValue, column));
123
+ });
124
+ lines.push(renderLine(cells, padding));
125
+ });
126
+
127
+ return lines.join(os.EOL) + os.EOL;
128
+
129
+ };
130
+
131
+
132
+ module.exports = generateMarkdownGrid;
package/lib/utils/util.js CHANGED
@@ -8,10 +8,8 @@ const EC = require('eight-colors');
8
8
  const CG = require('console-grid');
9
9
  const Share = require('../platform/share.js');
10
10
  const request = require('./request.js');
11
- const { deflateSync } = require('lz-utils');
12
-
11
+ const version = require('../../package.json').version;
13
12
  const acornWalk = require('acorn-walk');
14
-
15
13
  const { findUpSync, supportsColor } = require('../packages/monocart-coverage-vendor.js');
16
14
 
17
15
  // https://github.com/chalk/supports-color
@@ -21,6 +19,8 @@ if (!supportsColor.stdout) {
21
19
  }
22
20
 
23
21
  const Util = {
22
+ version,
23
+
24
24
  ... Share,
25
25
 
26
26
  EC,
@@ -149,42 +149,6 @@ const Util = {
149
149
  return htmlPathHandler();
150
150
  },
151
151
 
152
- resolveNodeModule: (id) => {
153
-
154
- // for deno npm module
155
- const mp = require.resolve(id);
156
- if (fs.existsSync(mp)) {
157
- return mp;
158
- }
159
-
160
- const p = `${it}/dist/${it}.js`;
161
- // root
162
- const cwd = path.resolve('node_modules', p);
163
- if (fs.existsSync(cwd)) {
164
- return cwd;
165
- }
166
-
167
- // sub node modules
168
- const sub = path.resolve(__dirname, '../../node_modules', p);
169
- if (fs.existsSync(sub)) {
170
- return sub;
171
- }
172
-
173
- // same level dep
174
- const dep = path.resolve(__dirname, '../../../', p);
175
- if (fs.existsSync(dep)) {
176
- return dep;
177
- }
178
-
179
- Util.logError(`Not found module: ${p}`);
180
-
181
- return cwd;
182
- },
183
-
184
- resolvePackage: (p) => {
185
- return path.resolve(__dirname, '../packages', p);
186
- },
187
-
188
152
  getCacheFileInfo: (type, id, cacheDir) => {
189
153
  const cacheName = `${type}-${id}.json`;
190
154
  const cachePath = path.resolve(cacheDir, cacheName);
@@ -219,76 +183,6 @@ const Util = {
219
183
  // default config not found
220
184
  },
221
185
 
222
- saveHtmlReport: async (options) => {
223
-
224
- const {
225
- inline,
226
- reportData,
227
- jsFiles,
228
- assetsPath,
229
- outputDir,
230
- htmlFile,
231
-
232
- reportDataFile
233
- } = options;
234
-
235
- // report data
236
- const reportDataCompressed = deflateSync(JSON.stringify(reportData));
237
- const reportDataStr = `window.reportData = '${reportDataCompressed}';`;
238
-
239
- // js libs
240
- const jsList = [];
241
- for (const jsFile of jsFiles) {
242
- const jsStr = await Util.readFile(jsFile);
243
- jsList.push({
244
- filename: path.basename(jsFile),
245
- str: jsStr
246
- });
247
- }
248
-
249
- // html content
250
- let htmlStr = '';
251
- const EOL = Util.getEOL();
252
- if (inline) {
253
- htmlStr = [
254
- '<script>',
255
- reportDataStr,
256
- ... jsList.map((it) => it.str),
257
- '</script>'
258
- ].join(EOL);
259
- } else {
260
-
261
- await Util.writeFile(path.resolve(outputDir, reportDataFile), reportDataStr);
262
-
263
- const assetsDir = path.resolve(outputDir, assetsPath);
264
- const relAssetsDir = Util.relativePath(assetsDir, outputDir);
265
-
266
- for (const item of jsList) {
267
- const filePath = path.resolve(assetsDir, item.filename);
268
- if (!fs.existsSync(filePath)) {
269
- await Util.writeFile(filePath, item.str);
270
- }
271
- }
272
-
273
- htmlStr = [
274
- `<script src="${reportDataFile}"></script>`,
275
- ... jsList.map((it) => `<script src="${relAssetsDir}/${it.filename}"></script>`)
276
- ].join(EOL);
277
- }
278
-
279
- // html
280
- const htmlPath = path.resolve(outputDir, htmlFile);
281
- const template = Util.getTemplate(path.resolve(__dirname, '../default/template.html'));
282
- const html = Util.replace(template, {
283
- title: reportData.title,
284
- content: htmlStr
285
- });
286
-
287
- await Util.writeFile(htmlPath, html);
288
-
289
- return Util.relativePath(htmlPath);
290
- },
291
-
292
186
  runCustomReporter: async (reportName, reportData, reportOptions, globalOptions) => {
293
187
  let CustomReporter;
294
188
  let err;
@@ -485,26 +379,16 @@ const Util = {
485
379
  }
486
380
  },
487
381
 
488
- getTemplate: function(templatePath) {
489
- if (!Util.templateCache) {
490
- Util.templateCache = {};
491
- }
492
- let template = Util.templateCache[templatePath];
493
- if (!template) {
494
- template = Util.readFileSync(templatePath);
495
- if (template) {
496
- Util.templateCache[templatePath] = template;
497
- } else {
498
- Util.logError(`not found template: ${templatePath}`);
499
- }
500
- }
501
- return template;
502
- },
503
-
504
382
  normalizeColorType: (color) => {
505
383
  return `${color}`.trim().toLowerCase();
506
384
  },
507
385
 
386
+ normalizeMaxCols: (maxCols, min = 1) => {
387
+ if (Util.isNum(maxCols)) {
388
+ return Math.max(maxCols, min);
389
+ }
390
+ },
391
+
508
392
  getColorStrByStatus: (str, status, color = '') => {
509
393
 
510
394
  const colorHandlers = {
@@ -545,7 +429,7 @@ const Util = {
545
429
  return str;
546
430
  },
547
431
  'tex': () => {
548
- const texStr = str.replace('%', '\\\\%');
432
+ const texStr = str.replace(/%/g, '\\\\%');
549
433
  if (status === 'low') {
550
434
  return `$\\color{red}{\\textsf{${texStr}}}$`;
551
435
  }
package/lib/v8/v8.js CHANGED
@@ -1,8 +1,5 @@
1
- const path = require('path');
2
1
  const EC = require('eight-colors');
3
- const { minimatch } = require('minimatch');
4
2
  const { mergeScriptCovs } = require('@bcoe/v8-coverage');
5
-
6
3
  const Util = require('../utils/util.js');
7
4
  const { getV8Summary } = require('./v8-summary.js');
8
5
  const { dedupeFlatRanges } = require('../utils/dedupe.js');
@@ -10,7 +7,10 @@ const {
10
7
  resolveAnonymousUrl, normalizeSourcePath, getSourcePathReplacer
11
8
  } = require('../utils/source-path.js');
12
9
  const { collectSourceMaps } = require('../converter/collect-source-maps.js');
13
- const version = require('../../package.json').version;
10
+ const { minimatch } = require('../packages/monocart-coverage-vendor.js');
11
+
12
+ const { v8Report } = require('../reports/v8.js');
13
+ const { v8JsonReport } = require('../reports/v8-json.js');
14
14
 
15
15
  const getWrapperSource = (offset, source) => {
16
16
  // NO \n because it break line number in mappings
@@ -313,68 +313,6 @@ const mergeV8Coverage = async (dataList, sourceCache, options) => {
313
313
 
314
314
  // ============================================================
315
315
 
316
- const handleV8JsonReport = async (reportData, reportOptions, options) => {
317
- const v8JsonOptions = {
318
- outputFile: 'coverage-report.json',
319
- ... reportOptions
320
- };
321
-
322
- // console.log(mergedOptions);
323
- const jsonPath = path.resolve(options.outputDir, v8JsonOptions.outputFile);
324
- await Util.writeFile(jsonPath, JSON.stringify(reportData));
325
- return Util.relativePath(jsonPath);
326
- };
327
-
328
-
329
- const handleV8HtmlReport = async (reportData, reportOptions, options) => {
330
-
331
- // V8 only options, merged with root options
332
- const v8HtmlOptions = {
333
- outputFile: options.outputFile,
334
- inline: options.inline,
335
- assetsPath: options.assetsPath,
336
- metrics: options.metrics,
337
- ... reportOptions
338
- };
339
-
340
- // add metrics to data for UI
341
- reportData.metrics = v8HtmlOptions.metrics;
342
-
343
- const {
344
- outputFile, inline, assetsPath
345
- } = v8HtmlOptions;
346
-
347
- // resolve full report path
348
- const reportPath = path.resolve(options.outputDir, outputFile);
349
- const outputDir = path.dirname(reportPath);
350
- const htmlFile = path.basename(reportPath);
351
-
352
- // deps
353
- const jsFiles = ['monocart-code-viewer', 'monocart-formatter', 'turbogrid'].map((id) => {
354
- return Util.resolveNodeModule(id);
355
- });
356
-
357
- // package app ui
358
- jsFiles.push(Util.resolvePackage('monocart-coverage-app.js'));
359
-
360
- // console.log(jsFiles);
361
-
362
- const htmlOptions = {
363
- reportData,
364
- jsFiles,
365
- inline,
366
- assetsPath,
367
- outputDir,
368
- htmlFile,
369
-
370
- reportDataFile: 'coverage-data.js'
371
- };
372
-
373
- const htmlPath = await Util.saveHtmlReport(htmlOptions);
374
-
375
- return htmlPath;
376
- };
377
-
378
316
  const saveV8Report = async (v8list, options, istanbulReportPath) => {
379
317
 
380
318
  const defaultWatermarks = {
@@ -389,8 +327,11 @@ const saveV8Report = async (v8list, options, istanbulReportPath) => {
389
327
  const summary = getV8Summary(v8list, watermarks);
390
328
 
391
329
  const reportData = {
330
+ type: 'v8',
331
+ // override with saved file path
332
+ reportPath: '',
333
+ version: Util.version,
392
334
  name: options.name,
393
- version,
394
335
  watermarks,
395
336
  summary,
396
337
  files: v8list
@@ -398,17 +339,15 @@ const saveV8Report = async (v8list, options, istanbulReportPath) => {
398
339
 
399
340
  // v8 only reports
400
341
  const buildInV8Reports = {
401
- 'v8': handleV8HtmlReport,
402
- 'v8-json': handleV8JsonReport
342
+ 'v8': v8Report,
343
+ 'v8-json': v8JsonReport
403
344
  };
404
345
 
405
346
  const outputs = {};
406
- const v8Group = options.reportGroup.v8;
347
+ const v8Group = options.reportGroup.get('v8');
407
348
  // could be no v8 only reports, but have `both` data reports
408
349
  if (v8Group) {
409
- const v8Reports = Object.keys(v8Group);
410
- for (const reportName of v8Reports) {
411
- const reportOptions = v8Group[reportName];
350
+ for (const [reportName, reportOptions] of v8Group) {
412
351
  const buildInHandler = buildInV8Reports[reportName];
413
352
  const t1 = Date.now();
414
353
  if (buildInHandler) {
@@ -431,7 +370,9 @@ const saveV8Report = async (v8list, options, istanbulReportPath) => {
431
370
 
432
371
  const coverageResults = {
433
372
  type: 'v8',
373
+ // html or json
434
374
  reportPath,
375
+ version: Util.version,
435
376
  name: options.name,
436
377
  watermarks,
437
378
  summary,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "monocart-coverage-reports",
3
- "version": "2.9.3",
3
+ "version": "2.10.0",
4
4
  "description": "A code coverage tool to generate native V8 reports or Istanbul reports.",
5
5
  "main": "./lib/index.js",
6
6
  "bin": {
@@ -54,6 +54,7 @@
54
54
  "test-merge-istanbul": "node ./test/test-merge-istanbul.js",
55
55
  "test-client": "node ./test/test-client.js",
56
56
  "test-all": "node ./test/test.js && node ./scripts/docs.js",
57
+ "test-pr": "node --inspect=9230 ./test/test-pr.js",
57
58
  "test": "npm run test-unit && npx mcr npm run test-all -c test/mcr.config.mcr.js",
58
59
  "test:snap": "cross-env TEST_SNAPSHOT=true npm run test",
59
60
  "dev": "npx sf d app",
@@ -62,7 +63,6 @@
62
63
  "patch": "npm run build && npm run test && npx sf publish patch -r"
63
64
  },
64
65
  "workspaces": [
65
- "packages/*",
66
66
  "test"
67
67
  ],
68
68
  "files": [
@@ -82,31 +82,35 @@
82
82
  "acorn-walk": "^8.3.3",
83
83
  "commander": "^12.1.0",
84
84
  "console-grid": "^2.2.2",
85
- "diff-sequences": "^29.6.3",
86
85
  "eight-colors": "^1.3.0",
87
86
  "foreground-child": "^3.2.1",
88
87
  "istanbul-lib-coverage": "^3.2.2",
89
88
  "istanbul-lib-report": "^3.0.1",
90
89
  "istanbul-reports": "^3.1.7",
91
- "lz-utils": "^2.0.2",
92
- "minimatch": "9.0.5",
93
- "monocart-code-viewer": "^1.1.4",
94
- "monocart-formatter": "^3.0.0",
95
- "monocart-locator": "^1.0.2",
96
- "turbogrid": "^3.2.0"
90
+ "lz-utils": "^2.1.0",
91
+ "monocart-locator": "^1.0.2"
97
92
  },
98
93
  "devDependencies": {
94
+ "async-tick": "^1.0.0",
95
+ "convert-source-map": "^2.0.0",
96
+ "diff-sequences": "^29.6.3",
99
97
  "esbuild": "^0.23.0",
100
- "eslint": "~9.7.0",
98
+ "eslint": "~9.8.0",
101
99
  "eslint-config-plus": "^2.0.2",
102
100
  "eslint-plugin-html": "^8.1.1",
103
101
  "eslint-plugin-vue": "^9.27.0",
104
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",
105
107
  "starfall-cli": "^2.0.20",
106
108
  "stylelint": "^16.7.0",
107
109
  "stylelint-config-plus": "^1.1.2",
108
110
  "supports-color": "^9.4.0",
109
111
  "tsx": "^4.16.2",
112
+ "turbogrid": "^3.2.0",
113
+ "vine-ui": "^3.1.16",
110
114
  "ws": "^8.18.0"
111
115
  }
112
116
  }