Skip to content

Commit c5f69c2

Browse files
committed
emit failure element
1 parent 4c33d8b commit c5f69c2

File tree

2 files changed

+39
-11
lines changed

2 files changed

+39
-11
lines changed

javascript/src/ExtendedQuery.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,7 @@ export class ExtendedQuery {
133133

134134
findPickleBy(testCaseStarted: TestCaseStarted) {
135135
const testCase = this.findTestCaseBy(testCaseStarted)
136-
if (!testCase) {
137-
return undefined
138-
}
136+
assert.ok(testCase, 'Expected to find TestCase from TestCaseStarted')
139137
return this.pickleById.get(testCase.pickleId)
140138
}
141139

@@ -167,6 +165,14 @@ export class ExtendedQuery {
167165
)
168166
}
169167

168+
findMostSevereTestStepResultBy(testCaseStarted: TestCaseStarted) {
169+
return getWorstTestStepResult(
170+
this.findTestStepFinishedAndTestStepBy(testCaseStarted).map(
171+
([testStepFinished]) => testStepFinished.testStepResult
172+
)
173+
)
174+
}
175+
170176
findTestStepBy(testStepFinished: TestStepFinished) {
171177
return this.testStepById.get(testStepFinished.testStepId)
172178
}

javascript/src/index.ts

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as assert from 'node:assert'
22

33
import { Query as GherkinQuery } from '@cucumber/gherkin-utils'
4-
import { Envelope, TestStepResultStatus } from '@cucumber/messages'
4+
import { Envelope, TestCaseStarted, TestStepResultStatus } from '@cucumber/messages'
55
import xmlbuilder from 'xmlbuilder'
66

77
import { ExtendedQuery } from './ExtendedQuery.js'
@@ -35,12 +35,15 @@ export default {
3535
builder.att('errors', testSuite.errors)
3636

3737
for (const testCase of testSuite.testCases) {
38-
const element = builder.ele('testcase', {
38+
const testcaseElement = builder.ele('testcase', {
3939
classname: testCase.classname,
4040
name: testCase.name,
4141
time: testCase.time,
4242
})
43-
element.ele('system-out', {}).cdata(testCase.output)
43+
if (testCase.failure) {
44+
testcaseElement.ele(testCase.failure.type)
45+
}
46+
testcaseElement.ele('system-out', {}).cdata(testCase.output)
4447
}
4548

4649
write(builder.end({ pretty: true }))
@@ -49,23 +52,28 @@ export default {
4952
},
5053
}
5154

52-
interface Report {
55+
interface ReportSuite {
5356
time: number
5457
tests: number
5558
skipped: number
5659
failures: number
5760
errors: number
58-
testCases: ReadonlyArray<TestCase>
61+
testCases: ReadonlyArray<ReportTestCase>
5962
}
6063

61-
interface TestCase {
64+
interface ReportTestCase {
6265
classname: string
6366
name: string
6467
time: number
68+
failure?: ReportFailure
6569
output: string
6670
}
6771

68-
function makeReport(query: ExtendedQuery): Report {
72+
interface ReportFailure {
73+
type: 'failure' | 'skipped'
74+
}
75+
76+
function makeReport(query: ExtendedQuery): ReportSuite {
6977
const statuses = query.countMostSevereTestStepResultStatus()
7078
return {
7179
time: durationToSeconds(query.findTestRunDuration()),
@@ -80,14 +88,15 @@ function makeReport(query: ExtendedQuery): Report {
8088
}
8189
}
8290

83-
function makeTestCases(query: ExtendedQuery): ReadonlyArray<TestCase> {
91+
function makeTestCases(query: ExtendedQuery): ReadonlyArray<ReportTestCase> {
8492
return query.findAllTestCaseStarted().map((testCaseStarted) => {
8593
const pickle = query.findPickleBy(testCaseStarted)
8694
assert.ok(pickle, 'Expected to find Pickle by TestCaseStarted')
8795
return {
8896
classname: pickle.uri,
8997
name: pickle.name,
9098
time: durationToSeconds(query.findTestCaseDurationBy(testCaseStarted)),
99+
failure: makeFailure(query, testCaseStarted),
91100
output: query
92101
.findTestStepFinishedAndTestStepBy(testCaseStarted)
93102
// filter out hooks
@@ -103,3 +112,16 @@ function makeTestCases(query: ExtendedQuery): ReadonlyArray<TestCase> {
103112
}
104113
})
105114
}
115+
116+
function makeFailure(
117+
query: ExtendedQuery,
118+
testCaseStarted: TestCaseStarted
119+
): ReportFailure | undefined {
120+
const result = query.findMostSevereTestStepResultBy(testCaseStarted)
121+
if (result.status === TestStepResultStatus.PASSED) {
122+
return undefined
123+
}
124+
return {
125+
type: result.status === TestStepResultStatus.SKIPPED ? 'skipped' : 'failure',
126+
}
127+
}

0 commit comments

Comments
 (0)