Skip to content

Commit eaba650

Browse files
committed
replace deprecated method usage
1 parent 22400b7 commit eaba650

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

javascript/src/helpers.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ import {
88
} from '@cucumber/messages'
99
import { DateTime } from 'luxon'
1010

11+
export function ensure<T>(value: T | undefined, message: string): T {
12+
if (!value) {
13+
throw new Error(message)
14+
}
15+
return value
16+
}
17+
1118
export function durationToSeconds(duration?: Duration) {
1219
if (!duration) {
1320
return 0

javascript/src/makeReport.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import assert from 'node:assert'
2-
31
import { TestCaseStarted, TestStepResultStatus } from '@cucumber/messages'
42
import {
53
namingStrategy,
@@ -9,7 +7,7 @@ import {
97
Query,
108
} from '@cucumber/query'
119

12-
import { countStatuses, durationToSeconds, formatStep, formatTimestamp } from './helpers.js'
10+
import { countStatuses, durationToSeconds, ensure, formatStep, formatTimestamp } from './helpers.js'
1311

1412
const NAMING_STRATEGY = namingStrategy(
1513
NamingStrategyLength.LONG,
@@ -54,30 +52,36 @@ export function makeReport(query: Query): ReportSuite {
5452
),
5553
errors: 0,
5654
testCases: makeTestCases(query),
57-
timestamp: formatTimestamp(query.findTestRunStarted())
55+
timestamp: formatTimestamp(query.findTestRunStarted()),
5856
}
5957
}
6058

6159
function makeTestCases(query: Query): ReadonlyArray<ReportTestCase> {
6260
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')
6666

6767
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),
7070
time: durationToSeconds(query.findTestCaseDurationBy(testCaseStarted)),
7171
failure: makeFailure(query, testCaseStarted),
7272
output: query
7373
.findTestStepFinishedAndTestStepBy(testCaseStarted)
7474
// filter out hooks
7575
.filter(([, testStep]) => !!testStep.pickleStepId)
7676
.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+
)
8185
return formatStep(gherkinStep, pickleStep, testStepFinished.testStepResult.status)
8286
})
8387
.join('\n'),

0 commit comments

Comments
 (0)