browserstack-capabilities
Advanced tools
Comparing version 0.5.1 to 0.6.0
33
index.js
@@ -63,14 +63,29 @@ var _ = require("lodash"); | ||
browserMatches = _.flatten(_.map(rules, function (rule) { | ||
if (rule.browser_version === 'current') { | ||
if (_.includes(['previous', 'current', 'latest'], rule.browser_version)) { | ||
var current_rule = _.clone(rule); | ||
delete current_rule.browser_version; | ||
// ignore any browser with a version that can't be determined to be a number | ||
var candidates = _.filter(browserMatches, function(browser) { | ||
return isFinite(browser['browser_version']); | ||
var candidates = _.filter(browserMatches, current_rule); | ||
candidates = _.sortBy(candidates, function (browser) { | ||
var version = browser['browser_version']; | ||
if (isFinite(version)) { | ||
return parseFloat(version); | ||
} else { | ||
return Infinity; | ||
} | ||
}); | ||
candidates = _.filter(candidates, current_rule); | ||
var current = _.last(_.sortBy(candidates, function(browser) { | ||
return parseFloat(browser['browser_version']); | ||
})); | ||
return current ? [current] : []; | ||
if (rule.browser_version !== 'latest') { | ||
candidates = _.filter(candidates, function(browser) { | ||
return isFinite(browser['browser_version']); | ||
}); | ||
} | ||
var selected; | ||
switch (rule.browser_version) { | ||
case 'current': | ||
case 'latest': | ||
selected = _.nth(candidates, -1); | ||
break; | ||
case 'previous': | ||
selected = _.nth(candidates, -2); | ||
} | ||
return selected ? [selected] : []; | ||
} | ||
@@ -77,0 +92,0 @@ return _.filter(browserMatches, rule); |
{ | ||
"name": "browserstack-capabilities", | ||
"version": "0.5.1", | ||
"version": "0.6.0", | ||
"description": "An easier way to generate multiple capabilities based on JSON filters.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -399,2 +399,134 @@ var expect = require("chai").expect; | ||
}); | ||
describe("previous combinations", function () { | ||
it("should take a previous browser_version include", function () { | ||
var generatedCombo = bsCapabilities.create({ | ||
browser: "ie", | ||
browser_version: ["previous"], | ||
os: "Windows", | ||
os_version: ["XP", "7"] | ||
}); | ||
var expectedCombos = [ | ||
{ | ||
os: 'Windows', | ||
os_version: 'XP', | ||
browser: 'ie', | ||
device: null, | ||
browser_version: '6.0', | ||
real_mobile: null | ||
}, | ||
{ | ||
os: 'Windows', | ||
os_version: '7', | ||
browser: 'ie', | ||
device: null, | ||
browser_version: '10.0', | ||
real_mobile: null | ||
} | ||
]; | ||
expect(generatedCombo).to.deep.equal(expectedCombos); | ||
}); | ||
it("should only take operating system where browser exists", function () { | ||
var generatedCombo = bsCapabilities.create({ | ||
browser: "edge", | ||
browser_version: ["previous"], | ||
os: "Windows", | ||
os_version: ["XP", "7", "8", "8.1", "10"] | ||
}); | ||
var expectedCombos = [ | ||
{ | ||
os: 'Windows', | ||
os_version: '10', | ||
browser: 'edge', | ||
device: null, | ||
browser_version: '17.0', | ||
real_mobile: null | ||
} | ||
]; | ||
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: '7.0', | ||
real_mobile: null | ||
}, | ||
{ | ||
os: 'Windows', | ||
os_version: '7', | ||
browser: 'ie', | ||
device: null, | ||
browser_version: '11.0', | ||
real_mobile: null | ||
}, | ||
{ | ||
os: 'Windows', | ||
os_version: '8', | ||
browser: 'ie', | ||
device: null, | ||
browser_version: '10.0', | ||
real_mobile: null | ||
}, | ||
{ | ||
os: 'Windows', | ||
os_version: '8.1', | ||
browser: 'ie', | ||
device: null, | ||
browser_version: '11.0', | ||
real_mobile: null | ||
}, | ||
{ | ||
os: 'Windows', | ||
os_version: '10', | ||
browser: 'ie', | ||
device: null, | ||
browser_version: '11.0', | ||
real_mobile: null | ||
} | ||
]; | ||
expect(generatedCombo).to.deep.equal(expectedCombos); | ||
}); | ||
it("should only take operating system where browser exists", function () { | ||
var generatedCombo = bsCapabilities.create({ | ||
browser: "edge", | ||
browser_version: ["latest"], | ||
os: "Windows", | ||
os_version: ["XP", "7", "8", "8.1", "10"] | ||
}); | ||
var expectedCombos = [ | ||
{ | ||
os: 'Windows', | ||
os_version: '10', | ||
browser: 'edge', | ||
device: null, | ||
browser_version: 'insider preview', | ||
real_mobile: null | ||
} | ||
]; | ||
expect(generatedCombo).to.deep.equal(expectedCombos); | ||
}); | ||
}); | ||
}); |
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
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
31247
9
753
1