1
- import * as assert from 'node:assert'
2
-
3
- import { Envelope , TestCaseStarted , TestStepResultStatus } from '@cucumber/messages'
1
+ import { Envelope } from '@cucumber/messages'
4
2
import xmlbuilder from 'xmlbuilder'
5
3
6
4
import { ExtendedQuery } from './ExtendedQuery.js'
7
- import { countStatuses , durationToSeconds , formatStep } from './helpers.js'
8
- import {
9
- namingStrategy ,
10
- NamingStrategyExampleName ,
11
- NamingStrategyFeatureName ,
12
- NamingStrategyLength ,
13
- } from './Lineage.js'
14
-
15
- const NAMING_STRATEGY = namingStrategy (
16
- NamingStrategyLength . LONG ,
17
- NamingStrategyFeatureName . EXCLUDE ,
18
- NamingStrategyExampleName . NUMBER_AND_PICKLE_IF_PARAMETERIZED
19
- )
5
+ import { makeReport } from './makeReport.js'
20
6
21
7
export default {
22
8
type : 'formatter' ,
@@ -27,16 +13,16 @@ export default {
27
13
on : ( type : 'message' , handler : ( message : Envelope ) => void ) => void
28
14
write : ( content : string ) => void
29
15
} ) {
30
- const cucumberQuery = new ExtendedQuery ( )
16
+ const query = new ExtendedQuery ( )
31
17
const builder = xmlbuilder
32
18
. create ( 'testsuite' , { invalidCharReplacement : '' } )
33
19
. att ( 'name' , 'Cucumber' )
34
20
35
21
on ( 'message' , ( message ) => {
36
- cucumberQuery . update ( message )
22
+ query . update ( message )
37
23
38
24
if ( message . testRunFinished ) {
39
- const testSuite = makeReport ( cucumberQuery )
25
+ const testSuite = makeReport ( query )
40
26
builder . att ( 'time' , testSuite . time )
41
27
builder . att ( 'tests' , testSuite . tests )
42
28
builder . att ( 'skipped' , testSuite . skipped )
@@ -69,85 +55,3 @@ export default {
69
55
} )
70
56
} ,
71
57
}
72
-
73
- interface ReportSuite {
74
- time : number
75
- tests : number
76
- skipped : number
77
- failures : number
78
- errors : number
79
- testCases : ReadonlyArray < ReportTestCase >
80
- }
81
-
82
- interface ReportTestCase {
83
- classname : string
84
- name : string
85
- time : number
86
- failure ?: ReportFailure
87
- output : string
88
- }
89
-
90
- interface ReportFailure {
91
- kind : 'failure' | 'skipped'
92
- type ?: string
93
- message ?: string
94
- stack ?: string
95
- }
96
-
97
- function makeReport ( query : ExtendedQuery ) : ReportSuite {
98
- const statuses = query . countMostSevereTestStepResultStatus ( )
99
- return {
100
- time : durationToSeconds ( query . findTestRunDuration ( ) ) ,
101
- tests : countStatuses ( statuses ) ,
102
- skipped : countStatuses ( statuses , ( status ) => status === TestStepResultStatus . SKIPPED ) ,
103
- failures : countStatuses (
104
- statuses ,
105
- ( status ) => status !== TestStepResultStatus . PASSED && status !== TestStepResultStatus . SKIPPED
106
- ) ,
107
- errors : 0 ,
108
- testCases : makeTestCases ( query ) ,
109
- }
110
- }
111
-
112
- function makeTestCases ( query : ExtendedQuery ) : ReadonlyArray < ReportTestCase > {
113
- return query . findAllTestCaseStarted ( ) . map ( ( testCaseStarted ) => {
114
- const pickle = query . findPickleBy ( testCaseStarted )
115
- assert . ok ( pickle , 'Expected to find Pickle by TestCaseStarted' )
116
- const lineage = query . findLineageBy ( pickle )
117
-
118
- return {
119
- classname : lineage ?. feature ?. name ?? pickle . uri ,
120
- name : query . findNameOf ( pickle , NAMING_STRATEGY ) ,
121
- time : durationToSeconds ( query . findTestCaseDurationBy ( testCaseStarted ) ) ,
122
- failure : makeFailure ( query , testCaseStarted ) ,
123
- output : query
124
- . findTestStepFinishedAndTestStepBy ( testCaseStarted )
125
- // filter out hooks
126
- . filter ( ( [ , testStep ] ) => ! ! testStep . pickleStepId )
127
- . map ( ( [ testStepFinished , testStep ] ) => {
128
- const pickleStep = query . findPickleStepBy ( testStep )
129
- assert . ok ( pickleStep , 'Expected to find PickleStep by TestStep' )
130
- const gherkinStep = query . findStepBy ( pickleStep )
131
- assert . ok ( gherkinStep , 'Expected to find Step by PickleStep' )
132
- return formatStep ( gherkinStep , pickleStep , testStepFinished . testStepResult . status )
133
- } )
134
- . join ( '\n' ) ,
135
- }
136
- } )
137
- }
138
-
139
- function makeFailure (
140
- query : ExtendedQuery ,
141
- testCaseStarted : TestCaseStarted
142
- ) : ReportFailure | undefined {
143
- const result = query . findMostSevereTestStepResultBy ( testCaseStarted )
144
- if ( result . status === TestStepResultStatus . PASSED ) {
145
- return undefined
146
- }
147
- return {
148
- kind : result . status === TestStepResultStatus . SKIPPED ? 'skipped' : 'failure' ,
149
- type : result . exception ?. type ,
150
- message : result . exception ?. message ,
151
- stack : result . exception ?. stackTrace ?? result . message ,
152
- }
153
- }
0 commit comments