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

Commit

Permalink
fix: Implement advanced verification for suites with same names
Browse files Browse the repository at this point in the history
It is necessary to avoid error which occurs on testing suites with same names but on different platforms
  • Loading branch information
tormozz48 committed Nov 9, 2016
1 parent 57a319a commit 2572af5
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 13 deletions.
6 changes: 4 additions & 2 deletions lib/suite.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@ module.exports = class Suite {
return clonedSuite;
}

hasChildNamed(name) {
return _.some(this._children, {name: name});
hasChild(name, browsers) {
return _.some(this.children, (child) => {
return _.isEqual(child.name, name) && !_.isEmpty(_.intersection(child.browsers, browsers));
});
}

hasStateNamed(name) {
Expand Down
2 changes: 1 addition & 1 deletion lib/tests-api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = (suite, browsers) => {
throw new TypeError('Second argument of the gemini.suite must be a function');
}

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

Expand Down
17 changes: 12 additions & 5 deletions test/unit/suite.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,21 +226,28 @@ describe('suite', () => {
});
});

describe('hasChildNamed', () => {
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 of a given name', () => {
assert.isTrue(suite.hasChildNamed('has'));
it('should return true when suite has child with given name and intersected browser set', () => {
assert.isTrue(suite.hasChild('has', ['bro1']));
});

it('should return false when suite has no child of a given name', () => {
assert.isFalse(suite.hasChildNamed('has no'));
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']));
});
});
});

Expand Down
30 changes: 25 additions & 5 deletions test/unit/tests-api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,31 @@ describe('tests-api', function() {
assert.equal(this.suite.children[0].children[0].name, 'child');
});

it('should not allow create two child suites of the same name', function() {
assert.throws(function() {
gemini.suite('name', function() {
gemini.suite('child', function() {});
gemini.suite('child', function() {});
describe('child suites of the same name', () => {
beforeEach(function() {
gemini = testsAPI(this.suite, ['browser1']);
});

it('should not allow to create with intersect browsers', function() {
assert.throws(() => {
gemini.suite('name', () => {
gemini.suite('child', () => {});
gemini.suite('child', () => {});
});
});
});

it('should allow to create with not intersecting browser sets', function() {
gemini.suite('name', () => {
gemini.suite('child', () => {});
});

gemini = testsAPI(this.suite, ['browser2']);

assert.doesNotThrow(() => {
gemini.suite('name', () => {
gemini.suite('child', () => {});
});
});
});
});
Expand Down

0 comments on commit 2572af5

Please sign in to comment.