diff --git a/lib/runner/suite-runner/index.js b/lib/runner/suite-runner/index.js index 1131b3d00..81dbaffbc 100644 --- a/lib/runner/suite-runner/index.js +++ b/lib/runner/suite-runner/index.js @@ -3,12 +3,11 @@ const InsistentSuiteRunner = require('./insistent-suite-runner'); const SkippedSuiteRunner = require('./skipped-suite-runner'); const StatelessSuiteRunner = require('./stateless-suite-runner'); -const suiteUtil = require('../../suite-util'); exports.create = function(suite, browserAgent, config) { if (!suite.hasStates) { return new StatelessSuiteRunner(suite, browserAgent); - } else if (suiteUtil.shouldSkip(suite, browserAgent.browserId)) { + } else if (suite.shouldSkip(browserAgent.browserId)) { return new SkippedSuiteRunner(suite, browserAgent); } else { return new InsistentSuiteRunner(suite, browserAgent, config); diff --git a/lib/state.js b/lib/state.js index d584f5817..54e01c1c9 100644 --- a/lib/state.js +++ b/lib/state.js @@ -1,7 +1,6 @@ 'use strict'; const _ = require('lodash'); -const suiteUtil = require('./suite-util'); module.exports = class State { constructor(suite, name) { @@ -22,7 +21,7 @@ module.exports = class State { } shouldSkip(browserId) { - return suiteUtil.shouldSkip(this.suite, browserId); + return this.suite.shouldSkip(browserId); } get fullName() { diff --git a/lib/suite-util.js b/lib/suite-util.js deleted file mode 100644 index 9d26b7456..000000000 --- a/lib/suite-util.js +++ /dev/null @@ -1,18 +0,0 @@ -'use strict'; - -exports.shouldSkip = function(suite, browserId) { - var skipped = suite.skipped; - - if (typeof skipped === 'boolean') { - return skipped; - } - - return skipped.some(function(browserSkipMatcher) { - if (browserSkipMatcher.matches(browserId)) { - suite.skipComment = browserSkipMatcher.comment; - return true; - } else { - return false; - } - }); -}; diff --git a/lib/suite.js b/lib/suite.js index 200b27581..d7ce13cd3 100644 --- a/lib/suite.js +++ b/lib/suite.js @@ -65,6 +65,21 @@ module.exports = class Suite { } } + shouldSkip(browserId) { + if (_.isBoolean(this.skipped)) { + return this.skipped; + } + + return this.skipped.some((browserSkipMatcher) => { + if (browserSkipMatcher.matches(browserId)) { + this.skipComment = browserSkipMatcher.comment; + return true; + } + + return false; + }); + } + clone() { const clonedSuite = Suite.create(this.name, this.parent); diff --git a/test/unit/runner/suite-runner/index.js b/test/unit/runner/suite-runner/index.js index 146201d9c..8bfcc208f 100644 --- a/test/unit/runner/suite-runner/index.js +++ b/test/unit/runner/suite-runner/index.js @@ -1,7 +1,6 @@ 'use strict'; const proxyquire = require('proxyquire'); -const suiteUtil = require('lib/suite-util'); const util = require('../../../util'); describe('runner/suite-runner/create', () => { @@ -51,12 +50,15 @@ describe('runner/suite-runner/create', () => { }); describe('SkippedSuiteRunner', () => { + let suite; + beforeEach(() => { - sandbox.stub(suiteUtil, 'shouldSkip').returns(true); + suite = makeSuite(); + suite.shouldSkip = sinon.stub().returns(true); }); it('should create SkippedSuiteRunner', () => { - makeSuiteRunner(makeSuite()); + makeSuiteRunner(suite); assert.calledOnce(SkippedRunner); assert.notCalled(StatelessRunner); @@ -64,7 +66,7 @@ describe('runner/suite-runner/create', () => { }); it('should return SkippedSuiteRunner for skipped suite', () => { - const runner = makeSuiteRunner(makeSuite(), {}); + const runner = makeSuiteRunner(suite, {}); assert.instanceOf(runner, SkippedRunner); }); diff --git a/test/unit/state.js b/test/unit/state.js index b31a7717f..af0bb088d 100644 --- a/test/unit/state.js +++ b/test/unit/state.js @@ -2,18 +2,16 @@ const State = require('lib/state'); const util = require('../util'); -const suiteUtil = require('lib/suite-util'); describe('state methods', () => { describe('shouldSkip', () => { it('should check if state will be skipped', () => { const suite = util.makeSuiteStub(); + suite.shouldSkip = sinon.stub(); + suite.shouldSkip.withArgs('browserId').returns(true); const state = new State(suite); - sinon.stub(suiteUtil, 'shouldSkip').returns(true); - state.shouldSkip('browserId'); - - assert.calledWithMatch(suiteUtil.shouldSkip, suite, 'browserId'); + assert.isTrue(state.shouldSkip('browserId')); }); }); diff --git a/test/unit/suite-util.test.js b/test/unit/suite-util.test.js deleted file mode 100644 index eb1240651..000000000 --- a/test/unit/suite-util.test.js +++ /dev/null @@ -1,37 +0,0 @@ -'use strict'; -var _ = require('lodash'), - suiteUtil = require('lib/suite-util'), - shouldSkip = suiteUtil.shouldSkip; - -describe('suite-util', function() { - describe('shouldSkip()', function() { - it('should not skip any browser if skipped=false', function() { - assert.isFalse(shouldSkip({skipped: false}, 'browser')); - }); - - it('should skip any browser if skipped=true', function() { - assert.isTrue(shouldSkip({skipped: true}, 'browser')); - }); - - it('should skip browser if its id matches skip list', function() { - var matcher = { - matches: _.isEqual.bind(null, 'some-browser') - }; - - assert.isTrue(shouldSkip( - {skipped: [matcher]}, - 'some-browser' - )); - }); - - it('should not skip the browser if its id does not match skip list', function() { - var matcher = { - matches: _.isEqual.bind(null, 'some-browser') - }; - assert.isFalse(shouldSkip( - {skipped: [matcher]}, - 'another-browser' - )); - }); - }); -}); diff --git a/test/unit/suite.test.js b/test/unit/suite.js similarity index 87% rename from test/unit/suite.test.js rename to test/unit/suite.js index 4f13ecfdb..b0a969833 100644 --- a/test/unit/suite.test.js +++ b/test/unit/suite.js @@ -226,6 +226,51 @@ describe('suite', () => { }); }); + 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 any browser if a suite is skipped', () => { + suite.skip(); + + assert.isTrue(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;