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

Commit bad551c

Browse files
committed
feat: add method 'shouldSkip(browserId)' to suite instance
1 parent 7608170 commit bad551c

File tree

8 files changed

+71
-68
lines changed

8 files changed

+71
-68
lines changed

lib/runner/suite-runner/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
const InsistentSuiteRunner = require('./insistent-suite-runner');
44
const SkippedSuiteRunner = require('./skipped-suite-runner');
55
const StatelessSuiteRunner = require('./stateless-suite-runner');
6-
const suiteUtil = require('../../suite-util');
76

87
exports.create = function(suite, browserAgent, config) {
98
if (!suite.hasStates) {
109
return new StatelessSuiteRunner(suite, browserAgent);
11-
} else if (suiteUtil.shouldSkip(suite, browserAgent.browserId)) {
10+
} else if (suite.shouldSkip(browserAgent.browserId)) {
1211
return new SkippedSuiteRunner(suite, browserAgent);
1312
} else {
1413
return new InsistentSuiteRunner(suite, browserAgent, config);

lib/state.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
22

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

65
module.exports = class State {
76
constructor(suite, name) {
@@ -22,7 +21,7 @@ module.exports = class State {
2221
}
2322

2423
shouldSkip(browserId) {
25-
return suiteUtil.shouldSkip(this.suite, browserId);
24+
return this.suite.shouldSkip(browserId);
2625
}
2726

2827
get fullName() {

lib/suite-util.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

lib/suite.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,21 @@ module.exports = class Suite {
6565
}
6666
}
6767

68+
shouldSkip(browserId) {
69+
if (_.isBoolean(this.skipped)) {
70+
return this.skipped;
71+
}
72+
73+
return this.skipped.some((browserSkipMatcher) => {
74+
if (browserSkipMatcher.matches(browserId)) {
75+
this.skipComment = browserSkipMatcher.comment;
76+
return true;
77+
}
78+
79+
return false;
80+
});
81+
}
82+
6883
clone() {
6984
const clonedSuite = Suite.create(this.name, this.parent);
7085

test/unit/runner/suite-runner/index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
22

33
const proxyquire = require('proxyquire');
4-
const suiteUtil = require('lib/suite-util');
54
const util = require('../../../util');
65

76
describe('runner/suite-runner/create', () => {
@@ -51,20 +50,23 @@ describe('runner/suite-runner/create', () => {
5150
});
5251

5352
describe('SkippedSuiteRunner', () => {
53+
let suite;
54+
5455
beforeEach(() => {
55-
sandbox.stub(suiteUtil, 'shouldSkip').returns(true);
56+
suite = makeSuite();
57+
suite.shouldSkip = sinon.stub().returns(true);
5658
});
5759

5860
it('should create SkippedSuiteRunner', () => {
59-
makeSuiteRunner(makeSuite());
61+
makeSuiteRunner(suite);
6062

6163
assert.calledOnce(SkippedRunner);
6264
assert.notCalled(StatelessRunner);
6365
assert.notCalled(InsistentRunner);
6466
});
6567

6668
it('should return SkippedSuiteRunner for skipped suite', () => {
67-
const runner = makeSuiteRunner(makeSuite(), {});
69+
const runner = makeSuiteRunner(suite, {});
6870

6971
assert.instanceOf(runner, SkippedRunner);
7072
});

test/unit/state.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,16 @@
22

33
const State = require('lib/state');
44
const util = require('../util');
5-
const suiteUtil = require('lib/suite-util');
65

76
describe('state methods', () => {
87
describe('shouldSkip', () => {
98
it('should check if state will be skipped', () => {
109
const suite = util.makeSuiteStub();
10+
suite.shouldSkip = sinon.stub();
11+
suite.shouldSkip.withArgs('browserId').returns(true);
1112
const state = new State(suite);
12-
sinon.stub(suiteUtil, 'shouldSkip').returns(true);
1313

14-
state.shouldSkip('browserId');
15-
16-
assert.calledWithMatch(suiteUtil.shouldSkip, suite, 'browserId');
14+
assert.isTrue(state.shouldSkip('browserId'));
1715
});
1816
});
1917

test/unit/suite-util.test.js

Lines changed: 0 additions & 37 deletions
This file was deleted.

test/unit/suite.test.js renamed to test/unit/suite.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,51 @@ describe('suite', () => {
226226
});
227227
});
228228

229+
describe('shouldSkip', () => {
230+
let suite;
231+
232+
const createBrowserSkipMatcher = (browserId) => {
233+
const matcher = {matches: sinon.stub()};
234+
matcher.matches.withArgs(browserId).returns(true);
235+
236+
return matcher;
237+
};
238+
239+
beforeEach(() => suite = createSuite('suite'));
240+
241+
it('should be "false" for any browser if a suite is not skipped', function() {
242+
assert.isFalse(suite.shouldSkip('browser'));
243+
});
244+
245+
it('should be "true" for any browser if a suite is skipped', () => {
246+
suite.skip();
247+
248+
assert.isTrue(suite.shouldSkip('browser'));
249+
});
250+
251+
it('should be "true" for a browser if a suite is skipped in it', () => {
252+
suite.skip(createBrowserSkipMatcher('1st-skipped-bro'));
253+
suite.skip(createBrowserSkipMatcher('2nd-skipped-bro'));
254+
255+
assert.isTrue(suite.shouldSkip('1st-skipped-bro'));
256+
assert.isTrue(suite.shouldSkip('2nd-skipped-bro'));
257+
});
258+
259+
it('should set a skip comment if a suite is skipped in a browser', () => {
260+
suite.skip({matches: sinon.stub().withArgs('skipped-bro').returns(true), comment: 'skip-comment'});
261+
262+
suite.shouldSkip('skipped-bro');
263+
assert.equal(suite.skipComment, 'skip-comment');
264+
});
265+
266+
it('should be "false" for a browser if a suite is not skipped in it', () => {
267+
suite.skip(createBrowserSkipMatcher('1st-skipped-bro'));
268+
suite.skip(createBrowserSkipMatcher('2st-skipped-bro'));
269+
270+
assert.isFalse(suite.shouldSkip('some-bro'));
271+
});
272+
});
273+
229274
describe('hasChild', () => {
230275
let suite;
231276

0 commit comments

Comments
 (0)