-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
567 additions
and
491 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
const path = require('path'); | ||
const Util = require('../utils/util.js'); | ||
|
||
const codacyReport = async (reportData, reportOptions, options) => { | ||
const codacyOptions = { | ||
outputFile: 'codacy.json', | ||
... reportOptions | ||
}; | ||
|
||
const jsonPath = path.resolve(options.outputDir, codacyOptions.outputFile); | ||
|
||
// https://api.codacy.com/swagger#tocscoveragereport | ||
const fileReports = []; | ||
reportData.files.forEach((item) => { | ||
const { sourcePath, data } = item; | ||
|
||
const coverage = {}; | ||
for (const [key, value] of Object.entries(data.lines)) { | ||
if (typeof value === 'number') { | ||
coverage[key] = value; | ||
} else { | ||
// partial coverage not supported? | ||
coverage[key] = 0; | ||
} | ||
} | ||
|
||
fileReports.push({ | ||
filename: sourcePath, | ||
coverage | ||
}); | ||
}); | ||
const codacyData = { | ||
fileReports | ||
}; | ||
|
||
await Util.writeFile(jsonPath, JSON.stringify(codacyData)); | ||
return Util.relativePath(jsonPath); | ||
}; | ||
|
||
|
||
module.exports = { | ||
codacyReport | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const path = require('path'); | ||
const Util = require('../utils/util.js'); | ||
|
||
const codecovReport = async (reportData, reportOptions, options) => { | ||
const codecovOptions = { | ||
outputFile: 'codecov.json', | ||
... reportOptions | ||
}; | ||
|
||
const jsonPath = path.resolve(options.outputDir, codecovOptions.outputFile); | ||
|
||
// https://docs.codecov.com/docs/codecov-custom-coverage-format | ||
const coverage = {}; | ||
reportData.files.forEach((item) => { | ||
const { sourcePath, data } = item; | ||
coverage[sourcePath] = data.lines; | ||
}); | ||
const codecovData = { | ||
coverage | ||
}; | ||
|
||
await Util.writeFile(jsonPath, JSON.stringify(codecovData)); | ||
return Util.relativePath(jsonPath); | ||
}; | ||
|
||
module.exports = { | ||
codecovReport | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
const CG = require('console-grid'); | ||
const EC = require('eight-colors'); | ||
const { getGroupedRows } = require('../utils/snapshot.js'); | ||
const Util = require('../utils/util.js'); | ||
|
||
const getRowData = (rowName, summary, metrics, color) => { | ||
const summaryRow = {}; | ||
let lowest = { | ||
pct: 100, | ||
status: 'high' | ||
}; | ||
metrics.map((k) => { | ||
const s = summary[k]; | ||
if (!s) { | ||
return; | ||
} | ||
const percent = s.pct; | ||
if (typeof percent !== 'number') { | ||
return; | ||
} | ||
summaryRow[k] = Util.getColorStrByStatus(Util.PSF(percent, 100, 2), s.status, color); | ||
if (percent < lowest.pct) { | ||
lowest = s; | ||
} | ||
}); | ||
summaryRow.nameStatus = lowest.status; | ||
summaryRow.name = rowName; | ||
return summaryRow; | ||
}; | ||
|
||
const getDetailsRows = (files, metrics, cdOptions, color) => { | ||
|
||
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; | ||
}); | ||
} | ||
|
||
const flatRows = []; | ||
files.forEach((file) => { | ||
|
||
// do NOT add debug file | ||
if (file.debug) { | ||
return; | ||
} | ||
|
||
const { sourcePath, summary } = file; | ||
const fileRow = getRowData(sourcePath, summary, metrics, color); | ||
fileRow.uncoveredLines = Util.getUncoveredLines(file.data.lines, color); | ||
flatRows.push(fileRow); | ||
}); | ||
|
||
return getGroupedRows(flatRows); | ||
}; | ||
|
||
|
||
const consoleDetailsReport = (reportData, reportOptions, options) => { | ||
const cdOptions = { | ||
maxCols: 50, | ||
skipPercent: 0, | ||
metrics: [], | ||
... reportOptions | ||
}; | ||
|
||
const { | ||
type, name, summary, files | ||
} = reportData; | ||
|
||
if (name) { | ||
Util.logInfo(EC.cyan(name)); | ||
} | ||
|
||
const color = 'ansicode'; | ||
|
||
const metrics = Util.getMetrics(cdOptions.metrics, type); | ||
const rows = getDetailsRows(files, metrics, cdOptions, color); | ||
const summaryRow = getRowData('Summary', summary, metrics, color); | ||
if (summaryRow.nameStatus) { | ||
summaryRow.name = Util.getColorStrByStatus(summaryRow.name, summaryRow.nameStatus, color); | ||
} | ||
// 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' | ||
}]; | ||
|
||
return CG({ | ||
options: { | ||
silent: cdOptions.silent, | ||
nullPlaceholder: '', | ||
defaultMaxWidth: cdOptions.maxCols | ||
}, | ||
columns, | ||
rows | ||
}); | ||
}; | ||
|
||
module.exports = { | ||
getRowData, | ||
consoleDetailsReport | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
const CG = require('console-grid'); | ||
const EC = require('eight-colors'); | ||
const Util = require('../utils/util.js'); | ||
|
||
const nFormatter = (v) => { | ||
if (typeof v === 'number') { | ||
return Util.NF(v); | ||
} | ||
return v; | ||
}; | ||
|
||
|
||
const getSummaryColumns = (color) => { | ||
|
||
const columns = [{ | ||
id: 'name', | ||
name: 'Name' | ||
}, { | ||
id: 'pct', | ||
name: 'Coverage %', | ||
align: 'right', | ||
formatter: (v, row, column) => { | ||
if (typeof v === 'number') { | ||
return Util.getColorStrByStatus(Util.PSF(v, 100, 2), row.status, color); | ||
} | ||
return v; | ||
} | ||
}, { | ||
id: 'covered', | ||
name: 'Covered', | ||
align: 'right', | ||
formatter: nFormatter | ||
}, { | ||
id: 'uncovered', | ||
name: 'Uncovered', | ||
align: 'right', | ||
formatter: nFormatter | ||
}, { | ||
id: 'total', | ||
name: 'Total', | ||
align: 'right', | ||
formatter: nFormatter | ||
}]; | ||
|
||
return columns; | ||
}; | ||
|
||
const consoleSummaryReport = (reportData, reportOptions, options) => { | ||
|
||
const csOptions = { | ||
metrics: [], | ||
... reportOptions | ||
}; | ||
|
||
const { | ||
summary, name, type | ||
} = reportData; | ||
|
||
if (name) { | ||
Util.logInfo(EC.cyan(name)); | ||
} | ||
|
||
const metrics = Util.getMetrics(csOptions.metrics, type); | ||
|
||
const rows = metrics.map((k) => { | ||
return { | ||
... summary[k], | ||
name: Util.capitalizeFirstLetter(k) | ||
}; | ||
}); | ||
|
||
const columns = getSummaryColumns('ansicode'); | ||
|
||
CG({ | ||
columns, | ||
rows | ||
}); | ||
}; | ||
|
||
module.exports = { | ||
getSummaryColumns, | ||
consoleSummaryReport | ||
}; |
Oops, something went wrong.