Skip to content

Commit 624ef2d

Browse files
committed
Merged master
1 parent 781e06f commit 624ef2d

File tree

5 files changed

+29
-4
lines changed

5 files changed

+29
-4
lines changed

bin/commands/runs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ 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

3737
// Archive the spec files

bin/helpers/capabilityHelper.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const logger = require("./logger").winstonLogger,
2-
Constants = require("./constants");
2+
Constants = require("./constants"),
3+
Util = require("./util");
34

45
const caps = (bsConfig, zip) => {
56
return new Promise(function (resolve, reject) {
@@ -61,7 +62,7 @@ const caps = (bsConfig, zip) => {
6162
})
6263
}
6364

64-
const validate = (bsConfig) => {
65+
const validate = (bsConfig, args) => {
6566
return new Promise(function(resolve, reject){
6667
if (!bsConfig) reject(Constants.validationMessages.EMPTY_BROWSERSTACK_JSON);
6768

@@ -71,7 +72,15 @@ const validate = (bsConfig) => {
7172

7273
if (!bsConfig.run_settings) reject(Constants.validationMessages.EMPTY_RUN_SETTINGS);
7374

74-
if(!bsConfig.run_settings.cypress_proj_dir) reject(Constants.validationMessages.EMPTY_SPEC_FILES);
75+
if (!bsConfig.run_settings.cypress_proj_dir) reject(Constants.validationMessages.EMPTY_SPEC_FILES);
76+
77+
// validate parallels specified in browserstack.json if parallels are not specified via arguments
78+
if (Util.isUndefined(args.parallels) && !Util.isParallelValid(bsConfig.run_settings.parallels)) {
79+
reject(Constants.validationMessages.INVALID_PARALLES_CONFIGURATION);
80+
}
81+
// if parallels specified via arguments validate both parallels specifed in browserstack.json and parallels specified in arguments
82+
if (!Util.isUndefined(args.parallels) && !Util.isParallelValid(args.parallels)) reject(Constants.validationMessages.INVALID_PARALLES_CONFIGURATION);
83+
7584

7685
resolve(Constants.validationMessages.VALIDATED);
7786
});

bin/helpers/constants.js

Lines changed: 1 addition & 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 = {

bin/helpers/util.js

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

73+
exports.setParallels = (bsConfig, args) => {
74+
if ((args.parallels !== undefined && !isNaN(args.parallels)) && bsConfig && (bsConfig['run_settings']['parallels'] === undefined || bsConfig['run_settings']['parallels'])) {
75+
bsConfig['run_settings']['parallels'] = args.parallels;
76+
}
77+
}
78+
79+
exports.isUndefined = value => (value === undefined || value === null || value === '');
80+
81+
exports.isFloat = value => (Number(value) && Number(value) % 1 !== 0);
82+
83+
exports.isParallelValid = (value) => {
84+
return this.isUndefined(value) || !(isNaN(value) || this.isFloat(value) || parseInt(value, 10) === 0 || parseInt(value, 10) < -1);
85+
}
86+
7387
exports.getUserAgent = () => {
7488
return `BStack-Cypress-CLI/1.x (${os.arch()}/${os.platform()}/${os.release()})`;
7589
}

bin/templates/configTemplate.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ module.exports = function () {
1515
"cypress_proj_dir" : "/path/to/cypress.json",
1616
"project_name": "project-name",
1717
"build_name": "build-name",
18+
"parallels": "number of parallels to run",
1819
"npm_dependencies": {
1920
}
2021
},

0 commit comments

Comments
 (0)