Skip to content

Commit

Permalink
fix!: remove covered line adjustment in deploy coverage reports
Browse files Browse the repository at this point in the history
  • Loading branch information
mcarvin8 committed Dec 22, 2024
1 parent 6d66a5d commit 16db162
Show file tree
Hide file tree
Showing 15 changed files with 309 additions and 661 deletions.
242 changes: 120 additions & 122 deletions README.md

Large diffs are not rendered by default.

8 changes: 0 additions & 8 deletions src/helpers/getTotalLines.ts

This file was deleted.

48 changes: 48 additions & 0 deletions src/helpers/handleCloverFormat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
'use strict';
/* eslint-disable no-param-reassign */

import { CloverCoverageObject, CloverFile } from './types.js';
import { normalizePathToUnix } from './normalizePathToUnix.js';

export function handleCloverFormat(
filePath: string,
fileName: string,
lines: Record<string, number>,
uncoveredLines: number[],
coveredLines: number[],
coverageObj: CloverCoverageObject
): void {
const cloverFile: CloverFile = {
'@name': fileName,
'@path': normalizePathToUnix(filePath),
metrics: {
'@statements': uncoveredLines.length + coveredLines.length,
'@coveredstatements': coveredLines.length,
'@conditionals': 0,
'@coveredconditionals': 0,
'@methods': 0,
'@coveredmethods': 0,
},
line: [],
};

for (const [lineNumber, isCovered] of Object.entries(lines)) {
cloverFile.line.push({
'@num': Number(lineNumber),
'@count': isCovered === 1 ? 1 : 0,
'@type': 'stmt',
});
}

coverageObj.coverage.project.file.push(cloverFile);
const projectMetrics = coverageObj.coverage.project.metrics;

projectMetrics['@statements'] += uncoveredLines.length + coveredLines.length;
projectMetrics['@coveredstatements'] += coveredLines.length;
projectMetrics['@elements'] += uncoveredLines.length + coveredLines.length;
projectMetrics['@coveredelements'] += coveredLines.length;
projectMetrics['@files'] += 1;
projectMetrics['@classes'] += 1;
projectMetrics['@loc'] += uncoveredLines.length + coveredLines.length;
projectMetrics['@ncloc'] += uncoveredLines.length + coveredLines.length;
}
43 changes: 43 additions & 0 deletions src/helpers/handleCoberturaFormat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
'use strict';
/* eslint-disable no-param-reassign */

import { CoberturaCoverageObject, CoberturaClass, CoberturaPackage } from './types.js';
import { normalizePathToUnix } from './normalizePathToUnix.js';

export function handleCoberturaFormat(
filePath: string,
fileName: string,
lines: Record<string, number>,
uncoveredLines: number[],
coveredLines: number[],
coverageObj: CoberturaCoverageObject,
packageObj: CoberturaPackage
): void {
const classObj: CoberturaClass = {
'@name': fileName,
'@filename': normalizePathToUnix(filePath),
'@line-rate': (coveredLines.length / (coveredLines.length + uncoveredLines.length)).toFixed(4),
'@branch-rate': '1',
methods: {},
lines: {
line: [],
},
};

for (const [lineNumber, isCovered] of Object.entries(lines)) {
classObj.lines.line.push({
'@number': Number(lineNumber),
'@hits': isCovered === 1 ? 1 : 0,
'@branch': 'false',
});
}

coverageObj.coverage['@lines-valid'] += uncoveredLines.length + coveredLines.length;
coverageObj.coverage['@lines-covered'] += coveredLines.length;
packageObj.classes.class.push(classObj);

packageObj['@line-rate'] = Number(
(coverageObj.coverage['@lines-covered'] / coverageObj.coverage['@lines-valid']).toFixed(4)
);
coverageObj.coverage['@line-rate'] = packageObj['@line-rate'];
}
27 changes: 27 additions & 0 deletions src/helpers/handleSonarFormat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';
/* eslint-disable no-param-reassign */

import { SonarCoverageObject, SonarClass } from './types.js';
import { normalizePathToUnix } from './normalizePathToUnix.js';

export function handleSonarFormat(
filePath: string,
lines: Record<string, number>,
coverageObj: SonarCoverageObject
): void {
const fileObj: SonarClass = {
'@path': normalizePathToUnix(filePath),
lineToCover: [],
};

for (const lineNumberString in lines) {
if (!Object.hasOwn(lines, lineNumberString)) continue;
const covered = lines[lineNumberString] === 1 ? 'true' : 'false';
fileObj.lineToCover.push({
'@lineNumber': Number(lineNumberString),
'@covered': covered,
});
}

coverageObj.coverage.file.push(fileObj);
}
45 changes: 0 additions & 45 deletions src/helpers/setCoveredLinesClover.ts

This file was deleted.

45 changes: 0 additions & 45 deletions src/helpers/setCoveredLinesCobertura.ts

This file was deleted.

40 changes: 0 additions & 40 deletions src/helpers/setCoveredLinesSonar.ts

This file was deleted.

Loading

0 comments on commit 16db162

Please sign in to comment.