|
| 1 | +import {Box, Text} from 'ink'; |
| 2 | +import {ReporterSnapshot} from '../ReporterState'; |
| 3 | +import {Outcome} from '../Outcome'; |
| 4 | +import {Result, ScenarioResult} from '../Results'; |
| 5 | +import {StatusBadge} from './StatusBadge'; |
| 6 | + |
| 7 | +interface Props { |
| 8 | + snapshot: ReporterSnapshot; |
| 9 | +} |
| 10 | + |
| 11 | +const failed = (outcome: Outcome): boolean => outcome === Outcome.failed || outcome === Outcome.error || outcome === Outcome.timedout; |
| 12 | + |
| 13 | +interface FailureRow { |
| 14 | + scenario: ScenarioResult; |
| 15 | + step?: Result; |
| 16 | +} |
| 17 | + |
| 18 | +const failureRows = (scenarios: ScenarioResult[]): FailureRow[] => scenarios.flatMap<FailureRow>((scenario): FailureRow[] => { |
| 19 | + const steps = scenario.outcomes().filter((step) => failed(step.outcome)); |
| 20 | + return steps.length === 0 ? [{scenario}] : steps.map((step) => ({scenario, step})); |
| 21 | +}); |
| 22 | + |
| 23 | +export function ActiveFailures({snapshot}: Props) { |
| 24 | + const failures = snapshot.activeRuns.map((run) => ({ |
| 25 | + run, |
| 26 | + scenarios: run.scenarios.filter((scenario) => failed(scenario.outcome)) |
| 27 | + })).filter(({scenarios}) => scenarios.length > 0); |
| 28 | + |
| 29 | + if (failures.length === 0) { |
| 30 | + return null; |
| 31 | + } |
| 32 | + |
| 33 | + return ( |
| 34 | + <Box flexDirection="column" marginTop={1}> |
| 35 | + {failures.map(({run, scenarios}) => ( |
| 36 | + <Box key={`${run.id}-failures`} flexDirection="column"> |
| 37 | + <Text> |
| 38 | + <StatusBadge outcome={Outcome.failed}/> |
| 39 | + <Text> {run.suiteTitle}</Text> |
| 40 | + <Text color="gray"> ({scenarios.length}/{run.plannedScenarios ?? run.scenarios.length})</Text> |
| 41 | + </Text> |
| 42 | + {failureRows(scenarios).map(({scenario, step}) => ( |
| 43 | + <Box key={`${run.id}-failure-${scenario.name}-${step?.name ?? 'scenario'}`} marginLeft={5}> |
| 44 | + <Text> |
| 45 | + <Text color="gray">TEST</Text> |
| 46 | + <Text> {scenario.name}</Text> |
| 47 | + {step ? <Text color="gray"> · {step.name}</Text> : null} |
| 48 | + </Text> |
| 49 | + </Box> |
| 50 | + ))} |
| 51 | + </Box> |
| 52 | + ))} |
| 53 | + </Box> |
| 54 | + ); |
| 55 | +} |
0 commit comments