monocart-coverage-reports
Advanced tools
Comparing version 2.4.4 to 2.5.0
@@ -75,2 +75,3 @@ const fs = require('fs'); | ||
'codecov': 'v8', | ||
'console-details': 'v8', | ||
@@ -130,18 +131,5 @@ // istanbul | ||
const capitalizeFirstLetter = (string) => { | ||
return string.charAt(0).toUpperCase() + string.slice(1); | ||
}; | ||
const pFormatter = (v, row, column) => { | ||
if (typeof v === 'number') { | ||
const p = Util.PSF(v, 100, 2); | ||
if (row.status === 'low') { | ||
return EC.red(p); | ||
} | ||
if (row.status === 'medium') { | ||
return EC.yellow(p); | ||
} | ||
if (row.status === 'high') { | ||
return EC.green(p); | ||
} | ||
return Util.getColorStrByStatus(Util.PSF(v, 100, 2), row.status); | ||
} | ||
@@ -158,5 +146,8 @@ return v; | ||
const showConsoleSummary = (reportData, reportOptions, options) => { | ||
const handleConsoleSummaryReport = (reportData, reportOptions, options) => { | ||
const { metrics } = reportOptions; | ||
const csOptions = { | ||
metrics: [], | ||
... reportOptions | ||
}; | ||
@@ -171,19 +162,8 @@ const { | ||
const allMetrics = { | ||
v8: ['bytes', 'statements', 'branches', 'functions', 'lines'], | ||
istanbul: ['statements', 'branches', 'functions', 'lines'] | ||
}; | ||
const metrics = Util.getMetrics(type, csOptions.metrics); | ||
let list = allMetrics[type]; | ||
if (Util.isList(metrics)) { | ||
const newList = list.filter((k) => metrics.includes(k)); | ||
if (newList.length) { | ||
list = newList; | ||
} | ||
} | ||
const rows = list.map((k) => { | ||
const rows = metrics.map((k) => { | ||
return { | ||
... summary[k], | ||
name: capitalizeFirstLetter(k) | ||
name: Util.capitalizeFirstLetter(k) | ||
}; | ||
@@ -223,3 +203,3 @@ }); | ||
const saveRawReport = (reportData, reportOptions, options) => { | ||
const handleRawReport = (reportData, reportOptions, options) => { | ||
const rawOptions = { | ||
@@ -293,4 +273,4 @@ outputDir: 'raw', | ||
const buildInBothReports = { | ||
'console-summary': showConsoleSummary, | ||
'raw': saveRawReport | ||
'console-summary': handleConsoleSummaryReport, | ||
'raw': handleRawReport | ||
}; | ||
@@ -297,0 +277,0 @@ |
@@ -39,2 +39,7 @@ declare namespace MCR { | ||
}] | | ||
['console-details'] | ['console-details', { | ||
maxCols?: number; | ||
skipPercent?: number; | ||
metrics?: Array<"bytes" | "statements" | "branches" | "functions" | "lines">; | ||
}] | | ||
['clover'] | ['clover', { | ||
@@ -41,0 +46,0 @@ file?: string; |
@@ -7,61 +7,2 @@ const Util = { | ||
attachments: { | ||
audit: { | ||
name: 'audit', | ||
contentType: 'text/html', | ||
reportFile: 'audit-report.json' | ||
}, | ||
coverage: { | ||
name: 'coverage', | ||
contentType: 'text/html', | ||
reportFile: 'coverage-report.json' | ||
}, | ||
network: { | ||
name: 'network', | ||
contentType: 'text/html', | ||
reportFile: 'network-report.json' | ||
}, | ||
// artifact will be removed finally | ||
artifact: { | ||
name: 'artifact', | ||
contentType: 'application/json' | ||
} | ||
}, | ||
pageTimings: [{ | ||
key: 'onContentLoad', | ||
name: 'Content Loaded', | ||
color: '#1a1aa6' | ||
}, { | ||
key: 'onLoad', | ||
name: 'Page Loaded', | ||
color: '#c80000' | ||
}], | ||
timings: [{ | ||
key: 'blocked', | ||
name: 'Blocking', | ||
color: '#858585' | ||
}, { | ||
key: 'dns', | ||
name: 'DNS Lookup', | ||
color: '#009688' | ||
}, { | ||
key: 'connect', | ||
name: 'Connecting', | ||
color: '#b52dcd' | ||
}, { | ||
key: 'send', | ||
name: 'Sending', | ||
color: '#74979a' | ||
}, { | ||
key: 'wait', | ||
name: 'Waiting', | ||
color: '#00a846' | ||
}, { | ||
key: 'receive', | ||
name: 'Receiving', | ||
color: '#0299de' | ||
}], | ||
hasOwn: function(obj, key) { | ||
@@ -194,2 +135,16 @@ return Object.prototype.hasOwnProperty.call(obj, key); | ||
getMetrics: (type, metrics) => { | ||
const istanbulMetrics = ['statements', 'branches', 'functions', 'lines']; | ||
const v8Metrics = ['bytes'].concat(istanbulMetrics); | ||
const allMetrics = type === 'v8' ? v8Metrics : istanbulMetrics; | ||
let list = allMetrics; | ||
if (Util.isList(metrics)) { | ||
const newList = list.filter((k) => metrics.includes(k)); | ||
if (newList.length) { | ||
list = newList; | ||
} | ||
} | ||
return list; | ||
}, | ||
generatePercentChart: function(percent) { | ||
@@ -414,2 +369,6 @@ return `<div style="--mcr-percent:${percent}%;" class="mcr-percent-chart"></div>`; | ||
capitalizeFirstLetter: (string) => { | ||
return string.charAt(0).toUpperCase() + string.slice(1); | ||
}, | ||
// ============================================================================= | ||
@@ -416,0 +375,0 @@ // formatter |
@@ -412,2 +412,15 @@ const fs = require('fs'); | ||
getColorStrByStatus: (str, status) => { | ||
if (status === 'low') { | ||
return EC.red(str); | ||
} | ||
if (status === 'medium') { | ||
return EC.yellow(str); | ||
} | ||
if (status === 'high') { | ||
return EC.green(str); | ||
} | ||
return str; | ||
}, | ||
// ========================================================================================== | ||
@@ -414,0 +427,0 @@ |
220
lib/v8/v8.js
const path = require('path'); | ||
const CG = require('console-grid'); | ||
const EC = require('eight-colors'); | ||
const Util = require('../utils/util.js'); | ||
@@ -236,3 +238,208 @@ const { getV8Summary } = require('./v8-summary.js'); | ||
const saveCodecovReport = async (reportData, reportOptions, options) => { | ||
const mergeSingleSubGroups = (item) => { | ||
if (!item.subs) { | ||
return; | ||
} | ||
if (item.subs.length === 1) { | ||
const sub = item.subs[0]; | ||
if (!sub.subs) { | ||
return; | ||
} | ||
item.name = [item.name, sub.name].filter((it) => it).join('/'); | ||
item.subs = sub.subs; | ||
mergeSingleSubGroups(item); | ||
return; | ||
} | ||
item.subs.forEach((sub) => { | ||
mergeSingleSubGroups(sub); | ||
}); | ||
}; | ||
const getRowData = (rowName, summary, metrics) => { | ||
const summaryRow = {}; | ||
let lowest = { | ||
pct: 100, | ||
status: 'high' | ||
}; | ||
metrics.map((k) => { | ||
const s = summary[k]; | ||
const percent = s.pct; | ||
if (typeof percent !== 'number') { | ||
return; | ||
} | ||
summaryRow[k] = Util.getColorStrByStatus(Util.PSF(percent, 100, 2), s.status); | ||
if (percent < lowest.pct) { | ||
lowest = s; | ||
} | ||
}); | ||
summaryRow.name = Util.getColorStrByStatus(rowName, lowest.status); | ||
return summaryRow; | ||
}; | ||
const getUncoveredLines = (file) => { | ||
const lines = []; | ||
const dataLines = file.data.lines; | ||
let startLine; | ||
let endLine; | ||
const addLines = () => { | ||
if (!startLine) { | ||
return; | ||
} | ||
if (endLine) { | ||
// range | ||
const link = startLine.color === 'yellow' && endLine.color === 'yellow' ? EC.yellow('-') : EC.red('-'); | ||
lines.push(EC[startLine.color](startLine.line) + link + EC[endLine.color](endLine.line)); | ||
startLine = null; | ||
endLine = null; | ||
} else { | ||
// only start | ||
lines.push(EC[startLine.color](startLine.line)); | ||
startLine = null; | ||
} | ||
}; | ||
const setLines = (line, color) => { | ||
if (startLine) { | ||
endLine = { | ||
line, | ||
color | ||
}; | ||
return; | ||
} | ||
startLine = { | ||
line, | ||
color | ||
}; | ||
}; | ||
Object.keys(dataLines).forEach((line) => { | ||
const count = dataLines[line]; | ||
if (count === 0) { | ||
setLines(line, 'red'); | ||
return; | ||
} | ||
// 0 < count < 1 | ||
if (typeof count === 'string') { | ||
setLines(line, 'yellow'); | ||
return; | ||
} | ||
// count >= 1 | ||
addLines(); | ||
}); | ||
addLines(); | ||
return lines.join(','); | ||
}; | ||
const getGroupedRows = (files, metrics, cdOptions) => { | ||
const skipPercent = cdOptions.skipPercent; | ||
if (typeof skipPercent === 'number' && skipPercent > 0) { | ||
files = files.filter((file) => { | ||
const { summary } = file; | ||
for (const k of metrics) { | ||
const percent = summary[k].pct; | ||
if (typeof percent === 'number' && percent < skipPercent) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
}); | ||
} | ||
let groups = []; | ||
files.forEach((file) => { | ||
const { sourcePath, summary } = file; | ||
const pathList = sourcePath.split('/'); | ||
const lastName = pathList.pop(); | ||
let subs = groups; | ||
pathList.forEach((key) => { | ||
const item = subs.find((it) => it.name === key && it.subs); | ||
if (item) { | ||
subs = item.subs; | ||
return; | ||
} | ||
const sub = { | ||
name: key, | ||
subs: [] | ||
}; | ||
subs.push(sub); | ||
subs = sub.subs; | ||
}); | ||
const fileRow = getRowData(lastName, summary, metrics); | ||
fileRow.uncoveredLines = getUncoveredLines(file); | ||
subs.push(fileRow); | ||
}); | ||
const group = { | ||
subs: groups | ||
}; | ||
mergeSingleSubGroups(group); | ||
if (group.name) { | ||
groups = [group]; | ||
} | ||
return groups; | ||
}; | ||
const handleConsoleDetailsReport = (reportData, reportOptions, options) => { | ||
const cdOptions = { | ||
maxCols: 50, | ||
skipPercent: 0, | ||
metrics: [], | ||
... reportOptions | ||
}; | ||
const { | ||
name, summary, files | ||
} = reportData; | ||
if (name) { | ||
EC.logCyan(name); | ||
} | ||
const metrics = Util.getMetrics('v8', cdOptions.metrics); | ||
const rows = getGroupedRows(files, metrics, cdOptions); | ||
const summaryRow = getRowData('Summary', summary, metrics); | ||
// no rows if skipped all by skipPercent | ||
if (rows.length) { | ||
rows.push({ | ||
innerBorder: true | ||
}); | ||
} | ||
rows.push(summaryRow); | ||
const columns = [{ | ||
id: 'name', | ||
name: 'Name' | ||
}, ... metrics.map((m) => { | ||
return { | ||
id: m, | ||
name: Util.capitalizeFirstLetter(m), | ||
align: 'right' | ||
}; | ||
}), { | ||
id: 'uncoveredLines', | ||
name: 'Uncovered Lines' | ||
}]; | ||
CG({ | ||
options: { | ||
nullPlaceholder: '', | ||
defaultMaxWidth: cdOptions.maxCols | ||
}, | ||
columns, | ||
rows | ||
}); | ||
}; | ||
const handleCodecovReport = async (reportData, reportOptions, options) => { | ||
const codecovOptions = { | ||
@@ -259,3 +466,3 @@ outputFile: 'codecov.json', | ||
const saveV8JsonReport = async (reportData, reportOptions, options) => { | ||
const handleV8JsonReport = async (reportData, reportOptions, options) => { | ||
const v8JsonOptions = { | ||
@@ -273,3 +480,3 @@ outputFile: 'coverage-report.json', | ||
const saveV8HtmlReport = async (reportData, reportOptions, options) => { | ||
const handleV8HtmlReport = async (reportData, reportOptions, options) => { | ||
@@ -346,5 +553,6 @@ // V8 only options, merged with root options | ||
const buildInV8Reports = { | ||
'v8': saveV8HtmlReport, | ||
'v8-json': saveV8JsonReport, | ||
'codecov': saveCodecovReport | ||
'v8': handleV8HtmlReport, | ||
'v8-json': handleV8JsonReport, | ||
'codecov': handleCodecovReport, | ||
'console-details': handleConsoleDetailsReport | ||
}; | ||
@@ -351,0 +559,0 @@ |
{ | ||
"name": "monocart-coverage-reports", | ||
"version": "2.4.4", | ||
"version": "2.5.0", | ||
"description": "Monocart coverage reports", | ||
@@ -57,3 +57,3 @@ "main": "./lib/index.js", | ||
"dependencies": { | ||
"console-grid": "~2.1.0", | ||
"console-grid": "~2.2.1", | ||
"eight-colors": "~1.2.1", | ||
@@ -60,0 +60,0 @@ "istanbul-lib-coverage": "~3.2.2", |
@@ -59,20 +59,18 @@ # Monocart Coverage Reports | ||
## Available Reports | ||
- `v8` (V8 data only) | ||
- Test in browser | ||
- Build with webpack: [V8](https://cenfun.github.io/monocart-coverage-reports/v8) and [V8 Minify](https://cenfun.github.io/monocart-coverage-reports/v8-minify) | ||
- Build with [Rollup](https://cenfun.github.io/monocart-coverage-reports/v8-rollup) and [Esbuild](https://cenfun.github.io/monocart-coverage-reports/v8-esbuild) | ||
- Collect with [puppeteer](https://cenfun.github.io/monocart-coverage-reports/puppeteer/) | ||
- [anonymous](https://cenfun.github.io/monocart-coverage-reports/anonymous/) and [css](https://cenfun.github.io/monocart-coverage-reports/css/) | ||
- Test in Node.js | ||
- Collect with [env](https://cenfun.github.io/monocart-coverage-reports/v8-node-env), and also V8 [API](https://cenfun.github.io/monocart-coverage-reports/v8-node-api), [Inspector](https://cenfun.github.io/monocart-coverage-reports/v8-node-ins) and [CDP](https://cenfun.github.io/monocart-coverage-reports/v8-node-cdp) | ||
- Web server example: [koa](https://cenfun.github.io/monocart-coverage-reports/v8-node-koa/) | ||
> V8 build-in reports (V8 data only): | ||
- `v8` | ||
- Browser: Build with webpack [V8](https://cenfun.github.io/monocart-coverage-reports/v8) and [V8 Minify](https://cenfun.github.io/monocart-coverage-reports/v8-minify); Build with [Rollup](https://cenfun.github.io/monocart-coverage-reports/v8-rollup) and [Esbuild](https://cenfun.github.io/monocart-coverage-reports/v8-esbuild); Collect with [puppeteer](https://cenfun.github.io/monocart-coverage-reports/puppeteer/); [anonymous](https://cenfun.github.io/monocart-coverage-reports/anonymous/) and [css](https://cenfun.github.io/monocart-coverage-reports/css/) | ||
- Node.js: Collect with [env](https://cenfun.github.io/monocart-coverage-reports/v8-node-env), and also V8 [API](https://cenfun.github.io/monocart-coverage-reports/v8-node-api), [Inspector](https://cenfun.github.io/monocart-coverage-reports/v8-node-ins) and [CDP](https://cenfun.github.io/monocart-coverage-reports/v8-node-cdp); Web server example: [koa](https://cenfun.github.io/monocart-coverage-reports/v8-node-koa/) | ||
![](test/v8.gif) | ||
- `v8-json` (V8 data only) | ||
- `v8-json` | ||
- [V8 coverage-report.json](https://cenfun.github.io/monocart-coverage-reports/v8-and-istanbul/coverage-report.json) | ||
- `codecov` (V8 data only) | ||
- `codecov` | ||
- coverage data for [Codecov](https://docs.codecov.com/docs/codecov-custom-coverage-format), see [example](https://app.codecov.io/github/cenfun/monocart-coverage-reports) | ||
- `console-details` Show file coverage and uncovered lines in the console. Like `text`, but for V8. | ||
> Istanbul [build-in reports](https://github.com/istanbuljs/istanbuljs/tree/master/packages/istanbul-reports/lib) | ||
![](test/console-details.png) | ||
> Istanbul build-in reports (both V8 and istanbul data): | ||
- `clover` | ||
@@ -97,5 +95,7 @@ - `cobertura` | ||
> Other reports | ||
- `console-summary` shows coverage summary in console | ||
> Other reports: | ||
- `console-summary` shows coverage summary in the console | ||
![](test/console-summary.png) | ||
- `raw` only keep all original data, which can be used for other reports input with `inputDir` | ||
@@ -102,0 +102,0 @@ - see [Merge Coverage Reports](#merge-coverage-reports) |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
917798
7562
+ Addedconsole-grid@2.2.2(transitive)
- Removedconsole-grid@2.1.0(transitive)
Updatedconsole-grid@~2.2.1