1
- import * as assert from 'node:assert'
2
-
3
1
import { Query as GherkinQuery } from '@cucumber/gherkin-utils'
4
- import { Envelope , TestStepResultStatus } from '@cucumber/messages'
2
+ import { Envelope , TestCaseStarted , TestStepResultStatus } from '@cucumber/messages'
5
3
import xmlbuilder from 'xmlbuilder'
6
4
7
5
import { ExtendedQuery } from './ExtendedQuery.js'
8
6
import { countStatuses , durationToSeconds } from './helpers.js'
7
+ import * as assert from 'node:assert'
9
8
10
9
export default {
11
10
type : 'formatter' ,
@@ -27,30 +26,18 @@ export default {
27
26
cucumberQuery . update ( message )
28
27
29
28
if ( message . testRunFinished ) {
30
- builder . att ( 'time' , durationToSeconds ( cucumberQuery . findTestRunDuration ( ) ) )
31
- const statusCounts = cucumberQuery . countMostSevereTestStepResultStatus ( )
32
- builder . att ( 'tests' , countStatuses ( statusCounts ) )
33
- builder . att (
34
- 'skipped' ,
35
- countStatuses ( statusCounts , ( status ) => status === TestStepResultStatus . SKIPPED )
36
- )
37
- builder . att (
38
- 'failures' ,
39
- countStatuses (
40
- statusCounts ,
41
- ( status ) =>
42
- status !== TestStepResultStatus . PASSED && status !== TestStepResultStatus . SKIPPED
43
- )
44
- )
45
- builder . att ( 'errors' , 0 )
46
-
47
- for ( const testCaseStarted of cucumberQuery . findAllTestCaseStarted ( ) ) {
48
- const pickle = cucumberQuery . findPickleBy ( testCaseStarted )
49
- assert . ok ( pickle , 'Expected to find Pickle for TestCaseStarted' )
50
- builder . ele ( 'testcase' , {
51
- classname : pickle . uri ,
52
- name : pickle . name ,
53
- time : durationToSeconds ( cucumberQuery . findTestCaseDurationBy ( testCaseStarted ) ) ,
29
+ const testSuite = makeReport ( cucumberQuery )
30
+ builder . att ( 'time' , testSuite . time )
31
+ builder . att ( 'tests' , testSuite . tests )
32
+ builder . att ( 'skipped' , testSuite . skipped )
33
+ builder . att ( 'failures' , testSuite . failures )
34
+ builder . att ( 'errors' , testSuite . errors )
35
+
36
+ for ( const testCase of testSuite . testCases ) {
37
+ const element = builder . ele ( 'testcase' , {
38
+ classname : testCase . classname ,
39
+ name : testCase . name ,
40
+ time : testCase . time ,
54
41
} )
55
42
}
56
43
@@ -59,3 +46,45 @@ export default {
59
46
} )
60
47
} ,
61
48
}
49
+
50
+ interface Report {
51
+ time : number
52
+ tests : number
53
+ skipped : number
54
+ failures : number
55
+ errors : number
56
+ testCases : ReadonlyArray < TestCase >
57
+ }
58
+
59
+ interface TestCase {
60
+ classname : string
61
+ name : string
62
+ time : number
63
+ }
64
+
65
+ function makeReport ( query : ExtendedQuery ) : Report {
66
+ const statuses = query . countMostSevereTestStepResultStatus ( )
67
+ return {
68
+ time : durationToSeconds ( query . findTestRunDuration ( ) ) ,
69
+ tests : countStatuses ( statuses ) ,
70
+ skipped : countStatuses ( statuses , ( status ) => status === TestStepResultStatus . SKIPPED ) ,
71
+ failures : countStatuses (
72
+ statuses ,
73
+ ( status ) => status !== TestStepResultStatus . PASSED && status !== TestStepResultStatus . SKIPPED
74
+ ) ,
75
+ errors : 0 ,
76
+ testCases : makeTestCases ( query ) ,
77
+ }
78
+ }
79
+
80
+ function makeTestCases ( query : ExtendedQuery ) : ReadonlyArray < TestCase > {
81
+ return query . findAllTestCaseStarted ( ) . map ( ( testCaseStarted ) => {
82
+ const pickle = query . findPickleBy ( testCaseStarted )
83
+ assert . ok ( pickle , 'Expected to find Pickle by TestCaseStarted' )
84
+ return {
85
+ classname : pickle . uri ,
86
+ name : pickle . name ,
87
+ time : durationToSeconds ( query . findTestCaseDurationBy ( testCaseStarted ) ) ,
88
+ }
89
+ } )
90
+ }
0 commit comments