browserstack-capabilities
Advanced tools
Comparing version 0.3.0 to 0.4.0
70
index.js
var _ = require("lodash"); | ||
var browsers = require("./lib/browsers.json"); | ||
var parser = require("./lib/parse"); | ||
var request = require("sync-request"); | ||
var browsers; | ||
function createRulesProduct(rules) { | ||
@@ -23,3 +25,3 @@ var filters = [rules]; | ||
} | ||
}) | ||
}); | ||
@@ -33,25 +35,53 @@ return filters; | ||
}, browsers); | ||
}; | ||
} | ||
module.exports = { | ||
create: function (includes, excludes) { | ||
var rules; | ||
var browserMatches = _.clone(browsers); | ||
module.exports = function(username, key) { | ||
return { | ||
create: function (includes, excludes) { | ||
if (includes) { | ||
rules = createRulesProduct(includes); | ||
if (!browsers) { | ||
var auth = 'Basic ' + new Buffer(username + ':' + key).toString('base64'); | ||
browserMatches = _.flatten(_.map(rules, function(rule) { | ||
return _.filter(browserMatches, rule); | ||
})); | ||
var res = request('GET', 'https://api.browserstack.com/4/browsers?flat=true', { | ||
'headers': { | ||
'Authorization': auth | ||
} | ||
}); | ||
} | ||
if (excludes) { | ||
rules = createRulesProduct(excludes); | ||
browserMatches = nestedExclude(browserMatches, rules); | ||
} | ||
browsers = JSON.parse(res.getBody()); | ||
} | ||
return browserMatches; | ||
}, | ||
parse: parser | ||
var rules; | ||
var browserMatches = _.clone(browsers); | ||
if (includes) { | ||
if (_.isArray(includes)) { | ||
rules = _.flatten(_.map(includes, createRulesProduct)); | ||
} else { | ||
rules = createRulesProduct(includes); | ||
} | ||
browserMatches = _.flatten(_.map(rules, function (rule) { | ||
if (rule.browser_version === 'latest') { | ||
var latest_rule = _.clone(rule); | ||
delete latest_rule.browser_version; | ||
return [_.last(_.sortBy(_.filter(browserMatches, latest_rule), ['browser_version']))]; | ||
} | ||
return _.filter(browserMatches, rule); | ||
})); | ||
} | ||
if (excludes) { | ||
if (_.isArray(excludes)) { | ||
rules = _.flatten(_.map(excludes, createRulesProduct)); | ||
} else { | ||
rules = createRulesProduct(excludes); | ||
} | ||
browserMatches = nestedExclude(browserMatches, rules); | ||
} | ||
return browserMatches; | ||
}, | ||
parse: parser | ||
}; | ||
}; |
@@ -15,3 +15,3 @@ var aliases = { | ||
"mac": "MAC" | ||
} | ||
}; | ||
@@ -33,2 +33,2 @@ module.exports = { | ||
} | ||
} | ||
}; |
@@ -21,3 +21,3 @@ var aliases = require("./aliases"); | ||
function parseCapabality(shorthand) { | ||
function parseCapability(shorthand) { | ||
// split by browser/os | ||
@@ -40,5 +40,5 @@ var props = splitProperties("@", shorthand); | ||
if (capabilities.constructor === Array) { | ||
return capabilities.map(parseCapabality); | ||
return capabilities.map(parseCapability); | ||
} else { | ||
return parseCapabality(capabilities); | ||
return parseCapability(capabilities); | ||
} | ||
@@ -45,0 +45,0 @@ } |
{ | ||
"name": "browserstack-capabilities", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "An easier way to generate multiple capabilities based on JSON filters.", | ||
@@ -29,3 +29,4 @@ "main": "index.js", | ||
"dependencies": { | ||
"lodash": "^3.10.1" | ||
"lodash": "^3.10.1", | ||
"sync-request": "^4.0.1" | ||
}, | ||
@@ -32,0 +33,0 @@ "devDependencies": { |
121
README.md
@@ -22,3 +22,5 @@ # browserstack-capabilities | ||
```js | ||
var bsCapabilities = require("browserstack-capabilities"); | ||
var username = "<browserstack username>"; | ||
var key = "<browserstack key>"; | ||
var bsCapabilities = require("browserstack-capabilities")(username, key); | ||
@@ -52,3 +54,5 @@ var capabilities = bsCapabilities.create({ | ||
```js | ||
var bsCapabilities = require("browserstack-capabilities"); | ||
var username = "<browserstack username>"; | ||
var key = "<browserstack key>"; | ||
var bsCapabilities = require("browserstack-capabilities")(username, key); | ||
@@ -95,3 +99,5 @@ var capabilities = bsCapabilities.create({ | ||
```js | ||
var bsCapabilities = require("browserstack-capabilities"); | ||
var username = "<browserstack username>"; | ||
var key = "<browserstack key>"; | ||
var bsCapabilities = require("browserstack-capabilities")(username, key); | ||
@@ -147,3 +153,5 @@ var capabilities = bsCapabilities.create({ | ||
```js | ||
var bsCapabilities = require("browserstack-capabilities"); | ||
var username = "<browserstack username>"; | ||
var key = "<browserstack key>"; | ||
var bsCapabilities = require("browserstack-capabilities")(username, key); | ||
@@ -188,7 +196,57 @@ var capabilities = bsCapabilities.create({ | ||
It's recommended that you create combinations for different browsers separately, due to the singular nature of the "version" property. Once created, you can concat the combinations: | ||
You can create combinations for multiple browsers at the same time by passing an array of filters into the create function: | ||
```js | ||
var bsCapabilities = require("browserstack-capabilities"); | ||
var username = "<browserstack username>"; | ||
var key = "<browserstack key>"; | ||
var bsCapabilities = require("browserstack-capabilities")(username, key); | ||
var capabilities = bsCapabilities.create([{ | ||
browser: "firefox", | ||
browser_version: "42.0", | ||
os: "Windows", | ||
os_version: ["10", "8.1"] | ||
},{ | ||
browser: "chrome", | ||
browser_version: "46.0", | ||
os: "Windows", | ||
os_version: ["10", "8.1"] | ||
}]); | ||
console.log(capabilities); | ||
// outputs: | ||
// [{ | ||
// device: null, | ||
// os: 'Windows', | ||
// browser: 'firefox', | ||
// os_version: '10', | ||
// browser_version: '42.0' | ||
// }, { | ||
// device: null, | ||
// os: 'Windows', | ||
// browser: 'firefox', | ||
// os_version: '8.1', | ||
// browser_version: '42.0' | ||
// }, { | ||
// device: null, | ||
// os: 'Windows', | ||
// browser: 'chrome', | ||
// os_version: '10', | ||
// browser_version: '46.0' | ||
// }, { | ||
// device: null, | ||
// os: 'Windows', | ||
// browser: 'chrome', | ||
// os_version: '8.1', | ||
// browser_version: '46.0' | ||
// }] | ||
``` | ||
If you prefer, you can create combinations for different browsers separately. Once created, you can concat the combinations: | ||
```js | ||
var username = "<browserstack username>"; | ||
var key = "<browserstack key>"; | ||
var bsCapabilities = require("browserstack-capabilities")(username, key); | ||
var ff = bsCapabilities.create({ | ||
@@ -237,2 +295,53 @@ browser: "firefox", | ||
// }] | ||
``` | ||
### Latest browser | ||
You can select the latest browser for an OS by passing in the string "latest" as the browser version: | ||
```js | ||
var username = "<browserstack username>"; | ||
var key = "<browserstack key>"; | ||
var bsCapabilities = require("browserstack-capabilities")(username, key); | ||
var capabilities = bsCapabilities.create({ | ||
browser: "ie", | ||
browser_version: ["latest"], | ||
os: "Windows", | ||
os_version: ["XP", "7", "8", "8.1", "10"] | ||
}); | ||
console.log(capabilities); | ||
// outputs: | ||
// [{ | ||
// os: 'Windows', | ||
// os_version: 'XP', | ||
// browser: 'ie', | ||
// device: null, | ||
// browser_version: '8.0' | ||
// }, { | ||
// os: 'Windows', | ||
// os_version: '7', | ||
// browser: 'ie', | ||
// device: null, | ||
// browser_version: '11.0' | ||
// }, { | ||
// os: 'Windows', | ||
// os_version: '8', | ||
// browser: 'ie', | ||
// device: null, | ||
// browser_version: '10.0 Metro' | ||
// }, { | ||
// os: 'Windows', | ||
// os_version: '8.1', | ||
// browser: 'ie', | ||
// device: null, | ||
// browser_version: '11.0 Metro' | ||
// }, { | ||
// os: 'Windows', | ||
// os_version: '10', | ||
// browser: 'ie', | ||
// device: null, | ||
// browser_version: '11.0' | ||
// }] | ||
``` |
var expect = require("chai").expect; | ||
var bsCapabilities = require("../index.js"); | ||
var bsCapabilities = require("../index.js")(process.env.BROWSERSTACK_USERNAME, process.env.BROWSERSTACK_KEY); | ||
describe("combo generation", function() { | ||
describe("simple combinations", function() { | ||
it("should take an include", function() { | ||
describe("simple combinations", function () { | ||
it("should take an include", function () { | ||
var generatedCombo = bsCapabilities.create({ | ||
@@ -13,14 +13,14 @@ browser: "ie", | ||
var expectedCombos = [{ | ||
device: null, | ||
os: 'Windows', | ||
browser: 'ie', | ||
os_version: '8', | ||
browser_version: '10.0' | ||
}, { | ||
device: null, | ||
os: 'Windows', | ||
browser: 'ie', | ||
os_version: '7', | ||
browser_version: '10.0' | ||
}]; | ||
device: null, | ||
os: 'Windows', | ||
browser: 'ie', | ||
os_version: '7', | ||
browser_version: '10.0' | ||
}, { | ||
device: null, | ||
os: 'Windows', | ||
browser: 'ie', | ||
os_version: '8', | ||
browser_version: '10.0' | ||
}]; | ||
@@ -30,20 +30,30 @@ expect(generatedCombo).to.deep.equal(expectedCombos); | ||
it.skip("should take an exclude", function() { | ||
var generatedCombo = bsCapabilities.create(null, { | ||
browser: "ie" | ||
it("should take an exclude", function () { | ||
var generatedCombo = bsCapabilities.create({ | ||
browser: "ie", | ||
os: "Windows", | ||
os_version: "7" | ||
}, { | ||
browser_version: "8.0" | ||
}); | ||
var expectedCombos = [{ | ||
device: null, | ||
os: 'Windows', | ||
browser: 'ie', | ||
os_version: '8', | ||
browser_version: '10.0' | ||
}, { | ||
device: null, | ||
os: 'Windows', | ||
browser: 'ie', | ||
os_version: '7', | ||
browser_version: '10.0' | ||
}]; | ||
device: null, | ||
os: 'Windows', | ||
browser: 'ie', | ||
os_version: '7', | ||
browser_version: '9.0' | ||
}, { | ||
device: null, | ||
os: 'Windows', | ||
browser: 'ie', | ||
os_version: '7', | ||
browser_version: '10.0' | ||
}, { | ||
device: null, | ||
os: 'Windows', | ||
browser: 'ie', | ||
os_version: '7', | ||
browser_version: '11.0' | ||
}]; | ||
@@ -53,3 +63,3 @@ expect(generatedCombo).to.deep.equal(expectedCombos); | ||
it("should take an include and an exclude", function() { | ||
it("should take an include and an exclude", function () { | ||
var generatedCombo = bsCapabilities.create({ | ||
@@ -75,6 +85,79 @@ browser: "ie", | ||
describe("nested combinations", function() { | ||
it("should take a nested include", function() { | ||
describe("multiple includes and excludes", function() { | ||
it("should take multiple includes", function () { | ||
var generatedCombo = bsCapabilities.create([{ | ||
browser: "firefox", | ||
browser_version: "42.0", | ||
os: "Windows", | ||
os_version: ["10", "8.1"] | ||
},{ | ||
browser: "chrome", | ||
browser_version: "46.0", | ||
os: "Windows", | ||
os_version: ["10", "8.1"] | ||
}]); | ||
var expectedCombos = [{ | ||
device: null, | ||
os: 'Windows', | ||
browser: 'firefox', | ||
os_version: '10', | ||
browser_version: '42.0' | ||
}, { | ||
device: null, | ||
os: 'Windows', | ||
browser: 'firefox', | ||
os_version: '8.1', | ||
browser_version: '42.0' | ||
}, { | ||
device: null, | ||
os: 'Windows', | ||
browser: 'chrome', | ||
os_version: '10', | ||
browser_version: '46.0' | ||
}, { | ||
device: null, | ||
os: 'Windows', | ||
browser: 'chrome', | ||
os_version: '8.1', | ||
browser_version: '46.0' | ||
}]; | ||
expect(generatedCombo).to.deep.equal(expectedCombos); | ||
}); | ||
it("should take multiple excludes", function () { | ||
var generatedCombo = bsCapabilities.create({ | ||
browser: "ie", | ||
os: "Windows", | ||
os_version: "7" | ||
}, [{ | ||
browser_version: "8.0" | ||
}, { | ||
browser_version: "9.0" | ||
}]); | ||
var expectedCombos = [{ | ||
device: null, | ||
os: 'Windows', | ||
browser: 'ie', | ||
os_version: '7', | ||
browser_version: '10.0' | ||
}, { | ||
device: null, | ||
os: 'Windows', | ||
browser: 'ie', | ||
os_version: '7', | ||
browser_version: '11.0' | ||
}]; | ||
expect(generatedCombo).to.deep.equal(expectedCombos); | ||
}); | ||
}); | ||
describe("nested combinations", function () { | ||
it("should take a nested include", function () { | ||
var generatedCombo = bsCapabilities.create({ | ||
browser: "ie", | ||
browser_version: ["11.0", "10.0"], | ||
@@ -90,18 +173,25 @@ os_version: ["10", "8.1", "7"] | ||
os_version: '10', | ||
browser_version: '11.0'}, | ||
{ device: null, | ||
browser_version: '11.0' | ||
}, | ||
{ | ||
device: null, | ||
os: 'Windows', | ||
browser: 'ie', | ||
os_version: '8.1', | ||
browser_version: '11.0' }, | ||
{ device: null, | ||
browser_version: '11.0' | ||
}, | ||
{ | ||
device: null, | ||
os: 'Windows', | ||
browser: 'ie', | ||
os_version: '7', | ||
browser_version: '11.0' }, | ||
{ device: null, | ||
browser_version: '11.0' | ||
}, | ||
{ | ||
device: null, | ||
os: 'Windows', | ||
browser: 'ie', | ||
os_version: '7', | ||
browser_version: '10.0' }]; | ||
browser_version: '10.0' | ||
}]; | ||
@@ -111,3 +201,3 @@ expect(generatedCombo).to.deep.equal(expectedCombos); | ||
it("should take a nested include and simple exclude", function() { | ||
it("should take a nested include and simple exclude", function () { | ||
var generatedCombo = bsCapabilities.create({ | ||
@@ -128,13 +218,18 @@ browser: "ie", | ||
os_version: '10', | ||
browser_version: '11.0'}, | ||
{ device: null, | ||
browser_version: '11.0' | ||
}, | ||
{ | ||
device: null, | ||
os: 'Windows', | ||
browser: 'ie', | ||
os_version: '8.1', | ||
browser_version: '11.0' }, | ||
{ device: null, | ||
browser_version: '11.0' | ||
}, | ||
{ | ||
device: null, | ||
os: 'Windows', | ||
browser: 'ie', | ||
os_version: '7', | ||
browser_version: '10.0' }]; | ||
browser_version: '10.0' | ||
}]; | ||
@@ -145,3 +240,3 @@ expect(generatedCombo).to.deep.equal(expectedCombos); | ||
it("should take a simple include and nested exclude", function() { | ||
it("should take a simple include and nested exclude", function () { | ||
var generatedCombo = bsCapabilities.create({ | ||
@@ -161,3 +256,4 @@ browser: "firefox", | ||
os_version: '7', | ||
browser_version: '42.0'}, | ||
browser_version: '42.0' | ||
}, | ||
{ | ||
@@ -167,9 +263,12 @@ device: null, | ||
browser: 'firefox', | ||
os_version: '10', | ||
browser_version: '42.0'}, | ||
{ device: null, | ||
os_version: '8.1', | ||
browser_version: '42.0' | ||
}, | ||
{ | ||
device: null, | ||
os: 'Windows', | ||
browser: 'firefox', | ||
os_version: '8.1', | ||
browser_version: '42.0' }]; | ||
os_version: '10', | ||
browser_version: '42.0' | ||
}]; | ||
@@ -179,3 +278,3 @@ expect(generatedCombo).to.deep.equal(expectedCombos); | ||
it("should take a nested include and nested exclude", function() { | ||
it("should take a nested include and nested exclude", function () { | ||
var generatedCombo = bsCapabilities.create({ | ||
@@ -196,8 +295,11 @@ browser: "ie", | ||
os_version: '10', | ||
browser_version: '11.0'}, | ||
{ device: null, | ||
browser_version: '11.0' | ||
}, | ||
{ | ||
device: null, | ||
os: 'Windows', | ||
browser: 'ie', | ||
os_version: '7', | ||
browser_version: '10.0' }]; | ||
browser_version: '10.0' | ||
}]; | ||
@@ -207,2 +309,53 @@ expect(generatedCombo).to.deep.equal(expectedCombos); | ||
}); | ||
describe("latest combinations", function () { | ||
it("should take a latest browser_version include", function () { | ||
var generatedCombo = bsCapabilities.create({ | ||
browser: "ie", | ||
browser_version: ["latest"], | ||
os: "Windows", | ||
os_version: ["XP", "7", "8", "8.1", "10"] | ||
}); | ||
var expectedCombos = [ | ||
{ | ||
os: 'Windows', | ||
os_version: 'XP', | ||
browser: 'ie', | ||
device: null, | ||
browser_version: '8.0' | ||
}, | ||
{ | ||
os: 'Windows', | ||
os_version: '7', | ||
browser: 'ie', | ||
device: null, | ||
browser_version: '11.0' | ||
}, | ||
{ | ||
os: 'Windows', | ||
os_version: '8', | ||
browser: 'ie', | ||
device: null, | ||
browser_version: '10.0 Metro' | ||
}, | ||
{ | ||
os: 'Windows', | ||
os_version: '8.1', | ||
browser: 'ie', | ||
device: null, | ||
browser_version: '11.0 Metro' | ||
}, | ||
{ | ||
os: 'Windows', | ||
os_version: '10', | ||
browser: 'ie', | ||
device: null, | ||
browser_version: '11.0' | ||
} | ||
]; | ||
expect(generatedCombo).to.deep.equal(expectedCombos); | ||
}); | ||
}); | ||
}); |
var expect = require("chai").expect; | ||
var bsCaps = require("../index.js"); | ||
var bsCaps = require("../index.js")(process.env.BROWSERSTACK_USERNAME, process.env.BROWSERSTACK_KEY); | ||
@@ -4,0 +4,0 @@ describe("bsCaps.parse", function() { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
341
26227
2
562
4
2
+ Addedsync-request@^4.0.1
+ Addedasap@2.0.6(transitive)
+ Addedbuffer-from@1.1.2(transitive)
+ Addedcall-bind-apply-helpers@1.0.1(transitive)
+ Addedcall-bound@1.0.3(transitive)
+ Addedcaseless@0.11.0(transitive)
+ Addedcommand-exists@1.2.9(transitive)
+ Addedconcat-stream@1.6.2(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addeddunder-proto@1.0.1(transitive)
+ Addedes-define-property@1.0.1(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedes-object-atoms@1.0.0(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-intrinsic@1.2.6(transitive)
+ Addedget-port@3.2.0(transitive)
+ Addedgopd@1.2.0(transitive)
+ Addedhas-symbols@1.1.0(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedhttp-basic@2.5.1(transitive)
+ Addedhttp-response-object@1.1.0(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedmath-intrinsics@1.1.0(transitive)
+ Addedobject-inspect@1.13.3(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedpromise@7.3.1(transitive)
+ Addedqs@6.13.1(transitive)
+ Addedreadable-stream@2.3.8(transitive)
+ Addedsafe-buffer@5.1.2(transitive)
+ Addedside-channel@1.1.0(transitive)
+ Addedside-channel-list@1.0.0(transitive)
+ Addedside-channel-map@1.0.1(transitive)
+ Addedside-channel-weakmap@1.0.2(transitive)
+ Addedstring_decoder@1.1.1(transitive)
+ Addedsync-request@4.1.0(transitive)
+ Addedthen-request@2.2.0(transitive)
+ Addedtypedarray@0.0.6(transitive)
+ Addedutil-deprecate@1.0.2(transitive)