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

Hide details when report exceeds size limit #278

Merged
merged 3 commits into from Jun 2, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/constants/GITHUB_MESSAGE_SIZE_LIMIT.ts
@@ -0,0 +1 @@
export const GITHUB_MESSAGE_SIZE_LIMIT = 65535;
6 changes: 4 additions & 2 deletions src/format/formatCoverage.ts
Expand Up @@ -6,15 +6,17 @@ import { JsonReport } from '../typings/JsonReport';
export const formatCoverage = (
headReport: JsonReport | undefined,
baseReport: JsonReport | undefined,
threshold: number | undefined
threshold: number | undefined,
hideDetails: boolean | undefined
): string => {
if (headReport) {
return getFormattedCoverage(
parseSummary(headReport),
baseReport ? parseSummary(baseReport) : undefined,
parseDetails(headReport),
baseReport ? parseDetails(baseReport) : undefined,
threshold
threshold,
hideDetails
);
}

Expand Down
8 changes: 6 additions & 2 deletions src/format/getFormattedCoverage.ts
@@ -1,17 +1,21 @@
import { formatCoverageDetails } from './details/formatCoverageDetails';
import { formatCoverageSummary } from './summary/formatCoverageSummary';
import { CoverageDetailsMap, CoverageSummary } from '../typings/Coverage';
import { i18n } from '../utils/i18n';

export const getFormattedCoverage = (
headSummary: Array<CoverageSummary>,
baseSummary: Array<CoverageSummary> | undefined,
headDetails: CoverageDetailsMap,
baseDetails: CoverageDetailsMap | undefined,
threshold: number | undefined
threshold: number | undefined,
hideDetails: boolean | undefined
): string =>
[
formatCoverageSummary(headSummary, baseSummary, threshold),
formatCoverageDetails(headDetails, baseDetails, threshold),
!hideDetails
? formatCoverageDetails(headDetails, baseDetails, threshold)
: `> ${i18n('detailsHidden')}`,
]
.filter(Boolean)
.join('\n');
1 change: 1 addition & 0 deletions src/format/strings.json
Expand Up @@ -104,6 +104,7 @@
"readingCoverageFileFailed": "Failed reading coverage file. (Error: {{ error }})",
"failedGettingCoverage": "Getting code coverage data failed."
},
"detailsHidden": ":warning: Details were not displayed: the report size has exceeded the limit." ,
"summaryTitle": "Coverage report {{ dir }}",
"newFilesCoverage": "Show new covered files :hatching_chick:",
"decreasedCoverageFiles": "Show files with reduced coverage :small_red_triangle_down:",
Expand Down
38 changes: 33 additions & 5 deletions src/stages/createReport.ts
@@ -1,6 +1,7 @@
import { context } from '@actions/github';

import { getReportTag } from '../constants/getReportTag';
import { GITHUB_MESSAGE_SIZE_LIMIT } from '../constants/GITHUB_MESSAGE_SIZE_LIMIT';
import { formatCoverage } from '../format/formatCoverage';
import { formatErrors } from '../format/formatErrors';
import { formatRunReport } from '../format/formatRunReport';
Expand Down Expand Up @@ -33,19 +34,42 @@ export const createReport = (
const formattedErrors = formatErrors(errors);

const formattedThresholdResults = formatThresholdResults(thresholdResults);
const coverage = formatCoverage(headReport, baseReport, undefined);
const coverage = formatCoverage(headReport, baseReport, undefined, false);
const runReport: TestRunReport = {
title: i18n(headReport.success ? 'testsSuccess' : 'testsFail'),
summary: getTestRunSummary(headReport),
failures: getFailureDetails(headReport),
};
const formattedReport = formatRunReport(runReport);
return {
text: insertArgs(template, {

let templateText = insertArgs(template, {
body: [
formattedErrors,
formattedThresholdResults,
coverage,
formattedReport,
].join('\n'),
dir: workingDirectory || '',
tag: getReportTag(options),
title: insertArgs(customTitle || i18n('summaryTitle'), {
dir: workingDirectory ? `for \`${workingDirectory}\`` : '',
}),
sha: getSha(),
});

if (templateText.length > GITHUB_MESSAGE_SIZE_LIMIT) {
const reducedCoverage = formatCoverage(
headReport,
baseReport,
undefined,
true
);

templateText = insertArgs(template, {
body: [
formattedErrors,
formattedThresholdResults,
coverage,
reducedCoverage,
formattedReport,
].join('\n'),
dir: workingDirectory || '',
Expand All @@ -54,7 +78,11 @@ export const createReport = (
dir: workingDirectory ? `for \`${workingDirectory}\`` : '',
}),
sha: getSha(),
}),
});
}

return {
text: templateText,
runReport,
};
};
7 changes: 7 additions & 0 deletions tests/constants/GITHUB_MESSAGE_SIZE_LIMIT.test.ts
@@ -0,0 +1,7 @@
import { GITHUB_MESSAGE_SIZE_LIMIT } from '../../src/constants/GITHUB_MESSAGE_SIZE_LIMIT';

describe('GITHUB_MESSAGE_SIZE_LIMIT', () => {
it('should be 65535', () => {
expect(GITHUB_MESSAGE_SIZE_LIMIT).toBe(65535);
});
});
10 changes: 10 additions & 0 deletions tests/format/__snapshots__/formatCoverage.test.ts.snap
@@ -1,5 +1,15 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`formatCoverage should display warning if hiding details 1`] = `
"| <div title=\\"Status of coverage:&#10; 🟢 - ok&#10; 🟡 - slightly more than threshold&#10; 🔴 - under the threshold\\">St.<sup>:grey_question:</sup></div> | Category | Percentage | Covered / Total |
| :----------------------------------------------------------------------------------------------------------------------------------------------------: | :--------- | :--------- | :-------------: |
| 🟢 | Statements | 81.82% | 27/33 |
| 🟢 | Branches | 100% | 8/8 |
| 🟢 | Functions | 63.64% | 7/11 |
| 🟢 | Lines | 80.65% | 25/31 |
> :warning: Details were not displayed: the report size has exceeded the limit."
`;

exports[`formatCoverage should format standard coverage 1`] = `
"| <div title=\\"Status of coverage:&#10; 🟢 - ok&#10; 🟡 - slightly more than threshold&#10; 🔴 - under the threshold\\">St.<sup>:grey_question:</sup></div> | Category | Percentage | Covered / Total |
| :----------------------------------------------------------------------------------------------------------------------------------------------------: | :--------- | :--------- | :-------------: |
Expand Down

This file was deleted.

18 changes: 14 additions & 4 deletions tests/format/formatCoverage.test.ts
Expand Up @@ -3,14 +3,24 @@ import jsonReport from '../mock-data/jsonReport.json';

describe('formatCoverage', () => {
it('should format standard coverage', () => {
expect(formatCoverage(jsonReport, jsonReport, 0.3)).toMatchSnapshot();
expect(formatCoverage(jsonReport, undefined, 0.3)).toMatchSnapshot();
expect(
formatCoverage(jsonReport, undefined, undefined)
formatCoverage(jsonReport, jsonReport, 0.3, false)
).toMatchSnapshot();
expect(
formatCoverage(jsonReport, undefined, 0.3, false)
).toMatchSnapshot();
expect(
formatCoverage(jsonReport, undefined, undefined, false)
).toMatchSnapshot();
});

it('should display warning if hiding details', () => {
expect(
formatCoverage(jsonReport, jsonReport, 0.3, true)
).toMatchSnapshot();
});

it('should return empty string if no reports specified', () => {
expect(formatCoverage(undefined, undefined, 0.3)).toBe('');
expect(formatCoverage(undefined, undefined, 0.3, false)).toBe('');
});
});
3 changes: 2 additions & 1 deletion tests/format/getFormattedCoverage.test.ts
Expand Up @@ -11,7 +11,8 @@ describe('getFormattedCoverage', () => {
undefined,
parseDetails(jsonReport),
undefined,
undefined
undefined,
false
)
).toMatchSnapshot();
});
Expand Down