Skip to content

Commit f11bd00

Browse files
authored
Merge pull request #30 from browserstack/cli-args-addition
CLI args options
2 parents b6d7e5f + 84471d0 commit f11bd00

File tree

13 files changed

+169
-10
lines changed

13 files changed

+169
-10
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ browserstack.json
44
specs
55
tests.zip
66
package-lock.json
7+
.nyc_output/

bin/commands/info.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ module.exports = function info(args) {
1010
let bsConfigPath = process.cwd() + args.cf;
1111

1212
return utils.validateBstackJson(bsConfigPath).then(function (bsConfig) {
13+
// accept the username from command line if provided
14+
utils.setUsername(bsConfig, args);
15+
16+
// accept the access key from command line if provided
17+
utils.setAccessKey(bsConfig, args);
18+
1319
utils.setUsageReportingFlag(bsConfig, args.disableUsageReporting);
1420

1521
let buildId = args._[1];

bin/commands/runs.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ module.exports = function run(args) {
1515
return utils.validateBstackJson(bsConfigPath).then(function (bsConfig) {
1616
utils.setUsageReportingFlag(bsConfig, args.disableUsageReporting);
1717

18+
// accept the username from command line if provided
19+
utils.setUsername(bsConfig, args);
20+
21+
// accept the access key from command line if provided
22+
utils.setAccessKey(bsConfig, args);
23+
24+
// accept the build name from command line if provided
25+
utils.setBuildName(bsConfig, args);
26+
1827
// Validate browserstack.json values and parallels specified via arguments
1928
return capabilityHelper.validate(bsConfig, args).then(function (validated) {
2029
logger.info(validated);

bin/commands/stop.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ module.exports = function stop(args) {
1010
let bsConfigPath = process.cwd() + args.cf;
1111

1212
return utils.validateBstackJson(bsConfigPath).then(function (bsConfig) {
13+
// accept the username from command line if provided
14+
utils.setUsername(bsConfig, args);
15+
16+
// accept the access key from command line if provided
17+
utils.setAccessKey(bsConfig, args);
18+
1319
utils.setUsageReportingFlag(bsConfig, args.disableUsageReporting);
1420

1521
let buildId = args._[1];

bin/helpers/capabilityHelper.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ const caps = (bsConfig, zip) => {
6464

6565
if (bsConfig.run_settings) {
6666
obj.project = bsConfig.run_settings.project || bsConfig.run_settings.project_name;
67-
obj.customBuildName = bsConfig.run_settings.customBuildName || bsConfig.run_settings.build_name;
67+
obj.customBuildName = bsConfig.run_settings.build_name || bsConfig.run_settings.customBuildName;
6868
obj.callbackURL = bsConfig.run_settings.callback_url;
6969
obj.projectNotifyURL = bsConfig.run_settings.project_notify_URL;
7070
obj.parallels = bsConfig.run_settings.parallels;
@@ -99,7 +99,7 @@ const validate = (bsConfig, args) => {
9999

100100
// validate parallels specified in browserstack.json if parallels are not specified via arguments
101101
if (!Utils.isUndefined(args) && Utils.isUndefined(args.parallels) && !Utils.isParallelValid(bsConfig.run_settings.parallels)) reject(Constants.validationMessages.INVALID_PARALLELS_CONFIGURATION);
102-
102+
103103
// if parallels specified via arguments validate only arguments
104104
if (!Utils.isUndefined(args) && !Utils.isUndefined(args.parallels) && !Utils.isParallelValid(args.parallels)) reject(Constants.validationMessages.INVALID_PARALLELS_CONFIGURATION);
105105

@@ -111,7 +111,7 @@ const validate = (bsConfig, args) => {
111111
}catch(error){
112112
reject(Constants.validationMessages.INVALID_CYPRESS_JSON)
113113
}
114-
114+
115115
resolve(Constants.validationMessages.VALIDATED);
116116
});
117117
}

bin/helpers/constants.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,13 @@ const cliMessages = {
5252
PARALLEL_DESC: "The maximum number of parallels to use to run your test suite",
5353
INFO: "Run your tests on BrowserStack.",
5454
DESC: "Path to BrowserStack config",
55-
CONFIG_DEMAND: "config file is required"
55+
CONFIG_DEMAND: "config file is required",
56+
BUILD_NAME: "The build name you want to use to name your test runs"
5657
},
5758
COMMON: {
58-
DISABLE_USAGE_REPORTING: "Disable usage reporting"
59+
DISABLE_USAGE_REPORTING: "Disable usage reporting",
60+
USERNAME: "Your BrowserStack username",
61+
ACCESS_KEY: "Your BrowserStack access key"
5962
}
6063
}
6164

bin/helpers/utils.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,24 @@ exports.setParallels = (bsConfig, args) => {
7676
}
7777
}
7878

79+
exports.setUsername = (bsConfig, args) => {
80+
if (!this.isUndefined(args.username)) {
81+
bsConfig['auth']['username'] = args.username;
82+
}
83+
}
84+
85+
exports.setAccessKey = (bsConfig, args) => {
86+
if (!this.isUndefined(args.key)) {
87+
bsConfig['auth']['access_key'] = args.key;
88+
}
89+
}
90+
91+
exports.setBuildName = (bsConfig, args) => {
92+
if (!this.isUndefined(args['build-name'])) {
93+
bsConfig['run_settings']['build_name'] = args['build-name'];
94+
}
95+
}
96+
7997
exports.isUndefined = value => (value === undefined || value === null);
8098

8199
exports.isFloat = value => (Number(value) && Number(value) % 1 !== 0);
@@ -85,5 +103,5 @@ exports.isParallelValid = (value) => {
85103
}
86104

87105
exports.getUserAgent = () => {
88-
return `BStack-Cypress-CLI/1.x (${os.arch()}/${os.platform()}/${os.release()})`;
106+
return `BStack-Cypress-CLI/1.2.0 (${os.arch()}/${os.platform()}/${os.release()})`;
89107
}

bin/runner.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,18 @@ var argv = yargs
6262
description: Constants.cliMessages.COMMON.DISABLE_USAGE_REPORTING,
6363
type: "boolean"
6464
},
65+
'u': {
66+
alias: 'username',
67+
describe: Constants.cliMessages.COMMON.USERNAME,
68+
type: "string",
69+
default: undefined
70+
},
71+
'k': {
72+
alias: 'key',
73+
describe: Constants.cliMessages.COMMON.ACCESS_KEY,
74+
type: "string",
75+
default: undefined
76+
},
6577
})
6678
.help('help')
6779
.wrap(null)
@@ -90,6 +102,18 @@ var argv = yargs
90102
description: Constants.cliMessages.COMMON.DISABLE_USAGE_REPORTING,
91103
type: "boolean"
92104
},
105+
'u': {
106+
alias: 'username',
107+
describe: Constants.cliMessages.COMMON.USERNAME,
108+
type: "string",
109+
default: undefined
110+
},
111+
'k': {
112+
alias: 'key',
113+
describe: Constants.cliMessages.COMMON.ACCESS_KEY,
114+
type: "string",
115+
default: undefined
116+
},
93117
})
94118
.help('help')
95119
.wrap(null)
@@ -122,6 +146,24 @@ var argv = yargs
122146
describe: Constants.cliMessages.RUN.PARALLEL_DESC,
123147
type: "number",
124148
default: undefined
149+
},
150+
'u': {
151+
alias: 'username',
152+
describe: Constants.cliMessages.COMMON.USERNAME,
153+
type: "string",
154+
default: undefined
155+
},
156+
'k': {
157+
alias: 'key',
158+
describe: Constants.cliMessages.COMMON.ACCESS_KEY,
159+
type: "string",
160+
default: undefined
161+
},
162+
'b': {
163+
alias: 'build-name',
164+
describe: Constants.cliMessages.RUN.BUILD_NAME,
165+
type: "string",
166+
default: undefined
125167
}
126168
})
127169
.help('help')

