This repository has been archived by the owner on Sep 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #867 from gemini-testing/skip_in_notIn
Add skip.in, skip.notIn, only.in and only.notIn methods to tests API
- Loading branch information
Showing
10 changed files
with
932 additions
and
406 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
'use strict'; | ||
|
||
const _ = require('lodash'); | ||
|
||
module.exports = class Skip { | ||
constructor(suite) { | ||
this._suite = suite; | ||
} | ||
|
||
_validateArgs(browsers) { | ||
if (!this._isArrayOfStringsAndRegExps(browsers)) { | ||
throw new TypeError('Browsers must be an array with strings and RegExp objects'); | ||
} | ||
} | ||
|
||
_shouldSkip(browsers, {negate} = {}) { | ||
const fn = negate ? _.every : _.some; | ||
return (browserId) => fn(this._mkBrowsersMatcher(browsers, {negate}), (matcher) => matcher(browserId)); | ||
} | ||
|
||
_mkBrowsersMatcher(browsers, {negate}) { | ||
const mkMatcher = (browser) => _.isRegExp(browser) ? browser.test.bind(browser) : _.isEqual.bind(null, browser); | ||
|
||
return browsers.map((browser) => negate ? _.negate(mkMatcher(browser)) : mkMatcher(browser)); | ||
} | ||
|
||
_isArrayOfStringsAndRegExps(arr) { | ||
return _.isArray(arr) && _.every(arr, (item) => _.isString(item) || _.isRegExp(item)); | ||
} | ||
|
||
in() { | ||
return new Error('Not implemented'); | ||
} | ||
|
||
notIn() { | ||
return new Error('Not implemented'); | ||
} | ||
|
||
buildAPI() { | ||
return new Error('Not implemented'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
'use strict'; | ||
|
||
const Skip = require('./index'); | ||
const _ = require('lodash'); | ||
|
||
module.exports = class OnlyBuilder extends Skip { | ||
static create(suite) { | ||
return new OnlyBuilder(suite); | ||
} | ||
|
||
constructor(suite) { | ||
super(suite); | ||
} | ||
|
||
in(...browsers) { | ||
return this._process(browsers); | ||
} | ||
|
||
notIn(...browsers) { | ||
return this._process(browsers, {negate: true}); | ||
} | ||
|
||
_process(browsers, opts = {negate: false}) { | ||
browsers = normalizeArgs(browsers); | ||
this._validateArgs(browsers); | ||
|
||
this._suite.browsers = this._suite.browsers.filter(this._shouldSkip(browsers, opts)); | ||
return this; | ||
} | ||
|
||
buildAPI(context) { | ||
const only = { | ||
in: (...browsers) => { | ||
this.in(...browsers); | ||
return context; | ||
}, | ||
notIn: (...browsers) => { | ||
this.notIn(...browsers); | ||
return context; | ||
} | ||
}; | ||
const browsers = (...browsers) => { | ||
this.in(...browsers); | ||
return context; | ||
}; | ||
|
||
return {only, browsers}; | ||
} | ||
}; | ||
|
||
function normalizeArgs(browsers) { | ||
if (browsers.length === 0) { | ||
return; | ||
} | ||
if (browsers.length === 1 && _.isArray(browsers[0])) { | ||
return browsers[0]; | ||
} | ||
return browsers; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
'use strict'; | ||
|
||
const Skip = require('./index'); | ||
|
||
module.exports = class SkipBuilder extends Skip { | ||
static create(suite) { | ||
return new SkipBuilder(suite); | ||
} | ||
|
||
constructor(suite) { | ||
super(suite); | ||
} | ||
|
||
in(browsers, comment) { | ||
return this._process(browsers, comment); | ||
} | ||
|
||
notIn(browsers, comment) { | ||
return this._process(browsers, comment, {negate: true}); | ||
} | ||
|
||
_process(browsers, comment, opts = {negate: false}) { | ||
browsers = [].concat(browsers); | ||
this._validateArgs(browsers); | ||
|
||
this._suite.skip({matches: this._shouldSkip(browsers, opts), comment}); | ||
return this; | ||
} | ||
|
||
buildAPI(context) { | ||
const skip = (browsers, comment) => { | ||
if (!browsers) { | ||
browsers = /.*/; | ||
} | ||
|
||
this.in(browsers, comment); | ||
return context; | ||
}; | ||
|
||
skip.in = (browsers, comment) => { | ||
this.in(browsers, comment); | ||
return context; | ||
}; | ||
|
||
skip.notIn = (browsers, comment) => { | ||
this.notIn(browsers, comment); | ||
return context; | ||
}; | ||
|
||
return {skip}; | ||
} | ||
}; |
Oops, something went wrong.