|
1 |
| -import assert from 'node:assert' |
2 |
| - |
3 | 1 | import { TestCaseStarted, TestStepResultStatus } from '@cucumber/messages'
|
4 | 2 | import {
|
5 | 3 | namingStrategy,
|
|
9 | 7 | Query,
|
10 | 8 | } from '@cucumber/query'
|
11 | 9 |
|
12 |
| -import { countStatuses, durationToSeconds, formatStep, formatTimestamp } from './helpers.js' |
| 10 | +import { countStatuses, durationToSeconds, ensure, formatStep, formatTimestamp } from './helpers.js' |
13 | 11 |
|
14 | 12 | const NAMING_STRATEGY = namingStrategy(
|
15 | 13 | NamingStrategyLength.LONG,
|
@@ -54,30 +52,36 @@ export function makeReport(query: Query): ReportSuite {
|
54 | 52 | ),
|
55 | 53 | errors: 0,
|
56 | 54 | testCases: makeTestCases(query),
|
57 |
| - timestamp: formatTimestamp(query.findTestRunStarted()) |
| 55 | + timestamp: formatTimestamp(query.findTestRunStarted()), |
58 | 56 | }
|
59 | 57 | }
|
60 | 58 |
|
61 | 59 | function makeTestCases(query: Query): ReadonlyArray<ReportTestCase> {
|
62 | 60 | return query.findAllTestCaseStarted().map((testCaseStarted) => {
|
63 |
| - const pickle = query.findPickleBy(testCaseStarted) |
64 |
| - assert.ok(pickle, 'Expected to find Pickle by TestCaseStarted') |
65 |
| - const feature = query.findFeatureBy(testCaseStarted) |
| 61 | + const pickle = ensure( |
| 62 | + query.findPickleBy(testCaseStarted), |
| 63 | + 'Expected to find Pickle by TestCaseStarted' |
| 64 | + ) |
| 65 | + const lineage = ensure(query.findLineageBy(pickle), 'Expected to find Lineage by Pickle') |
66 | 66 |
|
67 | 67 | return {
|
68 |
| - classname: feature?.name ?? pickle.uri, |
69 |
| - name: query.findNameOf(pickle, NAMING_STRATEGY), |
| 68 | + classname: lineage.feature?.name ?? pickle.uri, |
| 69 | + name: NAMING_STRATEGY.reduce(lineage, pickle), |
70 | 70 | time: durationToSeconds(query.findTestCaseDurationBy(testCaseStarted)),
|
71 | 71 | failure: makeFailure(query, testCaseStarted),
|
72 | 72 | output: query
|
73 | 73 | .findTestStepFinishedAndTestStepBy(testCaseStarted)
|
74 | 74 | // filter out hooks
|
75 | 75 | .filter(([, testStep]) => !!testStep.pickleStepId)
|
76 | 76 | .map(([testStepFinished, testStep]) => {
|
77 |
| - const pickleStep = query.findPickleStepBy(testStep) |
78 |
| - assert.ok(pickleStep, 'Expected to find PickleStep by TestStep') |
79 |
| - const gherkinStep = query.findStepBy(pickleStep) |
80 |
| - assert.ok(gherkinStep, 'Expected to find Step by PickleStep') |
| 77 | + const pickleStep = ensure( |
| 78 | + query.findPickleStepBy(testStep), |
| 79 | + 'Expected to find PickleStep by TestStep' |
| 80 | + ) |
| 81 | + const gherkinStep = ensure( |
| 82 | + query.findStepBy(pickleStep), |
| 83 | + 'Expected to find Step by PickleStep' |
| 84 | + ) |
81 | 85 | return formatStep(gherkinStep, pickleStep, testStepFinished.testStepResult.status)
|
82 | 86 | })
|
83 | 87 | .join('\n'),
|
|
0 commit comments