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

browserstack-select

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

browserstack-select - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

browserstack.options.json

93

browserstack-select.js
#!/usr/bin/env node
var path = require('path');
var args = Array.prototype.slice.call(process.argv, 2);
//console.log(args);
var CARDINALITY = 5;
if (!args.length) {
function printUsage() {
console.log('\nbrowserstack-select: Filters BrowserStack flat map of browser configs from REST API and outputs a JSON array fit to be used with browserstack.json config for browserstack-runner.\n\nUsage: `node browserstack-select.js <os> <os_version> <browser> <browser_version> <device>`\n(put `any` where you want all possibilies)');

@@ -14,29 +13,81 @@ console.log('\nExpects a file `browserstack.options.json` containing source data in working directory.');

console.log('');
return;
}
if (!args.length) {
printUsage();
process.exit(1);
}
function validArgsLength() {
return (args.length + 1) % (CARDINALITY + 1) === 0;
}
function getArgsOffset() {
return (args.length + 1) / (CARDINALITY + 1);
}
var countMode = false;
var count = 0;
if (args[0] === '--count') {
countMode = true;
args.shift();
}
if (!validArgsLength()) {
console.error('Invalid arguments length: %d\n\n', args.length);
printUsage();
process.exit(1);
}
var output = [];
var options = require(path.resolve('./browserstack.options.json'));
var offset = getArgsOffset();
//console.log(options);
while(offset-- > 0) {
options.forEach(function(item) {
options.forEach(function(item) {
function checkArg(field, argIndex) {
return (item[field] === args[argIndex] || item[field] === null || 'any' === args[argIndex]);
}
function checkValidSeperator() {
var sep = getArg(5);
return sep === undefined || sep === '+';
}
if (
checkArg('device', 4)
&& checkArg('browser_version', 3)
&& checkArg('browser', 2)
&& checkArg('os_version', 1)
&& checkArg('os', 0)
) {
output.push(item);
}
function getArg(index) {
return args[index + (CARDINALITY + 1) * offset];
}
});
function getFieldValue(field) {
return item[field] ? item[field].replace(/ /g, '') : null;
}
console.log(output);
function checkArg(field, argIndex) {
return (getFieldValue(field) === getArg(argIndex) || getFieldValue(field) === null || 'any' === getArg(argIndex));
}
if(!checkValidSeperator()) {
console.error('Invalid seperator: ' + getArg(5));
process.exit(1);
}
if (
checkArg('device', 4)
&& checkArg('browser_version', 3)
&& checkArg('browser', 2)
&& checkArg('os_version', 1)
&& checkArg('os', 0)
) {
output.push(item);
count++;
}
});
}
if (countMode) {
console.log(count);
process.exit();
}
console.log(JSON.stringify(output));
{
"name": "browserstack-select",
"version": "1.0.0",
"version": "1.1.0",
"description": "Filters BrowserStack config flat hash and outputs a JSON array fit to be used with runner config.",

@@ -5,0 +5,0 @@ "main": "browserstack-select.js",

# browserstack-select
Filters BrowserStack flat map of browser configs from REST API and outputs a JSON array fit to be used with browserstack.json config for browserstack-runner.
Filters BrowserStack Automate flat map of browser configurations (as from their REST API) and outputs a JSON array fit to be used with `browserstack.json` config for [browserstack-runner](https://github.com/browserstack/browserstack-runner).
## Usage
`node browserstack-select <os> <os_version> <browser> <browser_version> <device>`
`npm install -g browserstack-select`
`browserstack-select <os> <os_version> <browser> <browser_version> <device>`
Put `any` where you want all possibilies.
**Trim spaces for all values that have spaces!**
For example `OS X` -> `OSX`, `Mountain Lion` -> `MountainLion`, `Motorolla Razor` -> `MotorollaRazor` etc ...
**Expects a file `browserstack.options.json` containing source data in working directory.**
**Adding up configurations**
You can add up several configuration sets. One set consisting of: `<os> <os_version> <browser> <browser_version> <device>`, further abreviated as `<set>`:
`browserstack-select <set> + <set> + ...` will add up results of each set selected.
Source data can be retrieved from BrowserStack API with a command like:

@@ -17,2 +29,7 @@

## Wishlist
* Get source data directly from BrowserStack REST API (take credentials as input)
* Directly write output into browserstack.json `browsers` field
## Example

@@ -23,3 +40,3 @@

```
$ node browserstack-select.js Windows any chrome 47.0 any
$ browserstack-select Windows any chrome 47.0 any
[ { os_version: 'XP',

@@ -51,1 +68,17 @@ browser_version: '47.0',

```
## Example: adding up several sets
```
$ browserstack-select Windows 8 chrome 47.0 any + OSX MountainLion chrome 47.0 any
[ { browser_version: '47.0',
os: 'OS X',
browser: 'chrome',
device: null,
os_version: 'Mountain Lion' },
{ browser_version: '47.0',
os: 'Windows',
browser: 'chrome',
device: null,
os_version: '8' } ]
```
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