Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: remove covered line adjustment in deploy coverage reports #52

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading