This repository was archived by the owner on Sep 21, 2022. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathsuite.js
More file actions
400 lines (302 loc) Β· 11.9 KB
/
Copy pathsuite.js
File metadata and controls
400 lines (302 loc) Β· 11.9 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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
'use strict';
const createSuite = require('lib/suite').create;
const State = require('lib/state');
const mkTree = require('../util').makeSuiteTree;
describe('suite', () => {
describe('create', () => {
it('should create named suite', () => {
const suite = createSuite('some name');
assert.equal(suite.name, 'some name');
});
it('should inherit properties from parent, if any', () => {
const parent = createSuite('parent');
const child = createSuite('child', parent);
parent.url = 'http://example.com';
assert.equal(child.url, parent.url);
});
it('should allow to overwrite parent properties', () => {
const parent = createSuite('parent');
const child = createSuite('child', parent);
parent.url = 'http://example.com';
child.url = 'http://example2.com';
assert.notEqual(child.url, parent.url);
});
it('should set `parent` property of a parent suite', () => {
const parent = createSuite('parent');
const child = createSuite('child', parent);
assert.equal(child.parent, parent);
});
it('child suite should have same data in context as parent', () => {
const parent = createSuite('parent');
parent.context.some = 'data';
const child = createSuite('child', parent);
assert.deepEqual(child.context, {some: 'data'});
});
it('modifications of child context should not affect parent context', () => {
const parent = createSuite('parent');
parent.context.some = 'data';
const child = createSuite('child', parent);
child.context.some = 'other-data';
child.context.other = 'data';
assert.deepEqual(parent.context, {some: 'data'});
});
it('should not allow to create suite with empty name', () => {
const parent = createSuite('parent');
assert.throws(() => createSuite('', parent), /Empty suite name/);
});
});
describe('states', () => {
let suite;
beforeEach(() => {
suite = createSuite('suite');
});
it('should be empty by default', () => {
assert.lengthOf(suite.states, 0);
});
it('should not be writable', () => {
assert.throws(() => suite.states = []);
});
it('should not be inherited', () => {
const child = createSuite('child', suite);
suite.addState({});
assert.lengthOf(child.states, 0);
});
});
describe('addChild', () => {
it('should add child for parent suite', () => {
const suite = createSuite('suite');
const child = createSuite('child', suite);
suite.addChild(child);
assert.equal(suite.children[0], child);
});
it('should set himself as a parent for child suite', () => {
const suite = createSuite('suite');
const anotherSuite = createSuite('another-suite');
suite.addChild(anotherSuite);
assert.equal(anotherSuite.parent, suite);
});
it('child suite should inherit properties from the parent', () => {
const suite = createSuite('suite');
const anotherSuite = createSuite('another-suite');
suite.addChild(anotherSuite);
assert.equal(Object.getPrototypeOf(anotherSuite), suite);
});
});
describe('addState', () => {
let suite;
beforeEach(() => {
suite = createSuite('suite');
});
it('should modify states property', () => {
const state = {name: 'some state'};
suite.addState(state);
assert.equal(suite.states[0], state);
});
it('should redefine parent suite for state', () => {
const state = {name: 'some state'};
suite.addState(state);
assert.equal(state.suite, suite);
});
});
describe('hasStates', () => {
let suite;
beforeEach(() => {
suite = createSuite('suite');
});
it('should be false if there is no states', () => {
assert.isFalse(suite.hasStates);
});
it('should be true if there are states', () => {
suite.addState({name: 'state'});
assert.isTrue(suite.hasStates);
});
});
describe('isRoot', () => {
it('should be true for root suites', () => {
const suite = createSuite('suite');
assert.isTrue(suite.isRoot);
});
it('should be false for child suites', () => {
const parent = createSuite('parent');
const child = createSuite('child', parent);
assert.isFalse(child.isRoot);
});
});
describe('skipped', () => {
let suite;
let matcher;
let matcher2;
beforeEach(() => {
suite = createSuite('suite');
matcher = {a: 1};
matcher2 = {b: 2};
});
it('should be empty by default', () => {
assert.deepEqual(suite.skipped, []);
});
it('should be changed by skip(object) method', () => {
suite.skip(matcher);
assert.deepEqual(suite.skipped, [matcher]);
});
it('should be inherited by children', () => {
suite.skip(matcher);
const child = createSuite('child', suite);
assert.equal(suite.skipped, child.skipped);
});
it('should merge multiple matchers together', () => {
suite.skip(matcher);
suite.skip(matcher2);
assert.deepEqual(suite.skipped, [matcher, matcher2]);
});
it('should merge children list with parent', () => {
suite.skip(matcher);
const child = createSuite('child', suite);
child.skip(matcher2);
assert.deepEqual(child.skipped, [matcher, matcher2]);
});
it('should not affect parent when calling .skip() on child', () => {
suite.skip(matcher);
const child = createSuite('child', suite);
child.skip(matcher2);
assert.deepEqual(suite.skipped, [matcher]);
});
});
describe('shouldSkip', () => {
let suite;
const createBrowserSkipMatcher = (browserId) => {
const matcher = {matches: sinon.stub()};
matcher.matches.withArgs(browserId).returns(true);
return matcher;
};
beforeEach(() => suite = createSuite('suite'));
it('should be "false" for any browser if a suite is not skipped', function() {
assert.isFalse(suite.shouldSkip('browser'));
});
it('should be "true" for a browser if a suite is skipped in it', () => {
suite.skip(createBrowserSkipMatcher('1st-skipped-bro'));
suite.skip(createBrowserSkipMatcher('2nd-skipped-bro'));
assert.isTrue(suite.shouldSkip('1st-skipped-bro'));
assert.isTrue(suite.shouldSkip('2nd-skipped-bro'));
});
it('should set a skip comment if a suite is skipped in a browser', () => {
suite.skip({matches: sinon.stub().withArgs('skipped-bro').returns(true), comment: 'skip-comment'});
suite.shouldSkip('skipped-bro');
assert.equal(suite.skipComment, 'skip-comment');
});
it('should be "false" for a browser if a suite is not skipped in it', () => {
suite.skip(createBrowserSkipMatcher('1st-skipped-bro'));
suite.skip(createBrowserSkipMatcher('2st-skipped-bro'));
assert.isFalse(suite.shouldSkip('some-bro'));
});
});
describe('hasChild', () => {
let suite;
beforeEach(() => {
suite = createSuite('parent');
const child = createSuite('has', suite);
child.browsers = ['bro1', 'bro2'];
suite.addChild(child);
});
it('should return true when suite has child with given name and intersected browser set', () => {
assert.isTrue(suite.hasChild('has', ['bro1']));
});
describe('should return false when', () => {
it('suite has no child with given name', () => {
assert.isFalse(suite.hasChild('has no', []));
});
it('has child with given name and not intersected browser set', () => {
assert.isFalse(suite.hasChild('has no', ['bad-bro']));
});
});
});
describe('hasStateNamed', () => {
let suite;
beforeEach(() => {
suite = createSuite('suite');
suite.addState({name: 'has'});
});
it('should return true when suite has state of a given name', () => {
assert.isTrue(suite.hasStateNamed('has'));
});
it('should return true when suite has state of a given name', () => {
assert.isFalse(suite.hasStateNamed('has no'));
});
});
describe('fullName', () => {
let parent;
let child;
beforeEach(() => {
parent = createSuite('parent');
child = createSuite('child', parent);
});
it('should return name for top level suite', () => {
assert.equal(parent.fullName, 'parent');
});
it('should concat own name with parents', () => {
assert.equal(child.fullName, 'parent child');
});
});
describe('suite clone', () => {
let sandbox;
beforeEach(() => {
sandbox = sinon.sandbox.create();
});
afterEach(() => sandbox.restore());
it('should return cloned suite', () => {
const suite = createSuite('origin');
const clonedSuite = suite.clone();
assert.notEqual(clonedSuite, suite);
});
it('should clone nested suites', () => {
const tree = mkTree({
suite: {
child: []
}
});
const childSuite = tree.child;
sandbox.stub(childSuite, 'clone').returns({});
tree.suite.clone();
assert.calledOnce(childSuite.clone);
});
it('should not change child suite count while cloning', () => {
const tree = mkTree({
suite: {
child: []
}
});
const clonedSuite = tree.suite.clone();
assert.lengthOf(clonedSuite.children, 1);
});
it('should redefine parent for nested suites', () => {
const suite = createSuite('origin');
const childSuite = createSuite('child suite');
suite.addChild(childSuite);
const clonedSuite = suite.clone();
assert.deepEqual(clonedSuite.children[0].parent, clonedSuite);
});
it('should clone nested states', () => {
const suite = createSuite('origin');
const state = new State(suite);
sandbox.stub(state, 'clone').returns({});
suite.addState(state);
suite.clone();
assert.calledOnce(state.clone);
});
it('should redefine parent suite for state', () => {
const suite = createSuite('origin');
const state = new State(suite);
suite.addState(state);
const clonedSuite = suite.clone();
assert.equal(clonedSuite.states[0].suite, clonedSuite);
});
it('should not change state count while cloning', () => {
const suite = createSuite('origin');
const state1 = new State(suite);
const state2 = new State(suite);
suite.addState(state1);
suite.addState(state2);
const clonedSuite = suite.clone();
assert.lengthOf(clonedSuite.states, 2);
});
});
});