1
1
import * as assert from 'node:assert'
2
2
3
3
import { Query as GherkinQuery } from '@cucumber/gherkin-utils'
4
- import { Envelope , TestStepResultStatus } from '@cucumber/messages'
4
+ import { Envelope , TestCaseStarted , TestStepResultStatus } from '@cucumber/messages'
5
5
import xmlbuilder from 'xmlbuilder'
6
6
7
7
import { ExtendedQuery } from './ExtendedQuery.js'
@@ -35,12 +35,15 @@ export default {
35
35
builder . att ( 'errors' , testSuite . errors )
36
36
37
37
for ( const testCase of testSuite . testCases ) {
38
- const element = builder . ele ( 'testcase' , {
38
+ const testcaseElement = builder . ele ( 'testcase' , {
39
39
classname : testCase . classname ,
40
40
name : testCase . name ,
41
41
time : testCase . time ,
42
42
} )
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 )
44
47
}
45
48
46
49
write ( builder . end ( { pretty : true } ) )
@@ -49,23 +52,28 @@ export default {
49
52
} ,
50
53
}
51
54
52
- interface Report {
55
+ interface ReportSuite {
53
56
time : number
54
57
tests : number
55
58
skipped : number
56
59
failures : number
57
60
errors : number
58
- testCases : ReadonlyArray < TestCase >
61
+ testCases : ReadonlyArray < ReportTestCase >
59
62
}
60
63
61
- interface TestCase {
64
+ interface ReportTestCase {
62
65
classname : string
63
66
name : string
64
67
time : number
68
+ failure ?: ReportFailure
65
69
output : string
66
70
}
67
71
68
- function makeReport ( query : ExtendedQuery ) : Report {
72
+ interface ReportFailure {
73
+ type : 'failure' | 'skipped'
74
+ }
75
+
76
+ function makeReport ( query : ExtendedQuery ) : ReportSuite {
69
77
const statuses = query . countMostSevereTestStepResultStatus ( )
70
78
return {
71
79
time : durationToSeconds ( query . findTestRunDuration ( ) ) ,
@@ -80,14 +88,15 @@ function makeReport(query: ExtendedQuery): Report {
80
88
}
81
89
}
82
90
83
- function makeTestCases ( query : ExtendedQuery ) : ReadonlyArray < TestCase > {
91
+ function makeTestCases ( query : ExtendedQuery ) : ReadonlyArray < ReportTestCase > {
84
92
return query . findAllTestCaseStarted ( ) . map ( ( testCaseStarted ) => {
85
93
const pickle = query . findPickleBy ( testCaseStarted )
86
94
assert . ok ( pickle , 'Expected to find Pickle by TestCaseStarted' )
87
95
return {
88
96
classname : pickle . uri ,
89
97
name : pickle . name ,
90
98
time : durationToSeconds ( query . findTestCaseDurationBy ( testCaseStarted ) ) ,
99
+ failure : makeFailure ( query , testCaseStarted ) ,
91
100
output : query
92
101
. findTestStepFinishedAndTestStepBy ( testCaseStarted )
93
102
// filter out hooks
@@ -103,3 +112,16 @@ function makeTestCases(query: ExtendedQuery): ReadonlyArray<TestCase> {
103
112
}
104
113
} )
105
114
}
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