Skip to content

Commit 7c64385

Browse files
committed
[CYP-175] Parallelisation support in cli
1 parent dedbd95 commit 7c64385

File tree

5 files changed

+28
-3
lines changed

5 files changed

+28
-3
lines changed

bin/commands/runs.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,12 @@ function runCypress(args) {
3131
util.setUsageReportingFlag(bsConfig, args.disableUsageReporting);
3232

3333
// Validate browserstack.json values
34-
capabilityHelper.validate(bsConfig).then(function (validated) {
34+
capabilityHelper.validate(bsConfig, args).then(function (validated) {
3535
logger.info(validated);
3636

37+
// accept the number of parallels
38+
util.setParallels(bsConfig, args);
39+
3740
// Archive the spec files
3841
archiver.archive(bsConfig.run_settings, config.fileName).then(function (data) {
3942

bin/helpers/capabilityHelper.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,15 @@ const caps = (bsConfig, zip) => {
5656
obj.projectNotifyURL = bsConfig.run_settings.project_notify_URL
5757
if (obj.projectNotifyURL) logger.info(`Project notify URL is: ${obj.projectNotifyURL}`);
5858

59+
obj.parallels = bsConfig.run_settings.parallels;
60+
if (obj.parallels) logger.info(`Parallels specified are: ${obj.parallels}`);
61+
5962
var data = JSON.stringify(obj);
6063
resolve(data);
6164
})
6265
}
6366

64-
const validate = (bsConfig) => {
67+
const validate = (bsConfig, args) => {
6568
return new Promise(function(resolve, reject){
6669
if (!bsConfig) reject(Constants.validationMessages.EMPTY_BROWSERSTACK_JSON);
6770

@@ -73,6 +76,11 @@ const validate = (bsConfig) => {
7376

7477
if(!bsConfig.run_settings.cypress_proj_dir) reject(Constants.validationMessages.EMPTY_SPEC_FILES);
7578

79+
if (!args.parallels) {
80+
if (Number.isNaN(bsConfig.run_settings.parallels) || (parseInt(bsConfig.run_settings.parallels, 10) < 0 && parseInt(bsConfig.run_settings.parallels, 10) != -1))
81+
reject(Constants.validationMessages.INVALID_PARALLES_CONFIGURATION)
82+
};
83+
7684
resolve(Constants.validationMessages.VALIDATED);
7785
});
7886
}

bin/helpers/constants.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const validationMessages = {
2424
NOT_VALID: "browerstack.json is not valid",
2525
NOT_VALID_JSON: "browerstack.json is not a valid json",
2626
INVALID_EXTENSION: "Invalid files, please remove these files and try again.",
27+
INVALID_PARALLES_CONFIGURATION: "Invalid type of parallel, accepted values are positive or -1",
2728
};
2829

2930
const cliMessages = {
@@ -46,6 +47,7 @@ const cliMessages = {
4647
STOP_MESSAGE: "Stopping build with given buildId "
4748
},
4849
RUN: {
50+
PARALLEL_DESC: "Maximum number of parallels to run",
4951
INFO: "Run your tests on BrowserStack.",
5052
DESC: "Path to BrowserStack config",
5153
CONFIG_DEMAND: "config file is required"

bin/helpers/util.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ exports.setUsageReportingFlag = (bsConfig, disableUsageReporting) => {
7070
}
7171
}
7272

73+
exports.setParallels = (bsConfig, args) => {
74+
if ((args.parallels !== undefined && !Number.isNaN(args.parallels))) {
75+
bsConfig['run_settings']['parallels'] = args.parallels;
76+
}
77+
}
78+
7379
exports.getUserAgent = () => {
7480
return `BStack-Cypress-CLI/1.x (${os.arch()}/${os.platform()}/${os.release()})`;
7581
}

bin/runner.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ var argv = yargs
101101
})
102102
.command('run', Constants.cliMessages.RUN.INFO, function(yargs) {
103103
argv = yargs
104-
.usage('usage: $0 build')
104+
.usage('usage: $0 run <options>')
105105
.options({
106106
'cf': {
107107
alias: 'config-file',
@@ -117,6 +117,12 @@ var argv = yargs
117117
description: Constants.cliMessages.COMMON.DISABLE_USAGE_REPORTING,
118118
type: "boolean"
119119
},
120+
'p': {
121+
alias: 'parallels',
122+
describe: Constants.cliMessages.RUN.PARALLEL_DESC,
123+
type: "number",
124+
default: undefined
125+
}
120126
})
121127
.help('help')
122128
.wrap(null)

0 commit comments

Comments
 (0)