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

Commit

Permalink
fix: enable correct suite through suite collection api
Browse files Browse the repository at this point in the history
If there are 2 suites with equal names suiteCollection.enable will enable first suite
  • Loading branch information
sipayRT committed Mar 27, 2017
1 parent 3377412 commit 60c1147
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/suite-collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,14 @@ module.exports = class SuiteCollection {
}

_disableEntity(obj, browser) {
this._originalBrowsers[obj.fullName] = obj.browsers;
this._originalBrowsers[obj.fullName + obj.file] = obj.browsers;
obj.browsers = browser ? _.without(obj.browsers, browser) : [];
}

_enableEntity(obj, browser) {
if (!browser && this._originalBrowsers[obj.fullName]) {
obj.browsers = _.union(obj.browsers, this._originalBrowsers[obj.fullName]);
const suiteKey = obj.fullName + obj.file;
if (!browser && this._originalBrowsers[suiteKey]) {
obj.browsers = _.union(obj.browsers, this._originalBrowsers[suiteKey]);
}

if (browser) {
Expand Down
21 changes: 21 additions & 0 deletions test/unit/suite-collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const proxyquire = require('proxyquire');
const mkTree = require('../util').makeSuiteTree;
const mkSuite = require('../util').makeSuiteStub;

describe('suite-collection', () => {
const sandbox = sinon.sandbox.create();
Expand Down Expand Up @@ -385,6 +386,26 @@ describe('suite-collection', () => {
assert.deepEqual(tree.child.browsers, ['b1', 'b2']);
});

it('should enable only current suite if there are the same suites exists in the tree', () => {
const suite1 = mkSuite({
name: 'suite',
browsers: ['b1', 'b2'],
file: 'some/path.js'
});
const suite2 = mkSuite({
name: 'suite',
browsers: ['b3', 'b4'],
file: 'another/path.js'
});

new SuiteCollection([suite1, suite2])
.disableAll()
.enable(suite1);

assert.deepEqual(suite1.browsers, ['b1', 'b2']);
assert.deepEqual(suite2.browsers, []);
});

it('should fail on attempt to enable unknown suite', () => {
const tree = mkTree({
suite: []
Expand Down
1 change: 1 addition & 0 deletions test/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ function makeSuiteStub(opts) {
suite.addState(state);
});
suite.url = opts.url;
suite.file = opts.file;

return suite;
}
Expand Down

0 comments on commit 60c1147

Please sign in to comment.