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

Commit

Permalink
feat: add method 'shouldSkip(browserId)' to suite instance
Browse files Browse the repository at this point in the history
  • Loading branch information
eGavr committed Jun 30, 2017
1 parent 7608170 commit bad551c
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 68 deletions.
3 changes: 1 addition & 2 deletions lib/runner/suite-runner/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions lib/state.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

const _ = require('lodash');
const suiteUtil = require('./suite-util');

module.exports = class State {
constructor(suite, name) {
Expand All @@ -22,7 +21,7 @@ module.exports = class State {
}

shouldSkip(browserId) {
return suiteUtil.shouldSkip(this.suite, browserId);
return this.suite.shouldSkip(browserId);
}

get fullName() {
Expand Down
18 changes: 0 additions & 18 deletions lib/suite-util.js

This file was deleted.

15 changes: 15 additions & 0 deletions lib/suite.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
10 changes: 6 additions & 4 deletions test/unit/runner/suite-runner/index.js
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down Expand Up @@ -51,20 +50,23 @@ 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);
assert.notCalled(InsistentRunner);
});

it('should return SkippedSuiteRunner for skipped suite', () => {
const runner = makeSuiteRunner(makeSuite(), {});
const runner = makeSuiteRunner(suite, {});

assert.instanceOf(runner, SkippedRunner);
});
Expand Down
8 changes: 3 additions & 5 deletions test/unit/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
});
});

Expand Down
37 changes: 0 additions & 37 deletions test/unit/suite-util.test.js

This file was deleted.

45 changes: 45 additions & 0 deletions test/unit/suite.test.js β†’ test/unit/suite.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit bad551c

Please sign in to comment.