-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
message_steps.ts
211 lines (194 loc) · 5.95 KB
/
message_steps.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
import _ from 'lodash'
import { Then } from '../../'
import { expect } from 'chai'
import DataTable from '../../src/models/data_table'
import {
getPickleNamesInOrderOfExecution,
getPickleStep,
getTestCaseResult,
getTestStepAttachmentsForHook,
getTestStepAttachmentsForStep,
getTestStepResults,
} from '../support/message_helpers'
import { messages } from 'cucumber-messages'
type StringifiedStatus =
| 'UNKNOWN'
| 'PASSED'
| 'SKIPPED'
| 'PENDING'
| 'UNDEFINED'
| 'AMBIGUOUS'
| 'FAILED'
const { Status } = messages.TestResult
Then('it runs {int} scenarios', function(expectedCount: number) {
const testCaseStartedEvents = _.filter(
this.lastRun.envelopes,
e => e.testCaseStarted
)
expect(testCaseStartedEvents).to.have.lengthOf(expectedCount)
})
Then('it runs the scenario {string}', function(name: string) {
const actualNames = getPickleNamesInOrderOfExecution(this.lastRun.envelopes)
expect(actualNames).to.eql([name])
})
Then('it runs the scenarios {string} and {string}', function(
name1: string,
name2: string
) {
const actualNames = getPickleNamesInOrderOfExecution(this.lastRun.envelopes)
expect(actualNames).to.eql([name1, name2])
})
Then('it runs the scenarios:', function(table: DataTable) {
const expectedNames = table.rows().map(row => row[0])
const actualNames = getPickleNamesInOrderOfExecution(this.lastRun.envelopes)
expect(expectedNames).to.eql(actualNames)
})
Then('scenario {string} has status {string}', function(
name: string,
status: string
) {
const result = getTestCaseResult(this.lastRun.envelopes, name)
expect(result.status).to.eql(
Status[status.toUpperCase() as StringifiedStatus]
)
})
Then('the scenario {string} has the steps:', function(
name: string,
table: DataTable
) {
const actualTexts = getTestStepResults(this.lastRun.envelopes, name).map(
s => s.text
)
const expectedTexts = table.rows().map(row => row[0])
expect(actualTexts).to.eql(expectedTexts)
})
Then('scenario {string} step {string} has status {string}', function(
pickleName: string,
stepText: string,
status: string
) {
const testStepResults = getTestStepResults(this.lastRun.envelopes, pickleName)
const testStepResult = _.find(testStepResults, ['text', stepText])
expect(testStepResult.result.status).to.eql(
Status[status.toUpperCase() as StringifiedStatus]
)
})
Then(
'scenario {string} attempt {int} step {string} has status {string}',
function(
pickleName: string,
attempt: number,
stepText: string,
status: string
) {
const testStepResults = getTestStepResults(
this.lastRun.envelopes,
pickleName,
attempt
)
const testStepResult = _.find(testStepResults, ['text', stepText])
expect(testStepResult.result.status).to.eql(
Status[status.toUpperCase() as StringifiedStatus]
)
}
)
Then('scenario {string} {string} hook has status {string}', function(
pickleName: string,
hookKeyword: string,
status: string
) {
const testStepResults = getTestStepResults(this.lastRun.envelopes, pickleName)
const testStepResult = _.find(testStepResults, ['text', hookKeyword])
expect(testStepResult.result.status).to.eql(
Status[status.toUpperCase() as StringifiedStatus]
)
})
Then('scenario {string} step {string} failed with:', function(
pickleName: string,
stepText: string,
errorMessage: string
) {
const testStepResults = getTestStepResults(this.lastRun.envelopes, pickleName)
const testStepResult = _.find(testStepResults, ['text', stepText])
expect(testStepResult.result.status).to.eql(Status.FAILED)
expect(testStepResult.result.message).to.include(errorMessage)
})
Then('scenario {string} attempt {int} step {string} failed with:', function(
pickleName: string,
attempt: number,
stepText: string,
errorMessage: string
) {
const testStepResults = getTestStepResults(
this.lastRun.envelopes,
pickleName,
attempt
)
const testStepResult = _.find(testStepResults, ['text', stepText])
expect(testStepResult.result.status).to.eql(Status.FAILED)
expect(testStepResult.result.message).to.include(errorMessage)
})
Then('scenario {string} step {string} has the doc string:', function(
pickleName: string,
stepText: string,
docString: string
) {
const pickleStep = getPickleStep(this.lastRun.envelopes, pickleName, stepText)
expect(pickleStep.argument.docString.content).to.eql(docString)
})
Then('scenario {string} step {string} has the data table:', function(
pickleName: string,
stepText: string,
dataTable: DataTable
) {
const pickleStep = getPickleStep(this.lastRun.envelopes, pickleName, stepText)
expect(new DataTable(pickleStep.argument.dataTable)).to.eql(dataTable)
})
Then('scenario {string} step {string} has the attachments:', function(
pickleName: string,
stepText: string,
table: DataTable
) {
const expectedAttachments = table.hashes().map(x => {
return {
data: x.DATA,
media: messages.Media.fromObject({
contentType: x['MEDIA TYPE'],
encoding: messages.Media.Encoding[x['MEDIA ENCODING']],
}),
}
})
const stepAttachments = getTestStepAttachmentsForStep(
this.lastRun.envelopes,
pickleName,
stepText
)
const actualAttachments = stepAttachments.map(e => {
return { data: e.data, media: e.media }
})
expect(actualAttachments).to.eql(expectedAttachments)
})
Then('scenario {string} {string} hook has the attachments:', function(
pickleName: string,
hookKeyword: string,
table: DataTable
) {
const expectedAttachments = table.hashes().map(x => {
return {
data: x.DATA,
media: messages.Media.fromObject({
contentType: x['MEDIA TYPE'],
encoding: messages.Media.Encoding[x['MEDIA ENCODING']],
}),
}
})
const hookAttachments = getTestStepAttachmentsForHook(
this.lastRun.envelopes,
pickleName,
hookKeyword === 'Before'
)
const actualAttachments = hookAttachments.map(e => {
return { data: e.data, media: e.media }
})
expect(actualAttachments).to.eql(expectedAttachments)
})