Skip to content

Commit 6d8c43d

Browse files
committed
make changes for --sync
1 parent 3bb6a6b commit 6d8c43d

File tree

4 files changed

+113
-90
lines changed

4 files changed

+113
-90
lines changed

bin/commands/runs.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ module.exports = function run(args) {
5858
// Create build
5959
return build.createBuild(bsConfig, zip).then(function (data) {
6060
let message = `${data.message}! ${Constants.userMessages.BUILD_CREATED} with build id: ${data.build_id}`;
61-
let dashboardLink = `${Constants.userMessages.VISIT_DASHBOARD} ${config.dashboardUrl}${data.build_id}`;
61+
let dashboardLink = `${Constants.userMessages.VISIT_DASHBOARD} ${data.dashboard_url}`;
6262
utils.exportResults(data.build_id, `${config.dashboardUrl}${data.build_id}`);
6363
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)) {
6464
logger.warn(Constants.userMessages.NO_PARALLELS);
@@ -67,17 +67,20 @@ module.exports = function run(args) {
6767
if (!args.disableNpmWarning && bsConfig.run_settings.npm_dependencies && Object.keys(bsConfig.run_settings.npm_dependencies).length <= 0) logger.warn(Constants.userMessages.NO_NPM_DEPENDENCIES);
6868

6969
if (args.sync) {
70-
syncRunner.pollBuildStatus(bsConfig, data.build_id).then((exitCode) => {
70+
syncRunner.pollBuildStatus(bsConfig, bsConfigPath, data).then((exitCode) => {
7171
utils.sendUsageReport(bsConfig, args, `${message}\n${dashboardLink}`, Constants.messageTypes.SUCCESS, null);
7272

7373
process.exit(exitCode);
74+
}).catch((err) => {
75+
logger.error(err);
76+
process.exit(1);
7477
});
78+
} else {
79+
logger.info(message);
80+
logger.info(dashboardLink);
81+
utils.sendUsageReport(bsConfig, args, `${message}\n${dashboardLink}`, Constants.messageTypes.SUCCESS, null);
82+
process.exit(2);
7583
}
76-
77-
logger.info(message);
78-
logger.info(dashboardLink);
79-
utils.sendUsageReport(bsConfig, args, `${message}\n${dashboardLink}`, Constants.messageTypes.SUCCESS, null);
80-
return;
8184
}).catch(function (err) {
8285
// Build creation failed
8386
logger.error(err);

bin/helpers/constants.js

Lines changed: 58 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
const userMessages = {
2-
BUILD_FAILED: "Build creation failed.",
3-
BUILD_CREATED: "Build created",
4-
BUILD_INFO_FAILED: "Failed to get build info.",
5-
BUILD_STOP_FAILED: "Failed to stop build.",
6-
BUILD_REPORT_MESDSAGE: "See the entire build report here:",
7-
ZIP_UPLOADER_NOT_REACHABLE: "Could not reach to zip uploader.",
8-
ZIP_UPLOAD_FAILED: "Zip Upload failed.",
9-
CONFIG_FILE_CREATED: "BrowserStack Config File created, you can now run browserstack-cypress --config-file run",
10-
CONFIG_FILE_EXISTS: "File already exists, delete the browserstack.json file manually. skipping...",
11-
DIR_NOT_FOUND: "Given path does not exist. Failed to create browserstack.json in %s",
12-
ZIP_DELETE_FAILED: "Could not delete local file.",
13-
ZIP_DELETED: "Zip file deleted successfully.",
14-
API_DEPRECATED: "This version of API is deprecated, please use latest version of API.",
15-
FAILED_TO_ZIP: "Failed to zip files.",
16-
VISIT_DASHBOARD: "Visit the Automate dashboard for test reporting:",
17-
CONFLICTING_INIT_ARGUMENTS: "Conflicting arguments given. You can use --path only with a file name, and not with a file path.",
18-
NO_PARALLELS: "Your tests will run sequentially. Read more about running your tests in parallel here: https://www.browserstack.com/docs/automate/cypress/run-tests-in-parallel",
19-
NO_NPM_DEPENDENCIES: "No npm dependencies specified. Read more here: https://www.browserstack.com/docs/automate/cypress/npm-packages. You can suppress this warning by using --disable-npm-warning flag."
2+
BUILD_FAILED: "Build creation failed.",
3+
BUILD_CREATED: "Build created",
4+
BUILD_INFO_FAILED: "Failed to get build info.",
5+
BUILD_STOP_FAILED: "Failed to stop build.",
6+
BUILD_REPORT_MESDSAGE: "See the entire build report here:",
7+
ZIP_UPLOADER_NOT_REACHABLE: "Could not reach to zip uploader.",
8+
ZIP_UPLOAD_FAILED: "Zip Upload failed.",
9+
CONFIG_FILE_CREATED: "BrowserStack Config File created, you can now run browserstack-cypress --config-file run",
10+
CONFIG_FILE_EXISTS: "File already exists, delete the browserstack.json file manually. skipping...",
11+
DIR_NOT_FOUND: "Given path does not exist. Failed to create browserstack.json in %s",
12+
ZIP_DELETE_FAILED: "Could not delete local file.",
13+
ZIP_DELETED: "Zip file deleted successfully.",
14+
API_DEPRECATED: "This version of API is deprecated, please use latest version of API.",
15+
FAILED_TO_ZIP: "Failed to zip files.",
16+
VISIT_DASHBOARD: "Visit the Automate dashboard for test reporting:",
17+
CONFLICTING_INIT_ARGUMENTS: "Conflicting arguments given. You can use --path only with a file name, and not with a file path.",
18+
NO_PARALLELS: "Your tests will run sequentially. Read more about running your tests in parallel here: https://www.browserstack.com/docs/automate/cypress/run-tests-in-parallel",
19+
NO_NPM_DEPENDENCIES: "No npm dependencies specified. Read more here: https://www.browserstack.com/docs/automate/cypress/npm-packages. You can suppress this warning by using --disable-npm-warning flag."
2020
};
2121

2222
const validationMessages = {
@@ -40,45 +40,46 @@ const validationMessages = {
4040
};
4141

4242
const cliMessages = {
43-
VERSION: {
44-
INFO: "shows version information",
45-
HELP: "Specify --help for available options",
46-
DEMAND: "Requires init, run or poll argument"
47-
},
48-
INIT: {
49-
INFO: "create a browserstack.json file in the folder specified with the default configuration options.",
50-
DESC: "Init in a specified folder"
51-
},
52-
BUILD: {
53-
INFO: "Check status of your build.",
54-
STOP: "Stop your build.",
55-
DEMAND: "Requires a build id.",
56-
DESC: "Path to BrowserStack config",
57-
CONFIG_DEMAND: "config file is required",
58-
INFO_MESSAGE: "Getting information for buildId ",
59-
STOP_MESSAGE: "Stopping build with given buildId "
60-
},
61-
RUN: {
62-
PARALLEL_DESC: "The maximum number of parallels to use to run your test suite",
63-
INFO: "Run your tests on BrowserStack.",
64-
DESC: "Path to BrowserStack config",
65-
CYPRESS_DESC: "Path to Cypress config file",
66-
CONFIG_DEMAND: "config file is required",
67-
CYPRESS_CONFIG_DEMAND: "Cypress config file is required",
68-
BUILD_NAME: "The build name you want to use to name your test runs",
69-
EXCLUDE: "Exclude files matching a pattern from zipping and uploading",
70-
DEFAULT_PARALLEL_MESSAGE: "Here goes the number of parallels you want to run",
71-
SPECS_DESCRIPTION: 'Specify the spec files to run',
72-
ENV_DESCRIPTION: "Specify the environment variables for your spec files",
73-
SYNC_DESCRIPTION: "Makes the run command in sync"
74-
},
75-
COMMON: {
76-
DISABLE_USAGE_REPORTING: "Disable usage reporting",
77-
USERNAME: "Your BrowserStack username",
78-
ACCESS_KEY: "Your BrowserStack access key",
79-
NO_NPM_WARNING: "No NPM warning if npm_dependencies is empty"
80-
}
81-
}
43+
VERSION: {
44+
INFO: "shows version information",
45+
HELP: "Specify --help for available options",
46+
DEMAND: "Requires init, run or poll argument",
47+
},
48+
INIT: {
49+
INFO: "create a browserstack.json file in the folder specified with the default configuration options.",
50+
DESC: "Init in a specified folder",
51+
},
52+
BUILD: {
53+
INFO: "Check status of your build.",
54+
STOP: "Stop your build.",
55+
DEMAND: "Requires a build id.",
56+
DESC: "Path to BrowserStack config",
57+
CONFIG_DEMAND: "config file is required",
58+
INFO_MESSAGE: "Getting information for buildId ",
59+
STOP_MESSAGE: "Stopping build with given buildId ",
60+
},
61+
RUN: {
62+
PARALLEL_DESC: "The maximum number of parallels to use to run your test suite",
63+
INFO: "Run your tests on BrowserStack.",
64+
DESC: "Path to BrowserStack config",
65+
CYPRESS_DESC: "Path to Cypress config file",
66+
CONFIG_DEMAND: "config file is required",
67+
CYPRESS_CONFIG_DEMAND: "Cypress config file is required",
68+
BUILD_NAME: "The build name you want to use to name your test runs",
69+
EXCLUDE: "Exclude files matching a pattern from zipping and uploading",
70+
DEFAULT_PARALLEL_MESSAGE: "Here goes the number of parallels you want to run",
71+
SPECS_DESCRIPTION: "Specify the spec files to run",
72+
ENV_DESCRIPTION: "Specify the environment variables for your spec files",
73+
SYNC_DESCRIPTION: "Makes the run command in sync",
74+
BUILD_REPORT_MESSAGE: "See the entire build report here",
75+
},
76+
COMMON: {
77+
DISABLE_USAGE_REPORTING: "Disable usage reporting",
78+
USERNAME: "Your BrowserStack username",
79+
ACCESS_KEY: "Your BrowserStack access key",
80+
NO_NPM_WARNING: "No NPM warning if npm_dependencies is empty",
81+
},
82+
};
8283

8384
const messageTypes = {
8485
SUCCESS: "success",

bin/helpers/syncRunner.js

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,43 +5,62 @@ const config = require("./config"),
55
utils = require("./utils"),
66
request = require('request');
77

8-
exports.pollBuildStatus = (bsConfig, buildId) => {
9-
logBuildDetails().then((data) => {
10-
printSpecsStatus();
11-
}).then((data) => {
12-
printSpecsRunSummary();
13-
}).then((data) => {
14-
printFailedSpecsDetails();
15-
}).then((data) => {
16-
printBuildDashboardLink(buildId);
17-
}).then((data) => {
18-
// success case!
19-
return 0; // exit code 0
20-
}).catch((err) => {
21-
// failed case!
22-
return 1; // exit code 1
23-
});
8+
exports.pollBuildStatus = (bsConfig, bsConfigPath, buildDetails) => {
9+
return new Promise(function (resolve, reject) {
10+
logBuildDetails(bsConfig, bsConfigPath, buildDetails);
11+
printSpecsStatus()
12+
.then((data) => {
13+
printSpecsRunSummary();
14+
})
15+
.then((data) => {
16+
printFailedSpecsDetails();
17+
})
18+
.then((data) => {
19+
printBuildDashboardLink(buildDetails.dashboard_url);
20+
// success case!
21+
resolve(0); // exit code 0
22+
})
23+
.catch((err) => {
24+
// failed case!
25+
reject(err); // exit code 1
26+
});
27+
});
2428
};
2529

26-
let logBuildDetails = () => {
30+
let logBuildDetails = (bsConfig, bsConfigPath, buildDetails) => {
31+
let parallels_enabled = false;
32+
if (bsConfig.run_settings.parallels) {
33+
parallels_enabled = true;
34+
}
35+
let parallelMessage = `Run in parallel: ${parallels_enabled ? 'enabled' : 'disabled'}`;
36+
if (parallels_enabled) parallelMessage = parallelMessage + `(attempting to run on ${buildDetails.machines} machines)`;
2737

38+
// logger.info(`Configuration file: ${bsConfigPath}`);
39+
// logger.info(`Cypress config file: ${bsConfig.run_settings.cypress_config_file}`);
40+
// logger.info(`Local connection: ${bsConfig.connection_settings.local ? 'enabled' : 'disabled'}`);
41+
logger.info(`Browser Combinations: ${buildDetails.combinations}`);
42+
logger.info(parallelMessage);
43+
logger.info(`BrowserStack Dashboard: ${buildDetails.dashboard_url}`);
2844
};
2945

3046
let printSpecsStatus = () => {
31-
47+
return new Promise(function (resolve, reject) {
48+
resolve();
49+
});
3250
};
3351

3452
let printSpecsRunSummary = () => {
35-
53+
return new Promise(function (resolve, reject) {
54+
resolve();
55+
});
3656
};
3757

3858
let printFailedSpecsDetails = () => {
39-
59+
return new Promise(function (resolve, reject) {
60+
resolve();
61+
});
4062
};
4163

42-
let printBuildDashboardLink = (buildId) => {
43-
new Promise((resolve, reject) => {
44-
logger.info(Constants.userMessages.BUILD_REPORT_MESSAGE);
45-
logger.info(`${config.dashboardUrl}${buildId}`);
46-
});
64+
let printBuildDashboardLink = (dashboardUrl) => {
65+
logger.info(`${Constants.cliMessages.RUN.BUILD_REPORT_MESSAGE}: ${dashboardUrl}`);
4766
};

bin/runner.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ var argv = yargs
198198
},
199199
'sync': {
200200
default: false,
201-
describe: Constants.cliMessages.SYNC_DESCRIPTION,
201+
describe: Constants.cliMessages.RUN.SYNC_DESCRIPTION,
202202
type: "boolean"
203203
}
204204
})

0 commit comments

Comments
 (0)