Skip to content

Commit

Permalink
Avoid NaN percentage passed when nothing ran (#363)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidjgoss authored Jan 23, 2025
1 parent 075a33b commit 31723da
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
### Fixed
- Avoid NaN percentage passed when nothing ran ([#363](https://github.com/cucumber/react-components/pull/363))
- Don't render hook steps with no content ([#361](https://github.com/cucumber/react-components/pull/361))

## [22.3.0] - 2024-08-02
Expand Down
1 change: 1 addition & 0 deletions src/components/app/ExecutionSummary.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ describe('ExecutionSummary', () => {
[5, 45, '11%'],
[45, 45, '100%'],
[0, 45, '0%'],
[0, 0, '0%'],
]

for (const [passed, total, percentage] of examples) {
Expand Down
11 changes: 11 additions & 0 deletions src/components/app/ExecutionSummary.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,14 @@ WithCi.args = {
testRunFinished,
meta: metaWithCi,
} as IExecutionSummaryProps

export const NoTestCases = Template.bind({})
NoTestCases.args = {
scenarioCountByStatus: {
...makeEmptyScenarioCountsByStatus(),
},
totalScenarioCount: 0,
testRunStarted,
testRunFinished,
meta: metaMinimal,
}
6 changes: 5 additions & 1 deletion src/components/app/ExecutionSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ export const ExecutionSummary: React.FunctionComponent<IExecutionSummaryProps> =
const percentagePassed: string =
new Intl.NumberFormat(undefined, {
style: 'percent',
}).format(scenarioCountByStatus[TestStepResultStatus.PASSED] / totalScenarioCount) + ' passed'
}).format(
totalScenarioCount > 0
? scenarioCountByStatus[TestStepResultStatus.PASSED] / totalScenarioCount
: 0
) + ' passed'
const startDate = testRunStarted?.timestamp
? new Date(TimeConversion.timestampToMillisecondsSinceEpoch(testRunStarted.timestamp))
: undefined
Expand Down

0 comments on commit 31723da

Please sign in to comment.