Skip to content

Commit

Permalink
feat: remove summary data when empty
Browse files Browse the repository at this point in the history
  • Loading branch information
deblockt committed Oct 24, 2020
1 parent b082762 commit 1522442
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This action should be used to publish action annotations from cucumber json repo
## Exemple

``` yml
- uses: deblockt/cucumber-report-annotations-action@v1.6
- uses: deblockt/cucumber-report-annotations-action@v1.7
with:
access-token: ${{ secrets.GITHUB_TOKEN }}
path: "**/cucumber-report.json"
Expand All @@ -20,5 +20,7 @@ This action should be used to publish action annotations from cucumber json repo
- **path** (optional, default: **/cucumber-report.json): the glob path to get cucumber report on json format
- **check-status-on-error** (optional, default: failure): the check status to use on cucumber error. Can be 'neutral' or 'failure'
- **check-status-on-undefined** (optional, default: success): the check status to use on cucumber undefined steps. Can be 'success', 'neutral' or 'failure'
- **check-status-on-pending** (optional, default: success): the check status to use on cucumber pending steps. Can be 'success', 'neutral' or 'failure'
- **annotation-status-on-error** (optional, default: failure): the annotation status on error. Can be 'notice', 'warning', 'failure'
- **annotation-status-on-undefined** (optional): the annotation status on undefined steps. Can be 'notice', 'warning', 'failure'. if this property is not set, no annotation will be generated for undefined steps
- **annotation-status-on-undefined** (optional): the annotation status on undefined steps. Can be 'notice', 'warning', 'failure'. if this property is not set, no annotation will be generated for undefined steps
- **annotation-status-on-pending** (optional): the annotation status on pending steps. Can be 'notice', 'warning', 'failure'. if this property is not set, no annotation will be generated for pending steps
31 changes: 27 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,24 @@ async function buildPendingAnnotation(cucumberError, statusOnPending) {
const reportResultString = await fs.promises.readFile(cucumberReportFile);
const reportResult = JSON.parse(reportResultString);
const globalInformation = reportReader.globalInformation(reportResult);
const summary = `
${globalInformation.scenarioNumber} Scenarios (${globalInformation.failedScenarioNumber} failed, ${globalInformation.undefinedScenarioNumber} undefined, ${globalInformation.pendingScenarioNumber} pending, ${globalInformation.succeedScenarioNumber} passed)
${globalInformation.stepsNumber} Steps (${globalInformation.failedStepsNumber} failed, ${globalInformation.undefinedStepsNumber} undefined, ${globalInformation.skippedStepsNumber} skipped, ${globalInformation.pendingStepNumber} pending, ${globalInformation.succeedStepsNumber} passed)
`;
const summaryScenario = {
'failed': globalInformation.failedScenarioNumber,
'undefined': globalInformation.undefinedScenarioNumber,
'pending': globalInformation.pendingScenarioNumber,
'passed': globalInformation.succeedScenarioNumber
};
const summarySteps = {
'failed': globalInformation.failedStepsNumber,
'undefined': globalInformation.undefinedStepsNumber,
'skipped': globalInformation.skippedStepsNumber,
'pending': globalInformation.pendingStepNumber,
'passed': globalInformation.succeedStepsNumber
};
const summary =
buildSummary(globalInformation.scenarioNumber, 'Scenarios', summaryScenario)
+ '\n'
+ buildSummary(globalInformation.stepsNumber, 'Steps', summarySteps);

const errors = reportReader.failedSteps(reportResult);
var errorAnnotations = await Promise.all(errors.map(e => buildErrorAnnotations(e, annotationStatusOnError)));
if (annotationStatusOnUndefined) {
Expand Down Expand Up @@ -140,3 +154,12 @@ async function buildPendingAnnotation(cucumberError, statusOnPending) {
await octokit.checks.create(createCheckRequest);
}
})();

function buildSummary(itemNumber, itemType, itemCounts) {
const header = itemNumber + ' ' + itemType;
const counts = Object.keys(itemCounts)
.filter(key => itemCounts[key] > 0)
.map(key => itemCounts[key] + ' ' + key)
.join(', ');
return ` ${header} (${counts})`;
}

0 comments on commit 1522442

Please sign in to comment.