Skip to content

Commit 5cd99f1

Browse files
Merge branch 'master' of github.com:browserstack/browserstack-cypress-cli into sync-cli
2 parents e616c67 + ac5c1f8 commit 5cd99f1

File tree

13 files changed

+647
-422
lines changed

13 files changed

+647
-422
lines changed

bin/commands/info.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ module.exports = function info(args) {
1010
let bsConfigPath = utils.getConfigPath(args.cf);
1111

1212
return utils.validateBstackJson(bsConfigPath).then(function (bsConfig) {
13+
// setting setDefaultAuthHash to {} if not present and set via env variables or via args.
14+
utils.setDefaultAuthHash(bsConfig, args);
15+
1316
// accept the username from command line if provided
1417
utils.setUsername(bsConfig, args);
1518

@@ -18,6 +21,9 @@ module.exports = function info(args) {
1821

1922
utils.setUsageReportingFlag(bsConfig, args.disableUsageReporting);
2023

24+
// set cypress config filename
25+
utils.setCypressConfigFilename(bsConfig, args);
26+
2127
let buildId = args._[1];
2228

2329
let options = {
@@ -27,7 +33,7 @@ module.exports = function info(args) {
2733
password: bsConfig.auth.access_key,
2834
},
2935
headers: {
30-
"User-Agent": utils.getUserAgent(),
36+
'User-Agent': utils.getUserAgent(),
3137
},
3238
};
3339

@@ -52,7 +58,7 @@ module.exports = function info(args) {
5258

5359
if (resp.statusCode == 299) {
5460
messageType = Constants.messageTypes.INFO;
55-
errorCode = "api_deprecated";
61+
errorCode = 'api_deprecated';
5662

5763
if (build) {
5864
message = build.message;
@@ -63,14 +69,14 @@ module.exports = function info(args) {
6369
}
6470
} else if (resp.statusCode != 200) {
6571
messageType = Constants.messageTypes.ERROR;
66-
errorCode = "api_failed_build_info";
72+
errorCode = 'api_failed_build_info';
6773

6874
if (build) {
6975
message = `${
7076
Constants.userMessages.BUILD_INFO_FAILED
7177
} with error: \n${JSON.stringify(build, null, 2)}`;
7278
logger.error(message);
73-
if (build.message === "Unauthorized") errorCode = "api_auth_failed";
79+
if (build.message === 'Unauthorized') errorCode = 'api_auth_failed';
7480
} else {
7581
message = Constants.userMessages.BUILD_INFO_FAILED;
7682
logger.error(message);
@@ -86,7 +92,7 @@ module.exports = function info(args) {
8692
}
8793
}
8894
utils.sendUsageReport(bsConfig, args, message, messageType, errorCode);
89-
})
95+
});
9096
}).catch(function (err) {
9197
logger.error(err);
9298
utils.setUsageReportingFlag(null, args.disableUsageReporting);

bin/commands/init.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ function get_path(args) {
1313
if (filename !== path.basename(filename)) {
1414
let message = Constants.userMessages.CONFLICTING_INIT_ARGUMENTS;
1515
logger.error(message);
16+
// set cypress config filename
17+
utils.setCypressConfigFilename(args.bstack_config, args);
1618
utils.sendUsageReport(null, args, message, Constants.messageTypes.ERROR, 'conflicting_path_json_init');
1719
return;
1820
}

bin/commands/runs.js

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

21+
// setting setDefaultAuthHash to {} if not present and set via env variables or via args.
22+
utils.setDefaultAuthHash(bsConfig,args);
23+
2124
// accept the username from command line or env variable if provided
2225
utils.setUsername(bsConfig, args);
2326

bin/commands/stop.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ module.exports = function stop(args) {
1010
let bsConfigPath = utils.getConfigPath(args.cf);
1111

1212
return utils.validateBstackJson(bsConfigPath).then(function (bsConfig) {
13+
// setting setDefaultAuthHash to {} if not present and set via env variables or via args.
14+
utils.setDefaultAuthHash(bsConfig, args);
15+
1316
// accept the username from command line if provided
1417
utils.setUsername(bsConfig, args);
1518

@@ -18,6 +21,9 @@ module.exports = function stop(args) {
1821

1922
utils.setUsageReportingFlag(bsConfig, args.disableUsageReporting);
2023

24+
// set cypress config filename
25+
utils.setCypressConfigFilename(bsConfig, args);
26+
2127
let buildId = args._[1];
2228

2329
let options = {
@@ -27,7 +33,7 @@ module.exports = function stop(args) {
2733
password: bsConfig.auth.access_key,
2834
},
2935
headers: {
30-
"User-Agent": utils.getUserAgent(),
36+
'User-Agent': utils.getUserAgent(),
3137
},
3238
};
3339

@@ -43,16 +49,16 @@ module.exports = function stop(args) {
4349

4450
logger.info(message);
4551
} else {
46-
let build = null
52+
let build = null;
4753
try {
48-
build = JSON.parse(body)
54+
build = JSON.parse(body);
4955
} catch (error) {
50-
build = null
56+
build = null;
5157
}
5258

5359
if (resp.statusCode == 299) {
5460
messageType = Constants.messageTypes.INFO;
55-
errorCode = "api_deprecated";
61+
errorCode = 'api_deprecated';
5662

5763
if (build) {
5864
message = build.message;
@@ -63,14 +69,14 @@ module.exports = function stop(args) {
6369
}
6470
} else if (resp.statusCode != 200) {
6571
messageType = Constants.messageTypes.ERROR;
66-
errorCode = "api_failed_build_stop";
72+
errorCode = 'api_failed_build_stop';
6773

6874
if (build) {
6975
message = `${
7076
Constants.userMessages.BUILD_STOP_FAILED
7177
} with error: \n${JSON.stringify(build, null, 2)}`;
7278
logger.error(message);
73-
if (build.message === "Unauthorized") errorCode = "api_auth_failed";
79+
if (build.message === 'Unauthorized') errorCode = 'api_auth_failed';
7480
} else {
7581
message = Constants.userMessages.BUILD_STOP_FAILED;
7682
logger.error(message);
@@ -82,7 +88,7 @@ module.exports = function stop(args) {
8288
}
8389
}
8490
utils.sendUsageReport(bsConfig, args, message, messageType, errorCode);
85-
})
91+
});
8692
}).catch(function (err) {
8793
logger.error(err);
8894
utils.setUsageReportingFlag(null, args.disableUsageReporting);

bin/helpers/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
var config = require('./config.json');
22

3-
config.env = process.env.NODE_ENV || "production";
3+
config.env = process.env.BSTACK_CYPRESS_NODE_ENV || "production";
44

55
if(config.env !== "production") {
66
// load config based on env

bin/helpers/usageReporting.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ function local_cypress_version(bsConfig) {
3333
// 1. check version of Cypress installed in local project
3434
// 2. check version of Cypress installed globally if not present in project
3535

36-
if (bsConfig) {
37-
let version = get_version(path.join(bsConfig.run_settings.cypress_proj_dir, 'node_modules', '.bin', 'cypress'));
36+
if (bsConfig && bsConfig.run_settings.cypressProjectDir) {
37+
let version = get_version(path.join(bsConfig.run_settings.cypressProjectDir, 'node_modules', '.bin', 'cypress'));
3838
if (!version) {
3939
version = get_version('cypress');
4040
}
@@ -80,8 +80,8 @@ function cli_version_and_path(bsConfig) {
8080
// 1. check version of Cypress installed in local project
8181
// 2. check version of Cypress installed globally if not present in project
8282

83-
if (bsConfig) {
84-
let _path = path.join(bsConfig.run_settings.cypress_proj_dir, 'node_modules', 'browserstack-cypress');
83+
if (bsConfig && bsConfig.run_settings.cypressProjectDir) {
84+
let _path = path.join(bsConfig.run_settings.cypressProjectDir, 'node_modules', 'browserstack-cypress');
8585
let version = get_version(_path);
8686
if (!version) {
8787
version = get_version('browserstack-cypress');

bin/helpers/utils.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,16 @@ exports.setParallels = (bsConfig, args) => {
115115
}
116116
};
117117

118+
exports.setDefaultAuthHash = (bsConfig, args) => {
119+
if (
120+
this.isUndefined(bsConfig['auth']) &&
121+
(!this.isUndefined(args.username) ||
122+
!this.isUndefined(process.env.BROWSERSTACK_USERNAME))
123+
) {
124+
bsConfig['auth'] = {};
125+
}
126+
}
127+
118128
exports.setUsername = (bsConfig, args) => {
119129
if (!this.isUndefined(args.username)) {
120130
bsConfig["auth"]["username"] = args.username;
@@ -164,7 +174,7 @@ exports.setCypressConfigFilename = (bsConfig, args) => {
164174

165175
bsConfig.run_settings.userProvidedCypessConfigFile = (userProvidedCypessConfigFile || (!this.isUndefined(bsConfig.run_settings.cypress_config_file)));
166176

167-
if (userProvidedCypessConfigFile || this.isUndefined(bsConfig.run_settings.cypress_config_file)) {
177+
if ((userProvidedCypessConfigFile || this.isUndefined(bsConfig.run_settings.cypress_config_file)) && !this.isUndefined(args.cypressConfigFile)) {
168178
bsConfig.run_settings.cypress_config_file = args.cypressConfigFile;
169179
bsConfig.run_settings.cypress_config_filename = path.basename(args.cypressConfigFile);
170180
} else if (!this.isUndefined(bsConfig.run_settings.cypress_config_file)) {
@@ -219,7 +229,7 @@ exports.isParallelValid = (value) => {
219229
}
220230

221231
exports.getUserAgent = () => {
222-
return `BStack-Cypress-CLI/1.5.0 (${os.arch()}/${os.platform()}/${os.release()})`;
232+
return `BStack-Cypress-CLI/1.5.1 (${os.arch()}/${os.platform()}/${os.release()})`;
223233
};
224234

225235
exports.isAbsolute = (configPath) => {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "browserstack-cypress-cli",
3-
"version": "1.4.0",
3+
"version": "1.5.0",
44
"description": "BrowserStack Cypress CLI for Cypress integration with BrowserStack's remote devices.",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)