1
1
import { SupportCode } from '@cucumber/fake-cucumber'
2
2
import { Query as GherkinQuery } from '@cucumber/gherkin-utils'
3
3
import * as messages from '@cucumber/messages'
4
- import { SourceReference , TestStepResultStatus } from '@cucumber/messages'
4
+ import { Envelope , SourceReference , TestStepResultStatus } from '@cucumber/messages'
5
5
import { Query as CucumberQuery } from '@cucumber/query'
6
+ import fs from 'fs'
7
+ import path from 'path'
6
8
7
9
import { runFeature } from '../test-utils'
8
10
import countScenariosByStatuses from './countScenariosByStatuses'
11
+ import { EnvelopesQuery } from './EnvelopesQueryContext'
9
12
10
13
const sourceReference : SourceReference = { }
11
14
12
15
describe ( 'countScenariosByStatuses' , ( ) => {
13
16
let gherkinQuery : GherkinQuery
14
17
let cucumberQuery : CucumberQuery
18
+ let envelopesQuery : EnvelopesQuery
15
19
let supportCode : SupportCode
16
20
17
21
jest . setTimeout ( 3000 )
18
22
19
23
beforeEach ( ( ) => {
20
24
gherkinQuery = new GherkinQuery ( )
21
25
cucumberQuery = new CucumberQuery ( )
26
+ envelopesQuery = new EnvelopesQuery ( )
22
27
supportCode = new SupportCode ( )
23
28
supportCode . defineStepDefinition ( sourceReference , 'a passed step' , ( ) => null )
24
29
supportCode . defineStepDefinition ( sourceReference , 'a failed step' , ( ) => {
@@ -45,10 +50,11 @@ Feature: statuses
45
50
const envelopes = await runFeature ( feature , gherkinQuery , supportCode )
46
51
for ( const envelope of envelopes ) {
47
52
cucumberQuery . update ( envelope )
53
+ envelopesQuery . update ( envelope )
48
54
}
49
55
50
56
const { scenarioCountByStatus, statusesWithScenarios, totalScenarioCount } =
51
- countScenariosByStatuses ( gherkinQuery , cucumberQuery )
57
+ countScenariosByStatuses ( gherkinQuery , cucumberQuery , envelopesQuery )
52
58
53
59
expect ( scenarioCountByStatus [ messages . TestStepResultStatus . PASSED ] ) . toEqual ( 2 )
54
60
expect ( scenarioCountByStatus [ messages . TestStepResultStatus . FAILED ] ) . toEqual ( 1 )
@@ -79,10 +85,11 @@ Feature: statuses
79
85
const envelopes = await runFeature ( feature , gherkinQuery , supportCode )
80
86
for ( const envelope of envelopes ) {
81
87
cucumberQuery . update ( envelope )
88
+ envelopesQuery . update ( envelope )
82
89
}
83
90
84
91
const { scenarioCountByStatus, statusesWithScenarios, totalScenarioCount } =
85
- countScenariosByStatuses ( gherkinQuery , cucumberQuery )
92
+ countScenariosByStatuses ( gherkinQuery , cucumberQuery , envelopesQuery )
86
93
87
94
expect ( scenarioCountByStatus [ messages . TestStepResultStatus . PASSED ] ) . toEqual ( 1 )
88
95
expect ( scenarioCountByStatus [ messages . TestStepResultStatus . FAILED ] ) . toEqual ( 1 )
@@ -94,4 +101,29 @@ Feature: statuses
94
101
] )
95
102
expect ( totalScenarioCount ) . toEqual ( 3 )
96
103
} )
104
+
105
+ it ( 'only includes pickles that were slated for execution as test cases' , ( ) => {
106
+ const raw = fs . readFileSync (
107
+ path . join ( __dirname , '../test-utils/messages/filtered-pickles.ndjson' ) ,
108
+ {
109
+ encoding : 'utf-8' ,
110
+ }
111
+ )
112
+ const envelopes : Envelope [ ] = JSON . parse ( '[' + raw . trim ( ) . split ( '\n' ) . join ( ',' ) + ']' )
113
+ const gherkinQuery = new GherkinQuery ( )
114
+ const cucumberQuery = new CucumberQuery ( )
115
+ envelopes . forEach ( ( envelope ) => {
116
+ gherkinQuery . update ( envelope )
117
+ cucumberQuery . update ( envelope )
118
+ envelopesQuery . update ( envelope )
119
+ } )
120
+
121
+ const { totalScenarioCount } = countScenariosByStatuses (
122
+ gherkinQuery ,
123
+ cucumberQuery ,
124
+ envelopesQuery
125
+ )
126
+
127
+ expect ( totalScenarioCount ) . toEqual ( 1 )
128
+ } )
97
129
} )
0 commit comments