Skip to content

Commit

Permalink
add multi files to coverage report (#79)
Browse files Browse the repository at this point in the history
* add multi files to coverage report

* add multi files to coverage report2

* revert live test

* add multi files to coverage report to cli

* 1.1.32

* set final output to summaryReport
  • Loading branch information
MishaKav authored Aug 10, 2022
1 parent 7c2f420 commit 0b96302
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 122 deletions.
102 changes: 53 additions & 49 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17661,61 +17661,65 @@ const main = async () => {
options.changedFiles = changedFiles;
}

if (multipleFiles && multipleFiles.length) {
finalHtml += getMultipleReport(options);
core.setOutput('summaryReport', JSON.stringify(finalHtml));
} else {
let report = getCoverageReport(options);
const { coverage, color, html, warnings } = report;
const summaryReport = getSummaryReport(options);

if (html) {
const newOptions = { ...options, commit: defaultBranch };
const output = getCoverageReport(newOptions);
core.setOutput('coverageHtml', output.html);
}

// set to output junitxml values
if (summaryReport) {
const parsedXml = getParsedXml(options);
const { errors, failures, skipped, tests, time } = parsedXml;
const valuesToExport = { errors, failures, skipped, tests, time };
let report = getCoverageReport(options);
const { coverage, color, html, warnings } = report;
const summaryReport = getSummaryReport(options);

if (html) {
const newOptions = { ...options, commit: defaultBranch };
const output = getCoverageReport(newOptions);
core.setOutput('coverageHtml', output.html);
}

Object.entries(valuesToExport).forEach(([key, value]) => {
core.info(`${key}: ${value}`);
core.setOutput(key, value);
});
// set to output junitxml values
if (summaryReport) {
const parsedXml = getParsedXml(options);
const { errors, failures, skipped, tests, time } = parsedXml;
const valuesToExport = { errors, failures, skipped, tests, time };

const notSuccessTestInfo = getNotSuccessTest(options);
core.setOutput('notSuccessTestInfo', JSON.stringify(notSuccessTestInfo));
core.setOutput('summaryReport', JSON.stringify(summaryReport));
}
Object.entries(valuesToExport).forEach(([key, value]) => {
core.info(`${key}: ${value}`);
core.setOutput(key, value);
});

if (html.length + summaryReport.length > MAX_COMMENT_LENGTH) {
// generate new html without report
core.warning(
`Your comment is too long (maximum is ${MAX_COMMENT_LENGTH} characters), coverage report will not be added.`
);
core.warning(
`Try add: "--cov-report=term-missing:skip-covered", or add "hide-report: true", or add "report-only-changed-files: true", or switch to "multiple-files" mode`
);
report = getSummaryReport({ ...options, hideReport: true });
}
const notSuccessTestInfo = getNotSuccessTest(options);
core.setOutput('notSuccessTestInfo', JSON.stringify(notSuccessTestInfo));
core.setOutput('summaryReport', JSON.stringify(summaryReport));
}

finalHtml += html;
finalHtml += finalHtml.length ? `\n\n${summaryReport}` : summaryReport;
let multipleFilesHtml = '';
if (multipleFiles && multipleFiles.length) {
multipleFilesHtml = `\n\n${getMultipleReport(options)}`;
}

if (coverage) {
core.startGroup(options.covFile);
core.info(`coverage: ${coverage}`);
core.info(`color: ${color}`);
core.info(`warnings: ${warnings}`);
if (html.length + summaryReport.length > MAX_COMMENT_LENGTH) {
// generate new html without report
core.warning(
`Your comment is too long (maximum is ${MAX_COMMENT_LENGTH} characters), coverage report will not be added.`
);
core.warning(
`Try add: "--cov-report=term-missing:skip-covered", or add "hide-report: true", or add "report-only-changed-files: true", or switch to "multiple-files" mode`
);
report = getSummaryReport({ ...options, hideReport: true });
}

core.setOutput('coverage', coverage);
core.setOutput('color', color);
core.setOutput('warnings', warnings);
core.endGroup();
}
finalHtml += html;
finalHtml += finalHtml.length ? `\n\n${summaryReport}` : summaryReport;
finalHtml += multipleFilesHtml
? `\n\n${multipleFilesHtml}`
: multipleFilesHtml;
core.setOutput('summaryReport', JSON.stringify(finalHtml));

if (coverage) {
core.startGroup(options.covFile);
core.info(`coverage: ${coverage}`);
core.info(`color: ${color}`);
core.info(`warnings: ${warnings}`);

core.setOutput('coverage', coverage);
core.setOutput('color', color);
core.setOutput('warnings', warnings);
core.endGroup();
}

if (!finalHtml || options.hideComment) {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pytest-coverage-comment",
"version": "1.1.31",
"version": "1.1.32",
"description": "Comments a pull request with the pytest code coverage badge, full report and tests summary",
"author": "Misha Kav",
"license": "MIT",
Expand Down
47 changes: 26 additions & 21 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,30 +75,35 @@ const main = async () => {
},
};

const { html } = getCoverageReport(options);
const summaryReport = getSummaryReport(options);

// set to output junitxml values
if (summaryReport) {
const parsedXml = getParsedXml(options);
const { errors, failures, skipped, tests, time } = parsedXml;
const valuesToExport = { errors, failures, skipped, tests, time };
const notSuccessTestInfo = getNotSuccessTest(options);

console.log('notSuccessTestInfo', JSON.stringify(notSuccessTestInfo));

Object.entries(valuesToExport).forEach(([key, value]) => {
console.log(key, value);
});
}

finalHtml += html;
finalHtml += finalHtml.length ? `\n\n${summaryReport}` : summaryReport;

let multipleFilesHtml = '';
if (options.multipleFiles && options.multipleFiles.length) {
finalHtml += getMultipleReport(options);
} else {
const { html } = getCoverageReport(options);
const summaryReport = getSummaryReport(options);

// set to output junitxml values
if (summaryReport) {
const parsedXml = getParsedXml(options);
const { errors, failures, skipped, tests, time } = parsedXml;
const valuesToExport = { errors, failures, skipped, tests, time };
const notSuccessTestInfo = getNotSuccessTest(options);

console.log('notSuccessTestInfo', JSON.stringify(notSuccessTestInfo));

Object.entries(valuesToExport).forEach(([key, value]) => {
console.log(key, value);
});
}

finalHtml += html;
finalHtml += finalHtml.length ? `\n\n${summaryReport}` : summaryReport;
multipleFilesHtml = `\n\n${getMultipleReport(options)}`;
}

finalHtml += multipleFilesHtml
? `\n\n${multipleFilesHtml}`
: multipleFilesHtml;

if (!finalHtml || options.hideComment) {
console.log('Nothing to report');
return;
Expand Down
102 changes: 53 additions & 49 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,61 +81,65 @@ const main = async () => {
options.changedFiles = changedFiles;
}

if (multipleFiles && multipleFiles.length) {
finalHtml += getMultipleReport(options);
core.setOutput('summaryReport', JSON.stringify(finalHtml));
} else {
let report = getCoverageReport(options);
const { coverage, color, html, warnings } = report;
const summaryReport = getSummaryReport(options);

if (html) {
const newOptions = { ...options, commit: defaultBranch };
const output = getCoverageReport(newOptions);
core.setOutput('coverageHtml', output.html);
}

// set to output junitxml values
if (summaryReport) {
const parsedXml = getParsedXml(options);
const { errors, failures, skipped, tests, time } = parsedXml;
const valuesToExport = { errors, failures, skipped, tests, time };
let report = getCoverageReport(options);
const { coverage, color, html, warnings } = report;
const summaryReport = getSummaryReport(options);

if (html) {
const newOptions = { ...options, commit: defaultBranch };
const output = getCoverageReport(newOptions);
core.setOutput('coverageHtml', output.html);
}

Object.entries(valuesToExport).forEach(([key, value]) => {
core.info(`${key}: ${value}`);
core.setOutput(key, value);
});
// set to output junitxml values
if (summaryReport) {
const parsedXml = getParsedXml(options);
const { errors, failures, skipped, tests, time } = parsedXml;
const valuesToExport = { errors, failures, skipped, tests, time };

const notSuccessTestInfo = getNotSuccessTest(options);
core.setOutput('notSuccessTestInfo', JSON.stringify(notSuccessTestInfo));
core.setOutput('summaryReport', JSON.stringify(summaryReport));
}
Object.entries(valuesToExport).forEach(([key, value]) => {
core.info(`${key}: ${value}`);
core.setOutput(key, value);
});

if (html.length + summaryReport.length > MAX_COMMENT_LENGTH) {
// generate new html without report
core.warning(
`Your comment is too long (maximum is ${MAX_COMMENT_LENGTH} characters), coverage report will not be added.`
);
core.warning(
`Try add: "--cov-report=term-missing:skip-covered", or add "hide-report: true", or add "report-only-changed-files: true", or switch to "multiple-files" mode`
);
report = getSummaryReport({ ...options, hideReport: true });
}
const notSuccessTestInfo = getNotSuccessTest(options);
core.setOutput('notSuccessTestInfo', JSON.stringify(notSuccessTestInfo));
core.setOutput('summaryReport', JSON.stringify(summaryReport));
}

finalHtml += html;
finalHtml += finalHtml.length ? `\n\n${summaryReport}` : summaryReport;
let multipleFilesHtml = '';
if (multipleFiles && multipleFiles.length) {
multipleFilesHtml = `\n\n${getMultipleReport(options)}`;
}

if (coverage) {
core.startGroup(options.covFile);
core.info(`coverage: ${coverage}`);
core.info(`color: ${color}`);
core.info(`warnings: ${warnings}`);
if (html.length + summaryReport.length > MAX_COMMENT_LENGTH) {
// generate new html without report
core.warning(
`Your comment is too long (maximum is ${MAX_COMMENT_LENGTH} characters), coverage report will not be added.`
);
core.warning(
`Try add: "--cov-report=term-missing:skip-covered", or add "hide-report: true", or add "report-only-changed-files: true", or switch to "multiple-files" mode`
);
report = getSummaryReport({ ...options, hideReport: true });
}

core.setOutput('coverage', coverage);
core.setOutput('color', color);
core.setOutput('warnings', warnings);
core.endGroup();
}
finalHtml += html;
finalHtml += finalHtml.length ? `\n\n${summaryReport}` : summaryReport;
finalHtml += multipleFilesHtml
? `\n\n${multipleFilesHtml}`
: multipleFilesHtml;
core.setOutput('summaryReport', JSON.stringify(finalHtml));

if (coverage) {
core.startGroup(options.covFile);
core.info(`coverage: ${coverage}`);
core.info(`color: ${color}`);
core.info(`warnings: ${warnings}`);

core.setOutput('coverage', coverage);
core.setOutput('color', color);
core.setOutput('warnings', warnings);
core.endGroup();
}

if (!finalHtml || options.hideComment) {
Expand Down

0 comments on commit 0b96302

Please sign in to comment.