Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

browserstack-capabilities

Package Overview
Dependencies
Maintainers
2
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

browserstack-capabilities - npm Package Compare versions

Comparing version 0.3.0 to 0.4.0

.editorconfig

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": {

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc