-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathrerun_formatter_spec.ts
223 lines (192 loc) · 6.06 KB
/
rerun_formatter_spec.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
212
213
214
215
216
217
218
219
220
221
222
223
import { describe, it } from 'mocha'
import { expect } from 'chai'
import { buildSupportCodeLibrary } from '../../test/runtime_helpers'
import { testFormatter } from '../../test/formatter_helpers'
const onePickleSources = [
{
data: 'Feature: a\nScenario: b\nGiven a step',
uri: 'a.feature',
},
]
describe('RerunFormatter', () => {
describe('with no scenarios', () => {
it('outputs nothing', async () => {
// Arrange
// Act
const output = await testFormatter({ type: 'rerun' })
// Assert
expect(output).to.eql('')
})
})
describe('with one scenario', () => {
describe('passed', () => {
it('outputs nothing', async () => {
// Arrange
const supportCodeLibrary = buildSupportCodeLibrary(({ Given }) => {
Given('a step', function () {}) // eslint-disable-line @typescript-eslint/no-empty-function
})
// Act
const output = await testFormatter({
sources: onePickleSources,
supportCodeLibrary,
type: 'rerun',
})
// Assert
expect(output).to.eql('')
})
})
describe('ambiguous', () => {
it('outputs the reference needed to run the scenario again', async () => {
// Arrange
const supportCodeLibrary = buildSupportCodeLibrary(({ Given }) => {
Given('a step', function () {}) // eslint-disable-line @typescript-eslint/no-empty-function
Given('a step', function () {}) // eslint-disable-line @typescript-eslint/no-empty-function
})
// Act
const output = await testFormatter({
sources: onePickleSources,
supportCodeLibrary,
type: 'rerun',
})
// Assert
expect(output).to.eql('a.feature:2')
})
})
describe('failed', () => {
it('outputs the reference needed to run the scenario again', async () => {
// Arrange
const supportCodeLibrary = buildSupportCodeLibrary(({ Given }) => {
Given('a step', function () {
throw new Error('error')
})
})
// Act
const output = await testFormatter({
sources: onePickleSources,
supportCodeLibrary,
type: 'rerun',
})
// Assert
expect(output).to.eql('a.feature:2')
})
})
describe('pending', () => {
it('outputs the reference needed to run the scenario again', async () => {
// Arrange
const supportCodeLibrary = buildSupportCodeLibrary(({ Given }) => {
Given('a step', function () {
return 'pending'
})
})
// Act
const output = await testFormatter({
sources: onePickleSources,
supportCodeLibrary,
type: 'rerun',
})
// Assert
expect(output).to.eql('a.feature:2')
})
})
describe('skipped', () => {
it('outputs the reference needed to run the scenario again', async () => {
// Arrange
const supportCodeLibrary = buildSupportCodeLibrary(({ Given }) => {
Given('a step', function () {
return 'skipped'
})
})
// Act
const output = await testFormatter({
sources: onePickleSources,
supportCodeLibrary,
type: 'rerun',
})
// Assert
expect(output).to.eql('a.feature:2')
})
})
describe('undefined', () => {
it('outputs the reference needed to run the scenario again', async () => {
// Arrange
// Act
const output = await testFormatter({
sources: onePickleSources,
type: 'rerun',
})
// Assert
expect(output).to.eql('a.feature:2')
})
})
})
describe('with two failing scenarios in the same file', () => {
it('outputs the reference needed to run the scenario again', async () => {
// Arrange
const sources = [
{
data: 'Feature: a\nScenario: b\nGiven a step\nScenario: c\nGiven a step',
uri: 'a.feature',
},
]
// Act
const output = await testFormatter({ sources, type: 'rerun' })
// Assert
expect(output).to.eql('a.feature:2:4')
})
})
describe('with two failing scenarios in different files', () => {
const examples = [
{ separator: { opt: undefined, expected: '\n' }, label: 'default' },
{ separator: { opt: '\n', expected: '\n' }, label: 'newline' },
{ separator: { opt: ' ', expected: ' ' }, label: 'space' },
]
examples.forEach(({ separator, label }) => {
describe(`using ${label} separator`, () => {
it('outputs the reference needed to run the scenario again', async () => {
// Arrange
const parsedArgvOptions = { rerun: { separator: separator.opt } }
const sources = [
{
data: 'Feature: a\nScenario: b\nGiven a step',
uri: 'a.feature',
},
{
data: 'Feature: a\n\nScenario: b\nGiven a step',
uri: 'b.feature',
},
]
// Act
const output = await testFormatter({
parsedArgvOptions,
sources,
type: 'rerun',
})
// Assert
expect(output).to.eql(`a.feature:2${separator.expected}b.feature:3`)
})
it('outputs the reference needed to run the rule example again', async () => {
// Arrange
const parsedArgvOptions = { rerun: { separator: separator.opt } }
const sources = [
{
data: 'Feature: a\nRule: b\nExample: c\nGiven a step',
uri: 'a.feature',
},
{
data: 'Feature: a\n\nRule: b\nExample: c\nGiven a step',
uri: 'b.feature',
},
]
// Act
const output = await testFormatter({
parsedArgvOptions,
sources,
type: 'rerun',
})
// Assert
expect(output).to.eql(`a.feature:3${separator.expected}b.feature:4`)
})
})
})
})
})