Skip to content

Commit 7a3b405

Browse files
Improved support of config options in cli
1 parent a2e8a4f commit 7a3b405

File tree

5 files changed

+55
-7
lines changed

5 files changed

+55
-7
lines changed

bin/commands/runs.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module.exports = function run(args) {
2222
markBlockEnd('deleteOldResults');
2323

2424
markBlockStart('validateBstackJson');
25-
return utils.validateBstackJson(bsConfigPath).then(function (bsConfig) {
25+
return utils.validateBstackJson(bsConfigPath).then(async function (bsConfig) {
2626
markBlockEnd('validateBstackJson');
2727
markBlockStart('setConfig');
2828
utils.setUsageReportingFlag(bsConfig, args.disableUsageReporting);
@@ -67,6 +67,12 @@ module.exports = function run(args) {
6767

6868
// set the no-wrap
6969
utils.setNoWrap(bsConfig, args);
70+
71+
//set browsers
72+
await utils.setBrowsers(bsConfig, args);
73+
74+
//set config (--config)
75+
utils.setConfig(bsConfig, args);
7076
markBlockEnd('setConfig');
7177

7278
// Validate browserstack.json values and parallels specified via arguments

bin/helpers/capabilityHelper.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
const logger = require("./logger").winstonLogger,
22
Constants = require("./constants"),
33
Utils = require("./utils"),
4-
fs = require('fs'),
5-
path = require('path');
4+
fs = require('fs');
65

76
const caps = (bsConfig, zip) => {
87
return new Promise(function (resolve, reject) {

bin/helpers/constants.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ const validationMessages = {
6868
INVALID_CLI_LOCAL_IDENTIFIER: "When using --local-identifier, a value needs to be supplied. \n--local-identifier <String>.\nFor more info, check out https://www.browserstack.com/docs/automate/cypress/cli-reference",
6969
INVALID_LOCAL_MODE: "When using --local-mode, a value needs to be supplied. \n--local-mode (\"always-on\" | \"on-demand\").\nFor more info, check out https://www.browserstack.com/docs/automate/cypress/cli-reference",
7070
INVALID_LOCAL_CONFIG_FILE: "Using --local-config-file requires an input of the form /path/to/config-file.yml.\nFor more info, check out https://www.browserstack.com/docs/automate/cypress/cli-reference",
71-
INVALID_LOCAL_IDENTIFIER: "Invalid value specified for local_identifier. For more info, check out https://www.browserstack.com/docs/automate/cypress/cli-reference"
71+
INVALID_LOCAL_IDENTIFIER: "Invalid value specified for local_identifier. For more info, check out https://www.browserstack.com/docs/automate/cypress/cli-reference",
72+
INVALID_BROWSER_ARGS: "Aborting as an unacceptable value was passed for --browser. Read more at https://www.browserstack.com/docs/automate/cypress/cli-reference"
7273
};
7374

7475
const cliMessages = {
@@ -109,7 +110,9 @@ const cliMessages = {
109110
LOCAL_MODE: 'Accepted values: ("always-on" | "on-demand") - if you choose to keep the binary "always-on", it will speed up your tests by keeping the Local connection warmed up in the background; otherwise, you can choose to have it spawn and killed for every build',
110111
LOCAL_IDENTIFIER: "Accepted values: String - assign an identifier to your Local process instance",
111112
LOCAL_CONFIG_FILE: "Accepted values: String - path to local config-file to your Local process instance. Learn more at https://www.browserstack.com/local-testing/binary-params",
112-
SYNC_NO_WRAP: "Wrap the spec names in --sync mode in case of smaller terminal window size pass --no-wrap"
113+
SYNC_NO_WRAP: "Wrap the spec names in --sync mode in case of smaller terminal window size pass --no-wrap",
114+
BROWSER_DESCRIPTION: "Specify the browsers you need to run your tests on.",
115+
CONFIG_DESCRIPTION: "Set configuration values. Separate multiple values with a comma. The values set here override any values set in your configuration file."
113116
},
114117
COMMON: {
115118
DISABLE_USAGE_REPORTING: "Disable usage reporting",

bin/helpers/utils.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,3 +739,32 @@ exports.deleteBaseUrlFromError = (err) => {
739739
return err.replace(/To test ([\s\S]*)on BrowserStack/g, 'To test on BrowserStack');
740740
}
741741

742+
exports.setBrowsers = async (bsConfig, args) => {
743+
return new Promise((resolve, reject) => {
744+
if(!this.isUndefined(args.browser)){
745+
try{
746+
bsConfig["browsers"] = []
747+
let browsersList = args.browser.split(',')
748+
browsersList.forEach((browser)=>{
749+
let browserHash = {}
750+
let osBrowserDetails = browser.split(':')
751+
browserHash['os'] = osBrowserDetails[1]
752+
let browserDetails = osBrowserDetails[0].split('@')
753+
browserHash['browser'] = browserDetails[0]
754+
browserHash['versions'] = []
755+
browserHash['versions'].push(this.isUndefined(browserDetails[1]) ? "latest" : browserDetails[1])
756+
bsConfig["browsers"].push(browserHash)
757+
});
758+
} catch(err){
759+
reject(Constants.validationMessages.INVALID_BROWSER_ARGS)
760+
}
761+
}
762+
resolve()
763+
});
764+
}
765+
766+
exports.setConfig = (bsConfig, args) => {
767+
if (!this.isUndefined(args.config)) {
768+
bsConfig["run_settings"]["config"] = args.config
769+
}
770+
}

bin/runner.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ var argv = yargs
151151
type: "boolean"
152152
},
153153
'p': {
154-
alias: 'parallels',
154+
alias: ['parallels', 'parallel'],
155155
describe: Constants.cliMessages.RUN.PARALLEL_DESC,
156156
type: "number",
157157
default: undefined
@@ -169,7 +169,7 @@ var argv = yargs
169169
default: undefined
170170
},
171171
'b': {
172-
alias: 'build-name',
172+
alias: ['build-name', 'ci-build-id'],
173173
describe: Constants.cliMessages.RUN.BUILD_NAME,
174174
type: "string",
175175
default: undefined
@@ -231,6 +231,17 @@ var argv = yargs
231231
default: false,
232232
describe: Constants.cliMessages.RUN.SYNC_NO_WRAP,
233233
type: "boolean"
234+
},
235+
'browser': {
236+
describe: Constants.cliMessages.RUN.BROWSER_DESCRIPTION,
237+
type: "string",
238+
default: undefined
239+
},
240+
'c': {
241+
alias: 'config',
242+
describe: Constants.cliMessages.RUN.CONFIG_DESCRIPTION,
243+
type: "string",
244+
default: undefined
234245
}
235246
})
236247
.help('help')

0 commit comments

Comments
 (0)