bin/templates/configTemplate.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module.exports = function () {
22
var config = {
33
"auth": {
4-
"username": "<username>",
5-
"access_key": "<access-key>"
4+
"username": "<Your BrowserStack username>",
5+
"access_key": "<Your BrowserStack access key>"
66
},
77
"browsers": [
88
{
@@ -12,7 +12,7 @@ module.exports = function () {
1212
}
1313
],
1414
"run_settings": {
15-
"cypress_proj_dir" : "/path/to/cypress.json",
15+
"cypress_proj_dir" : "/path/to/directory-that-contains-<cypress.json>-file",
1616
"project_name": "project-name",
1717
"build_name": "build-name",
1818
"parallels": "Here goes the number of parallels you want to run",

test/unit/bin/commands/info.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ describe("buildInfo", () => {
2222

2323
beforeEach(() => {
2424
sandbox = sinon.createSandbox();
25+
setUsernameStub = sandbox.stub();
26+
setAccessKeyStub = sandbox.stub();
2527
validateBstackJsonStub = sandbox.stub();
2628
setUsageReportingFlagStub = sandbox.stub().returns(undefined);
2729
getUserAgentStub = sandbox.stub().returns("random user-agent");
@@ -45,6 +47,8 @@ describe("buildInfo", () => {
4547

4648
const info = proxyquire("../../../../bin/commands/info", {
4749
"../helpers/utils": {
50+
setUsername: setUsernameStub,
51+
setAccessKey: setAccessKeyStub,
4852
validateBstackJson: validateBstackJsonStub,
4953
getErrorCodeFromErr: getErrorCodeFromErrStub,
5054
sendUsageReport: sendUsageReportStub,
@@ -77,6 +81,8 @@ describe("buildInfo", () => {
7781

7882
const info = proxyquire("../../../../bin/commands/info", {
7983
"../helpers/utils": {
84+
setUsername: setUsernameStub,
85+
setAccessKey: setAccessKeyStub,
8086
validateBstackJson: validateBstackJsonStub,
8187
getErrorCodeFromErr: getErrorCodeFromErrStub,
8288
sendUsageReport: sendUsageReportStub,
@@ -103,6 +109,8 @@ describe("buildInfo", () => {
103109
describe("Handle statusCode != 200", () => {
104110
beforeEach(() => {
105111
sandbox = sinon.createSandbox();
112+
setUsernameStub = sandbox.stub();
113+
setAccessKeyStub = sandbox.stub();
106114
validateBstackJsonStub = sandbox.stub();
107115
setUsageReportingFlagStub = sandbox.stub().returns(undefined);
108116
getUserAgentStub = sandbox.stub().returns("random user-agent");
@@ -128,6 +136,8 @@ describe("buildInfo", () => {
128136

129137
const info = proxyquire("../../../../bin/commands/info", {
130138
"../helpers/utils": {
139+
setUsername: setUsernameStub,
140+
setAccessKey: setAccessKeyStub,
131141
validateBstackJson: validateBstackJsonStub,
132142
getErrorCodeFromErr: getErrorCodeFromErrStub,
133143
sendUsageReport: sendUsageReportStub,
@@ -166,6 +176,8 @@ describe("buildInfo", () => {
166176

167177
const info = proxyquire("../../../../bin/commands/info", {
168178
"../helpers/utils": {
179+
setUsername: setUsernameStub,
180+
setAccessKey: setAccessKeyStub,
169181
validateBstackJson: validateBstackJsonStub,
170182
getErrorCodeFromErr: getErrorCodeFromErrStub,
171183
sendUsageReport: sendUsageReportStub,
@@ -199,6 +211,8 @@ describe("buildInfo", () => {
199211

200212
const info = proxyquire("../../../../bin/commands/info", {
201213
"../helpers/utils": {
214+
setUsername: setUsernameStub,
215+
setAccessKey: setAccessKeyStub,
202216
validateBstackJson: validateBstackJsonStub,
203217
getErrorCodeFromErr: getErrorCodeFromErrStub,
204218
sendUsageReport: sendUsageReportStub,
@@ -227,6 +241,8 @@ describe("buildInfo", () => {
227241

228242
beforeEach(() => {
229243
sandbox = sinon.createSandbox();
244+
setUsernameStub = sandbox.stub();
245+
setAccessKeyStub = sandbox.stub();
230246
validateBstackJsonStub = sandbox.stub();
231247
setUsageReportingFlagStub = sandbox.stub().returns(undefined);
232248
getUserAgentStub = sandbox.stub().returns("random user-agent");
@@ -250,6 +266,8 @@ describe("buildInfo", () => {
250266

251267
const info = proxyquire("../../../../bin/commands/info", {
252268
"../helpers/utils": {
269+
setUsername: setUsernameStub,
270+
setAccessKey: setAccessKeyStub,
253271
validateBstackJson: validateBstackJsonStub,
254272
getErrorCodeFromErr: getErrorCodeFromErrStub,
255273
sendUsageReport: sendUsageReportStub,
@@ -277,6 +295,8 @@ describe("buildInfo", () => {
277295

278296
beforeEach(() => {
279297
sandbox = sinon.createSandbox();
298+
setUsernameStub = sandbox.stub();
299+
setAccessKeyStub = sandbox.stub();
280300
validateBstackJsonStub = sandbox.stub();
281301
setUsageReportingFlagStub = sandbox.stub().returns(undefined);
282302
sendUsageReportStub = sandbox.stub().callsFake(function () {
@@ -293,6 +313,8 @@ describe("buildInfo", () => {
293313
it("send usage report if validateBstackJson fails", () => {
294314
const info = proxyquire("../../../../bin/commands/info", {
295315
"../helpers/utils": {
316+
setUsername: setUsernameStub,
317+
setAccessKey: setAccessKeyStub,
296318
validateBstackJson: validateBstackJsonStub,
297319
getErrorCodeFromErr: getErrorCodeFromErrStub,
298320
sendUsageReport: sendUsageReportStub,

0 commit comments

Comments
 (0)