Commit 808b8e82 authored by Fatih Acet's avatar Fatih Acet 🙌

Merge branch '37363-junit-xml-summary-incorrectly-shows-100-success-rate' into 'master'

Resolve "JUnit XML summary incorrectly shows 100% success rate"

Closes #37363

See merge request gitlab-org/gitlab!20835
parents 43fce23e 903563ac
Pipeline #100661471 failed with stages
in 161 minutes and 32 seconds
......@@ -28,7 +28,9 @@ export default {
return this.report.name || __('Summary');
},
successPercentage() {
return Math.round((this.report.success_count / this.report.total_count) * 100) || 0;
// Returns a full number when the decimals equal .00.
// Otherwise returns a float to two decimal points
return Number(((this.report.success_count / this.report.total_count) * 100 || 0).toFixed(2));
},
formattedDuration() {
return formatTime(secondsToMilliseconds(this.report.total_time));
......
---
title: Junit success percentage no longer displays 100% if there are failures
merge_request: 20835
author:
type: fixed
......@@ -79,4 +79,25 @@ describe('Test reports summary', () => {
expect(duration().text()).toBe('00:00:00');
});
});
describe('success percentage calculation', () => {
it.each`
name | successCount | totalCount | result
${'displays 0 when there are no tests'} | ${0} | ${0} | ${'0'}
${'displays whole number when possible'} | ${10} | ${50} | ${'20'}
${'rounds to 0.01'} | ${1} | ${16604} | ${'0.01'}
${'correctly rounds to 50'} | ${8302} | ${16604} | ${'50'}
${'rounds down for large close numbers'} | ${16603} | ${16604} | ${'99.99'}
${'correctly displays 100'} | ${16604} | ${16604} | ${'100'}
`('$name', ({ successCount, totalCount, result }) => {
createComponent({
report: {
success_count: successCount,
total_count: totalCount,
},
});
expect(successRate().text()).toBe(`${result}% success rate`);
});
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment