diff --git a/CHANGELOG.md b/CHANGELOG.md index 671f8b25..3fa8373f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## Changelog +- 2.8.7 + - fixed OOM with better GC + - added new build-in report: `codacy` (codacy.json) + - 2.8.6 - improved performance - fixed warning message for adding empty istanbul coverage diff --git a/lib/converter/converter.js b/lib/converter/converter.js index d2bd919e..89229561 100644 --- a/lib/converter/converter.js +++ b/lib/converter/converter.js @@ -147,8 +147,7 @@ const handleLinesCoverage = (bytes, locator, ignoredRanges) => { blank: blankCount, comment: commentCount }; - // data lines for codecov - // https://docs.codecov.com/docs/codecov-custom-coverage-format + // data lines const dataLines = {}; // no ignore items diff --git a/lib/generate.js b/lib/generate.js index 801f8409..aec72702 100644 --- a/lib/generate.js +++ b/lib/generate.js @@ -90,6 +90,7 @@ const getReportGroup = (reports, lcov, dataType) => { // both 'codecov': 'both', + 'codacy': 'both', 'console-details': 'both', 'console-summary': 'both', 'raw': 'both' @@ -280,6 +281,42 @@ const handleCodecovReport = async (reportData, reportOptions, options) => { return Util.relativePath(jsonPath); }; +const handleCodacyReport = 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); +}; + const handleConsoleDetailsReport = (reportData, reportOptions, options) => { const cdOptions = { maxCols: 50, @@ -464,6 +501,7 @@ const generateCoverageReports = async (dataList, sourceCache, options) => { const buildInBothReports = { 'codecov': handleCodecovReport, + 'codacy': handleCodacyReport, 'console-details': handleConsoleDetailsReport, 'console-summary': handleConsoleSummaryReport, 'raw': handleRawReport diff --git a/lib/index.d.ts b/lib/index.d.ts index 50f455fb..bc142722 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -107,6 +107,9 @@ declare namespace MCR { ['codecov'] | ["codecov", { outputFile?: string; }] | + ['codacy'] | ["codacy", { + outputFile?: string; + }] | ['console-summary'] | ['console-summary', { metrics?: Array<"bytes" | "statements" | "branches" | "functions" | "lines">; }] | @@ -190,7 +193,7 @@ declare namespace MCR { branches?: CoverageRange[]; functions?: CoverageRange[]; ignores?: IgnoredRange[]; - /** codecov json format */ + /** common json format */ lines: { [key: string]: number | string; };