-
-
Notifications
You must be signed in to change notification settings - Fork 751
Expand file tree
/
Copy pathui_test.js
More file actions
309 lines (247 loc) · 11.4 KB
/
Copy pathui_test.js
File metadata and controls
309 lines (247 loc) · 11.4 KB
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
let expect
import('chai').then(chai => {
expect = chai.expect
})
const Mocha = require('mocha/lib/mocha')
const Suite = require('mocha/lib/suite')
const { createTest } = require('../../../lib/mocha/test')
global.codeceptjs = require('../../../lib')
const makeUI = require('../../../lib/mocha/ui')
const container = require('../../../lib/container')
describe('ui', () => {
let suite
let context
beforeEach(() => {
container.clear()
context = {}
suite = new Suite('empty')
makeUI(suite)
suite.emit('pre-require', context, {}, new Mocha())
})
describe('basic constants', () => {
const constants = ['Before', 'Background', 'BeforeAll', 'After', 'AfterAll', 'Scenario', 'xScenario']
constants.forEach(c => {
it(`context should contain ${c}`, () => expect(context[c]).is.ok)
})
it('context should contain Feature.only', () => {
expect(context.Feature.only).is.ok
expect(context.Feature.only).to.be.a('function')
})
})
describe('Feature', () => {
let suiteConfig
it('Feature should return featureConfig', () => {
suiteConfig = context.Feature('basic suite')
expect(suiteConfig.suite).is.ok
})
it('should contain title', () => {
suiteConfig = context.Feature('basic suite')
expect(suiteConfig.suite).is.ok
expect(suiteConfig.suite.title).eq('basic suite')
expect(suiteConfig.suite.fullTitle()).eq('basic suite:')
})
it('should contain tags', () => {
suiteConfig = context.Feature('basic suite')
expect(0).eq(suiteConfig.suite.tags.length)
suiteConfig = context.Feature('basic suite @very @important')
expect(suiteConfig.suite).is.ok
suiteConfig.suite.tags.should.include('@very')
suiteConfig.suite.tags.should.include('@important')
suiteConfig.tag('@user')
suiteConfig.suite.tags.should.include('@user')
suiteConfig.suite.tags.should.not.include('@slow')
suiteConfig.tag('slow')
suiteConfig.suite.tags.should.include('@slow')
})
it('retries can be set', () => {
suiteConfig = context.Feature('basic suite')
suiteConfig.retry(3)
expect(3).eq(suiteConfig.suite.retries())
})
it('timeout can be set', () => {
suiteConfig = context.Feature('basic suite')
expect(0).eq(suiteConfig.suite.timeout())
suiteConfig.timeout(3)
expect(3).eq(suiteConfig.suite.timeout())
})
it('helpers can be configured', () => {
suiteConfig = context.Feature('basic suite')
expect(!suiteConfig.suite.config)
suiteConfig.config('WebDriver', { browser: 'chrome' })
expect('chrome').eq(suiteConfig.suite.config.WebDriver.browser)
suiteConfig.config({ browser: 'firefox' })
expect('firefox').eq(suiteConfig.suite.config[0].browser)
suiteConfig.config('WebDriver', () => {
return { browser: 'edge' }
})
expect('edge').eq(suiteConfig.suite.config.WebDriver.browser)
})
it('Feature can be skipped', () => {
suiteConfig = context.Feature.skip('skipped suite')
expect(suiteConfig.suite.pending).eq(true, 'Skipped Feature must be contain pending === true')
expect(suiteConfig.suite.opts.skipInfo.message).eq('Skipped due to "skip" on Feature.')
expect(suiteConfig.suite.opts.skipInfo.skipped).eq(true, 'Skip should be set on skipInfo')
})
it('Feature can be skipped via xFeature', () => {
suiteConfig = context.xFeature('skipped suite')
expect(suiteConfig.suite.pending).eq(true, 'Skipped Feature must be contain pending === true')
expect(suiteConfig.suite.opts.skipInfo.message).eq('Skipped due to "skip" on Feature.')
expect(suiteConfig.suite.opts.skipInfo.skipped).eq(true, 'Skip should be set on skipInfo')
})
it('Feature are not skipped by default', () => {
suiteConfig = context.Feature('not skipped suite')
expect(suiteConfig.suite.pending).eq(false, 'Feature must not contain pending === true')
// expect(suiteConfig.suite.opts, undefined, 'Features should have no skip info');
})
it('Feature can be skipped', () => {
suiteConfig = context.Feature.skip('skipped suite')
expect(suiteConfig.suite.pending).eq(true, 'Skipped Feature must be contain pending === true')
expect(suiteConfig.suite.opts.skipInfo.message).eq('Skipped due to "skip" on Feature.')
expect(suiteConfig.suite.opts.skipInfo.skipped).eq(true, 'Skip should be set on skipInfo')
})
it('Feature can be skipped via xFeature', () => {
suiteConfig = context.xFeature('skipped suite')
expect(suiteConfig.suite.pending).eq(true, 'Skipped Feature must be contain pending === true')
expect(suiteConfig.suite.opts.skipInfo.message).eq('Skipped due to "skip" on Feature.')
expect(suiteConfig.suite.opts.skipInfo.skipped).eq(true, 'Skip should be set on skipInfo')
})
it('Feature are not skipped by default', () => {
suiteConfig = context.Feature('not skipped suite')
expect(suiteConfig.suite.pending).eq(false, 'Feature must not contain pending === true')
expect(suiteConfig.suite.opts).to.deep.eq({}, 'Features should have no skip info')
})
it('Feature can be run exclusively with only', () => {
// Create a new mocha instance to test grep behavior
const mocha = new Mocha()
let grepPattern = null
// Mock mocha.grep to capture the pattern
const originalGrep = mocha.grep
mocha.grep = function (pattern) {
grepPattern = pattern
return this
}
// Reset environment variable
delete process.env.FEATURE_ONLY
// Re-emit pre-require with our mocked mocha instance
suite.emit('pre-require', context, {}, mocha)
suiteConfig = context.Feature.only('exclusive feature', { key: 'value' })
expect(suiteConfig.suite.title).eq('exclusive feature')
expect(suiteConfig.suite.opts).to.deep.eq({ key: 'value' }, 'Feature.only should pass options correctly')
expect(suiteConfig.suite.pending).eq(false, 'Feature.only must not be pending')
expect(grepPattern).to.be.instanceOf(RegExp)
expect(grepPattern.source).eq('^exclusive feature:')
expect(process.env.FEATURE_ONLY).eq('true', 'FEATURE_ONLY environment variable should be set')
// Restore original grep
mocha.grep = originalGrep
})
it('Feature.only should work without options', () => {
// Create a new mocha instance to test grep behavior
const mocha = new Mocha()
let grepPattern = null
// Mock mocha.grep to capture the pattern
const originalGrep = mocha.grep
mocha.grep = function (pattern) {
grepPattern = pattern
return this
}
// Reset environment variable
delete process.env.FEATURE_ONLY
// Re-emit pre-require with our mocked mocha instance
suite.emit('pre-require', context, {}, mocha)
suiteConfig = context.Feature.only('exclusive feature without options')
expect(suiteConfig.suite.title).eq('exclusive feature without options')
expect(suiteConfig.suite.opts).to.deep.eq({}, 'Feature.only without options should have empty opts')
expect(suiteConfig.suite.pending).eq(false, 'Feature.only must not be pending')
expect(grepPattern).to.be.instanceOf(RegExp)
expect(grepPattern.source).eq('^exclusive feature without options:')
expect(process.env.FEATURE_ONLY).eq('true', 'FEATURE_ONLY environment variable should be set')
// Restore original grep
mocha.grep = originalGrep
})
it('Feature should correctly pass options to suite context', () => {
suiteConfig = context.Feature('not skipped suite', { key: 'value' })
expect(suiteConfig.suite.opts).to.deep.eq({ key: 'value' }, 'Features should have passed options')
})
it('should be able to set metadata', () => {
suiteConfig = context.Feature('suite')
const test1 = createTest('test', () => {})
const test2 = createTest('test2', () => {})
test1.addToSuite(suiteConfig.suite)
test2.addToSuite(suiteConfig.suite)
suiteConfig.meta('key', 'value')
expect(test1.meta.key).eq('value')
expect(test2.meta.key).eq('value')
})
})
describe('Scenario', () => {
let scenarioConfig
it('Scenario should return scenarioConfig', () => {
scenarioConfig = context.Scenario('basic scenario')
expect(scenarioConfig.test).is.ok
})
it('should contain title', () => {
context.Feature('suite')
scenarioConfig = context.Scenario('scenario')
expect(scenarioConfig.test.title).eq('scenario')
expect(scenarioConfig.test.fullTitle()).eq('suite: scenario')
expect(scenarioConfig.test.tags.length).eq(0)
})
it('should contain tags', () => {
context.Feature('basic suite @cool')
scenarioConfig = context.Scenario('scenario @very @important')
scenarioConfig.test.tags.should.include('@cool')
scenarioConfig.test.tags.should.include('@very')
scenarioConfig.test.tags.should.include('@important')
scenarioConfig.tag('@user')
scenarioConfig.test.tags.should.include('@user')
})
it('should dynamically inject dependencies', () => {
scenarioConfig = context.Scenario('scenario')
scenarioConfig.injectDependencies({ Data: 'data' })
expect(scenarioConfig.test.inject.Data).eq('data')
})
it('should be able to set metadata', () => {
scenarioConfig = context.Scenario('scenario')
scenarioConfig.meta('key', 'value')
expect(scenarioConfig.test.meta.key).eq('value')
})
describe('todo', () => {
it('should inject skipInfo to opts', () => {
scenarioConfig = context.Scenario.todo('scenario', () => {
console.log('Scenario Body')
})
expect(scenarioConfig.test.pending).eq(true, 'Todo Scenario must be contain pending === true')
expect(scenarioConfig.test.opts.skipInfo.message).eq('Test not implemented!')
expect(scenarioConfig.test.opts.skipInfo.description).to.include("console.log('Scenario Body')")
})
it('should contain empty description in skipInfo and empty body', () => {
scenarioConfig = context.Scenario.todo('scenario')
expect(scenarioConfig.test.pending).eq(true, 'Todo Scenario must be contain pending === true')
expect(scenarioConfig.test.opts.skipInfo.description).eq('')
expect(scenarioConfig.test.body).eq('')
})
it('should inject custom opts to opts and without callback', () => {
scenarioConfig = context.Scenario.todo('scenario', { customOpts: 'Custom Opts' })
expect(scenarioConfig.test.opts.customOpts).eq('Custom Opts')
})
it('should inject custom opts to opts and with callback', () => {
scenarioConfig = context.Scenario.todo('scenario', { customOpts: 'Custom Opts' }, () => {
console.log('Scenario Body')
})
expect(scenarioConfig.test.opts.customOpts).eq('Custom Opts')
})
})
describe('skip', () => {
it('should inject custom opts to opts and without callback', () => {
scenarioConfig = context.Scenario.skip('scenario', { customOpts: 'Custom Opts' })
expect(scenarioConfig.test.opts.customOpts).eq('Custom Opts')
})
it('should inject custom opts to opts and with callback', () => {
scenarioConfig = context.Scenario.skip('scenario', { customOpts: 'Custom Opts' }, () => {
console.log('Scenario Body')
})
expect(scenarioConfig.test.opts.customOpts).eq('Custom Opts')
})
})
})
})