Skip to content

Commit

Permalink
test coverage report in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
Curt Bonade authored and Curt Bonade committed Jan 17, 2025
1 parent 5ae3b9e commit 3dad6a9
Show file tree
Hide file tree
Showing 14 changed files with 161,768 additions and 76 deletions.
2,956 changes: 2,956 additions & 0 deletions coverage-report.json

Large diffs are not rendered by default.

147,506 changes: 147,506 additions & 0 deletions merged-coverage-report.json

Large diffs are not rendered by default.

864 changes: 864 additions & 0 deletions results/coverage-summary-0.json

Large diffs are not rendered by default.

732 changes: 732 additions & 0 deletions results/coverage-summary-1.json

Large diffs are not rendered by default.

1,207 changes: 1,207 additions & 0 deletions results/coverage-summary-2.json

Large diffs are not rendered by default.

985 changes: 985 additions & 0 deletions results/coverage-summary-3.json

Large diffs are not rendered by default.

787 changes: 787 additions & 0 deletions results/coverage-summary-4.json

Large diffs are not rendered by default.

1,054 changes: 1,054 additions & 0 deletions results/coverage-summary-5.json

Large diffs are not rendered by default.

1,049 changes: 1,049 additions & 0 deletions results/coverage-summary-6.json

Large diffs are not rendered by default.

746 changes: 746 additions & 0 deletions results/coverage-summary-7.json

Large diffs are not rendered by default.

3,598 changes: 3,598 additions & 0 deletions results/coverage-summary-8.json

Large diffs are not rendered by default.

244 changes: 244 additions & 0 deletions results/coverage-summary-9.json

Large diffs are not rendered by default.

34 changes: 18 additions & 16 deletions script/app-coverage-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,19 @@ const printCoverage = coverageResults => {
});

// Add each app coverage result to the table
Object.values(coverageResults).forEach(cov => {
const appLocation =
cov.path.substr(0, cov.path.lastIndexOf('/')) || 'All Files';
coverageTable.push({
[appLocation]: [
`${cov.lines.pct}%`,
`${cov.functions.pct}%`,
`${cov.statements.pct}%`,
`${cov.branches.pct}%`,
],
});
});
console.log(Object.values(coverageResults));
// Object.values(coverageResults).forEach(cov => {
// const appLocation =
// cov.path.substr(0, cov.path.lastIndexOf('/')) || 'All Files';
// coverageTable.push({
// [appLocation]: [
// `${cov.lines.pct}%`,
// `${cov.functions.pct}%`,
// `${cov.statements.pct}%`,
// `${cov.branches.pct}%`,
// ],
// });
// });

console.log(coverageTable.toString());
};
Expand Down Expand Up @@ -97,10 +98,11 @@ const logCoverage = coverageResults => {
const data = JSON.stringify(coverageResults, null, 4);
console.log(data);
// write coverageResults string to file
const outputFile = path.join(
__dirname,
'../qa-standards-dashboard-data/coverage/test-coverage-report.json',
);
// const outputFile = path.join(
// __dirname,
// '../qa-standards-dashboard-data/coverage/test-coverage-report.json',
// );
const outputFile = 'coverage-report.json';
fs.writeFile(outputFile, data, err => {
if (err) {
throw err;
Expand Down
82 changes: 22 additions & 60 deletions script/github-actions/merge-unit-test-coverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,69 +3,31 @@

const fs = require('fs');

const coverageResultsFiles = process.argv.slice(2);

const mergeResults = files => {
const mergedResults = {
total: {
lines: { total: 0, covered: 0, skipped: 0 },
statements: { total: 0, covered: 0, skipped: 0 },
functions: { total: 0, covered: 0, skipped: 0 },
branches: { total: 0, covered: 0, skipped: 0 },
},
};

files.forEach(file => {
const data = JSON.parse(fs.readFileSync(file, 'utf8'));

Object.entries(data).forEach(([filePath, coverageData]) => {
const match = filePath.match(/applications\/(?:[^/]+\/[^/]+|[^/]+)\//);

if (!match) {
return;
}

const directoryKey = match[0];

if (!mergedResults[directoryKey]) {
mergedResults[directoryKey] = {
lines: { total: 0, covered: 0, skipped: 0 },
statements: { total: 0, covered: 0, skipped: 0 },
functions: { total: 0, covered: 0, skipped: 0 },
branches: { total: 0, covered: 0, skipped: 0 },
};
}

const directoryCoverage = mergedResults[directoryKey];
['lines', 'statements', 'functions', 'branches'].forEach(key => {
directoryCoverage[key].total += coverageData[key].total;
directoryCoverage[key].covered += coverageData[key].covered;
directoryCoverage[key].skipped += coverageData[key].skipped;

mergedResults.total[key].total += coverageData[key].total;
mergedResults.total[key].covered += coverageData[key].covered;
mergedResults.total[key].skipped += coverageData[key].skipped;
function mergeJsonFiles(fileNames, outputFile) {
const mergedData = {};

fileNames.forEach(file => {
try {
const fileData = fs.readFileSync(file, 'utf8');
const parsedData = JSON.parse(fileData);

Object.entries(parsedData).forEach(([key, value]) => {
if (mergedData[key]) {
console.warn(`Duplicate key detected: "${key}". Overwriting data.`);
}
mergedData[key] = value;
});
});
} catch (err) {
console.error(`Error processing file: ${file} - ${err.message}`);
}
});

Object.values(mergedResults).forEach(coverageData => {
['lines', 'statements', 'functions', 'branches'].forEach(key => {
coverageData[key].pct = (
(coverageData[key].covered / coverageData[key].total) *
100
).toFixed(2);
});
});
fs.writeFileSync(outputFile, JSON.stringify(mergedData, null, 2));
console.log(`Merged JSON written to: ${outputFile}`);
}

return mergedResults;
};
const coverageResultsFiles = process.argv.slice(2);

const results = mergeResults(coverageResultsFiles);
fs.writeFileSync(
'merged-coverage-report.json',
JSON.stringify(results, null, 2),
'utf8',
);
const outputFileName = 'merged-coverage-report.json';

console.log('Merged results saved to mergedResults.json');
mergeJsonFiles(coverageResultsFiles, outputFileName);

0 comments on commit 3dad6a9

Please sign in to comment.