Skip to content

Commit 457830f

Browse files
committed
Merge branch 'master' of https://github.com/browserstack/browserstack-cypress-cli into multiple_versions
2 parents 500d901 + 8e341d9 commit 457830f

28 files changed

+1470
-278
lines changed

bin/commands/info.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ 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-
13+
utils.setDefaults(bsConfig, args);
14+
1615
// accept the username from command line if provided
1716
utils.setUsername(bsConfig, args);
1817

bin/commands/runs.js

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ const archiver = require("../helpers/archiver"),
77
capabilityHelper = require("../helpers/capabilityHelper"),
88
Constants = require("../helpers/constants"),
99
utils = require("../helpers/utils"),
10-
fileHelpers = require("../helpers/fileHelpers");
10+
fileHelpers = require("../helpers/fileHelpers"),
11+
syncRunner = require("../helpers/syncRunner");
1112

1213
module.exports = function run(args) {
1314
let bsConfigPath = utils.getConfigPath(args.cf);
@@ -17,8 +18,7 @@ module.exports = function run(args) {
1718
return utils.validateBstackJson(bsConfigPath).then(function (bsConfig) {
1819
utils.setUsageReportingFlag(bsConfig, args.disableUsageReporting);
1920

20-
// setting setDefaultAuthHash to {} if not present and set via env variables or via args.
21-
utils.setDefaultAuthHash(bsConfig,args);
21+
utils.setDefaults(bsConfig, args);
2222

2323
// accept the username from command line or env variable if provided
2424
utils.setUsername(bsConfig, args);
@@ -45,22 +45,23 @@ module.exports = function run(args) {
4545
utils.setLocalIdentifier(bsConfig);
4646

4747
// Validate browserstack.json values and parallels specified via arguments
48-
return capabilityHelper.validate(bsConfig, args).then(function (validated) {
49-
logger.info(validated);
48+
return capabilityHelper.validate(bsConfig, args).then(function (cypressJson) {
49+
50+
//get the number of spec files
51+
let specFiles = utils.getNumberOfSpecFiles(bsConfig, args, cypressJson);
5052

5153
// accept the number of parallels
52-
utils.setParallels(bsConfig, args);
54+
utils.setParallels(bsConfig, args, specFiles.length);
5355

5456
// Archive the spec files
5557
return archiver.archive(bsConfig.run_settings, config.fileName, args.exclude).then(function (data) {
5658

5759
// Uploaded zip file
5860
return zipUploader.zipUpload(bsConfig, config.fileName).then(function (zip) {
59-
6061
// Create build
6162
return build.createBuild(bsConfig, zip).then(function (data) {
6263
let message = `${data.message}! ${Constants.userMessages.BUILD_CREATED} with build id: ${data.build_id}`;
63-
let dashboardLink = `${Constants.userMessages.VISIT_DASHBOARD} ${config.dashboardUrl}${data.build_id}`;
64+
let dashboardLink = `${Constants.userMessages.VISIT_DASHBOARD} ${data.dashboard_url}`;
6465
utils.exportResults(data.build_id, `${config.dashboardUrl}${data.build_id}`);
6566
if ((utils.isUndefined(bsConfig.run_settings.parallels) && utils.isUndefined(args.parallels)) || (!utils.isUndefined(bsConfig.run_settings.parallels) && bsConfig.run_settings.parallels == Constants.cliMessages.RUN.DEFAULT_PARALLEL_MESSAGE)) {
6667
logger.warn(Constants.userMessages.NO_PARALLELS);
@@ -70,10 +71,21 @@ module.exports = function run(args) {
7071
logger.warn(Constants.userMessages.CYPRESS_VERSION_CHANGED);
7172
}
7273

73-
if (!args.disableNpmWarning && bsConfig.run_settings.npm_dependencies && Object.keys(bsConfig.run_settings.npm_dependencies).length <= 0) logger.warn(Constants.userMessages.NO_NPM_DEPENDENCIES);
74+
if (!args.disableNpmWarning && bsConfig.run_settings.npm_dependencies && Object.keys(bsConfig.run_settings.npm_dependencies).length <= 0) {
75+
logger.warn(Constants.userMessages.NO_NPM_DEPENDENCIES);
76+
logger.warn(Constants.userMessages.NO_NPM_DEPENDENCIES_READ_MORE);
77+
}
78+
79+
if (args.sync) {
80+
syncRunner.pollBuildStatus(bsConfig, data).then((exitCode) => {
81+
utils.sendUsageReport(bsConfig, args, `${message}\n${dashboardLink}`, Constants.messageTypes.SUCCESS, null);
82+
utils.handleSyncExit(exitCode, data.dashboard_url)
83+
});
84+
}
7485

7586
logger.info(message);
7687
logger.info(dashboardLink);
88+
if(!args.sync) logger.info(Constants.userMessages.EXIT_SYNC_CLI_MESSAGE.replace("<build-id>",data.build_id));
7789
utils.sendUsageReport(bsConfig, args, `${message}\n${dashboardLink}`, Constants.messageTypes.SUCCESS, null);
7890
return;
7991
}).catch(function (err) {
@@ -85,9 +97,8 @@ module.exports = function run(args) {
8597
// Zip Upload failed
8698
logger.error(err);
8799
logger.error(Constants.userMessages.ZIP_UPLOAD_FAILED);
88-
utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.userMessages.ZIP_UPLOAD_FAILED}`, Constants.messageTypes.ERROR, 'zip_upload_failed');
89-
}).finally(function () {
90100
fileHelpers.deleteZip();
101+
utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.userMessages.ZIP_UPLOAD_FAILED}`, Constants.messageTypes.ERROR, 'zip_upload_failed');
91102
});
92103
}).catch(function (err) {
93104
// Zipping failed

bin/commands/stop.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ 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-
13+
utils.setDefaults(bsConfig, args);
14+
1615
// accept the username from command line if provided
1716
utils.setUsername(bsConfig, args);
1817

bin/helpers/archiver.js

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ const archiveSpecs = (runSettings, filePath, excludeFiles) => {
1313

1414
var cypressFolderPath = path.dirname(runSettings.cypressConfigFilePath);
1515

16+
logger.info(`Creating tests.zip with files in ${cypressFolderPath}`);
17+
1618
var archive = archiver('zip', {
17-
zlib: { level: 9 } // Sets the compression level.
19+
zlib: {level: 9}, // Sets the compression level.
1820
});
1921

2022
archive.on('warning', function (err) {
@@ -26,7 +28,7 @@ const archiveSpecs = (runSettings, filePath, excludeFiles) => {
2628
});
2729

2830
output.on('close', function () {
29-
resolve("Zipping completed");
31+
resolve('Zipping completed');
3032
});
3133

3234
output.on('end', function () {
@@ -41,9 +43,7 @@ const archiveSpecs = (runSettings, filePath, excludeFiles) => {
4143

4244
let ignoreFiles = getFilesToIgnore(runSettings, excludeFiles);
4345

44-
Constants.allowedFileTypes.forEach(fileType => {
45-
archive.glob(`**/*.${fileType}`, { cwd: cypressFolderPath, matchBase: true, ignore: ignoreFiles });
46-
});
46+
archive.glob(`**/*.+(${Constants.allowedFileTypes.join("|")})`, { cwd: cypressFolderPath, matchBase: true, ignore: ignoreFiles, dot:true });
4747

4848
let packageJSON = {};
4949

@@ -52,19 +52,26 @@ const archiveSpecs = (runSettings, filePath, excludeFiles) => {
5252
}
5353

5454
if (typeof runSettings.npm_dependencies === 'object') {
55-
Object.assign(packageJSON, {devDependencies: runSettings.npm_dependencies});
55+
Object.assign(packageJSON, {
56+
devDependencies: runSettings.npm_dependencies,
57+
});
5658
}
5759

5860
if (Object.keys(packageJSON).length > 0) {
5961
let packageJSONString = JSON.stringify(packageJSON, null, 4);
60-
archive.append(packageJSONString, { name: 'browserstack-package.json' });
62+
archive.append(packageJSONString, {name: 'browserstack-package.json'});
6163
}
6264

6365
// do not add cypress.json if arg provided is false
64-
if (runSettings.cypress_config_file && runSettings.cypress_config_filename !== 'false') {
65-
let cypressJSON = JSON.parse(fs.readFileSync(runSettings.cypressConfigFilePath));
66+
if (
67+
runSettings.cypress_config_file &&
68+
runSettings.cypress_config_filename !== 'false'
69+
) {
70+
let cypressJSON = JSON.parse(
71+
fs.readFileSync(runSettings.cypressConfigFilePath)
72+
);
6673
let cypressJSONString = JSON.stringify(cypressJSON, null, 4);
67-
archive.append(cypressJSONString, { name: 'cypress.json' });
74+
archive.append(cypressJSONString, {name: 'cypress.json'});
6875
}
6976

7077
archive.finalize();

bin/helpers/capabilityHelper.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,32 @@ const caps = (bsConfig, zip) => {
2020

2121
// Browser list
2222
let osBrowserArray = [];
23+
let browsersList = [];
2324
if (bsConfig.browsers) {
2425
bsConfig.browsers.forEach((element) => {
2526
osBrowser = element.os + "-" + element.browser;
27+
osAndBrowser = element.os + " / " + Utils.capitalizeFirstLetter(element.browser);
2628
element.versions.forEach((version) => {
2729
osBrowserArray.push(osBrowser + version);
30+
browsersList.push(`${osAndBrowser} (${version})`);
2831
});
2932
});
3033
}
3134
obj.devices = osBrowserArray;
3235
if (obj.devices.length == 0) reject(Constants.validationMessages.EMPTY_BROWSER_LIST);
33-
logger.info(`Browser list: ${osBrowserArray.toString()}`);
36+
logger.info(`Browsers list: ${browsersList.join(", ")}`);
3437

3538
// Test suite
3639
if (zip.zip_url && zip.zip_url.split("://")[1].length !== 0) {
3740
obj.test_suite = zip.zip_url.split("://")[1];
3841
} else {
3942
reject("Test suite is empty");
4043
}
41-
logger.info(`Test suite: bs://${obj.test_suite}`);
4244

4345
// Local
4446
obj.local = false;
4547
if (bsConfig.connection_settings && bsConfig.connection_settings.local === true) obj.local = true;
46-
logger.info(`Local is set to: ${obj.local}`);
48+
logger.info(`Local is set to: ${obj.local} (${obj.local ? Constants.userMessages.LOCAL_TRUE : Constants.userMessages.LOCAL_FALSE})`);
4749

4850
// Local Identifier
4951
obj.localIdentifier = null;
@@ -102,6 +104,7 @@ const caps = (bsConfig, zip) => {
102104

103105
const validate = (bsConfig, args) => {
104106
return new Promise(function (resolve, reject) {
107+
logger.info(Constants.userMessages.VALIDATING_CONFIG);
105108
if (!bsConfig) reject(Constants.validationMessages.EMPTY_BROWSERSTACK_JSON);
106109

107110
if (!bsConfig.auth) reject(Constants.validationMessages.INCORRECT_AUTH_PARAMS);
@@ -125,6 +128,7 @@ const validate = (bsConfig, args) => {
125128
// validate if config file provided exists or not when cypress_config_file provided
126129
// validate the cypressProjectDir key otherwise.
127130
let cypressConfigFilePath = bsConfig.run_settings.cypressConfigFilePath;
131+
let cypressJson = {};
128132

129133
if (!fs.existsSync(cypressConfigFilePath) && bsConfig.run_settings.cypress_config_filename !== 'false') reject(Constants.validationMessages.INVALID_CYPRESS_CONFIG_FILE);
130134

@@ -142,8 +146,7 @@ const validate = (bsConfig, args) => {
142146
} catch(error){
143147
reject(Constants.validationMessages.INVALID_CYPRESS_JSON)
144148
}
145-
146-
resolve(Constants.validationMessages.VALIDATED);
149+
resolve(cypressJson);
147150
});
148151
}
149152

bin/helpers/config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,7 @@ config.cypress_v1 = `${config.rails_host}/automate/cypress/v1`;
1616
config.buildUrl = `${config.cypress_v1}/builds/`;
1717
config.buildStopUrl = `${config.cypress_v1}/builds/stop/`;
1818
config.fileName = "tests.zip";
19+
config.retries = 5;
20+
config.networkErrorExitCode = 2;
1921

2022
module.exports = config;

0 commit comments

Comments
 (0)