Skip to content
This repository was archived by the owner on Sep 21, 2022. It is now read-only.

Commit 2572af5

Browse files
committed
fix: Implement advanced verification for suites with same names
It is necessary to avoid error which occurs on testing suites with same names but on different platforms
1 parent 57a319a commit 2572af5

4 files changed

Lines changed: 42 additions & 13 deletions

File tree

lib/suite.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,10 @@ module.exports = class Suite {
8080
return clonedSuite;
8181
}
8282

83-
hasChildNamed(name) {
84-
return _.some(this._children, {name: name});
83+
hasChild(name, browsers) {
84+
return _.some(this.children, (child) => {
85+
return _.isEqual(child.name, name) && !_.isEmpty(_.intersection(child.browsers, browsers));
86+
});
8587
}
8688

8789
hasStateNamed(name) {

lib/tests-api/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module.exports = (suite, browsers) => {
1717
throw new TypeError('Second argument of the gemini.suite must be a function');
1818
}
1919

20-
if (suite.hasChildNamed(name)) {
20+
if (suite.hasChild(name, browsers)) {
2121
throw new Error(`Suite ${name} already exists at this level. Choose different name`);
2222
}
2323

test/unit/suite.test.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,21 +226,28 @@ describe('suite', () => {
226226
});
227227
});
228228

229-
describe('hasChildNamed', () => {
229+
describe('hasChild', () => {
230230
let suite;
231231

232232
beforeEach(() => {
233233
suite = createSuite('parent');
234234
const child = createSuite('has', suite);
235+
child.browsers = ['bro1', 'bro2'];
235236
suite.addChild(child);
236237
});
237238

238-
it('should return true when suite has child of a given name', () => {
239-
assert.isTrue(suite.hasChildNamed('has'));
239+
it('should return true when suite has child with given name and intersected browser set', () => {
240+
assert.isTrue(suite.hasChild('has', ['bro1']));
240241
});
241242

242-
it('should return false when suite has no child of a given name', () => {
243-
assert.isFalse(suite.hasChildNamed('has no'));
243+
describe('should return false when', () => {
244+
it('suite has no child with given name', () => {
245+
assert.isFalse(suite.hasChild('has no', []));
246+
});
247+
248+
it('has child with given name and not intersected browser set', () => {
249+
assert.isFalse(suite.hasChild('has no', ['bad-bro']));
250+
});
244251
});
245252
});
246253

test/unit/tests-api/index.js

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,31 @@ describe('tests-api', function() {
4747
assert.equal(this.suite.children[0].children[0].name, 'child');
4848
});
4949

50-
it('should not allow create two child suites of the same name', function() {
51-
assert.throws(function() {
52-
gemini.suite('name', function() {
53-
gemini.suite('child', function() {});
54-
gemini.suite('child', function() {});
50+
describe('child suites of the same name', () => {
51+
beforeEach(function() {
52+
gemini = testsAPI(this.suite, ['browser1']);
53+
});
54+
55+
it('should not allow to create with intersect browsers', function() {
56+
assert.throws(() => {
57+
gemini.suite('name', () => {
58+
gemini.suite('child', () => {});
59+
gemini.suite('child', () => {});
60+
});
61+
});
62+
});
63+
64+
it('should allow to create with not intersecting browser sets', function() {
65+
gemini.suite('name', () => {
66+
gemini.suite('child', () => {});
67+
});
68+
69+
gemini = testsAPI(this.suite, ['browser2']);
70+
71+
assert.doesNotThrow(() => {
72+
gemini.suite('name', () => {
73+
gemini.suite('child', () => {});
74+
});
5575
});
5676
});
5777
});

0 commit comments

Comments
 (0)