Skip to content

Commit e616c67

Browse files
Merge pull request #70 from browserstack/CYP_442_sync_cli_part_1
CYP-442 sync cli part 1
2 parents 6c86641 + 231812b commit e616c67

File tree

6 files changed

+148
-70
lines changed

6 files changed

+148
-70
lines changed

bin/commands/runs.js

Lines changed: 2 additions & 3 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,9 +67,8 @@ 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, data).then((exitCode) => {
7171
utils.sendUsageReport(bsConfig, args, `${message}\n${dashboardLink}`, Constants.messageTypes.SUCCESS, null);
72-
7372
process.exit(exitCode);
7473
});
7574
}

bin/helpers/constants.js

Lines changed: 58 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,24 @@ const syncCLI = {
33
};
44

55
const userMessages = {
6-
BUILD_FAILED: "Build creation failed.",
7-
BUILD_CREATED: "Build created",
8-
BUILD_INFO_FAILED: "Failed to get build info.",
9-
BUILD_STOP_FAILED: "Failed to stop build.",
10-
BUILD_REPORT_MESSAGE: "See the entire build report here:",
11-
ZIP_UPLOADER_NOT_REACHABLE: "Could not reach to zip uploader.",
12-
ZIP_UPLOAD_FAILED: "Zip Upload failed.",
13-
CONFIG_FILE_CREATED: "BrowserStack Config File created, you can now run browserstack-cypress --config-file run",
14-
CONFIG_FILE_EXISTS: "File already exists, delete the browserstack.json file manually. skipping...",
15-
DIR_NOT_FOUND: "Given path does not exist. Failed to create browserstack.json in %s",
16-
ZIP_DELETE_FAILED: "Could not delete local file.",
17-
ZIP_DELETED: "Zip file deleted successfully.",
18-
API_DEPRECATED: "This version of API is deprecated, please use latest version of API.",
19-
FAILED_TO_ZIP: "Failed to zip files.",
20-
VISIT_DASHBOARD: "Visit the Automate dashboard for test reporting:",
21-
CONFLICTING_INIT_ARGUMENTS: "Conflicting arguments given. You can use --path only with a file name, and not with a file path.",
22-
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",
23-
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."
6+
BUILD_FAILED: "Build creation failed.",
7+
BUILD_CREATED: "Build created",
8+
BUILD_INFO_FAILED: "Failed to get build info.",
9+
BUILD_STOP_FAILED: "Failed to stop build.",
10+
BUILD_REPORT_MESSAGE: "See the entire build report here:",
11+
ZIP_UPLOADER_NOT_REACHABLE: "Could not reach to zip uploader.",
12+
ZIP_UPLOAD_FAILED: "Zip Upload failed.",
13+
CONFIG_FILE_CREATED: "BrowserStack Config File created, you can now run browserstack-cypress --config-file run",
14+
CONFIG_FILE_EXISTS: "File already exists, delete the browserstack.json file manually. skipping...",
15+
DIR_NOT_FOUND: "Given path does not exist. Failed to create browserstack.json in %s",
16+
ZIP_DELETE_FAILED: "Could not delete local file.",
17+
ZIP_DELETED: "Zip file deleted successfully.",
18+
API_DEPRECATED: "This version of API is deprecated, please use latest version of API.",
19+
FAILED_TO_ZIP: "Failed to zip files.",
20+
VISIT_DASHBOARD: "Visit the Automate dashboard for test reporting:",
21+
CONFLICTING_INIT_ARGUMENTS: "Conflicting arguments given. You can use --path only with a file name, and not with a file path.",
22+
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",
23+
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."
2424
};
2525

2626
const validationMessages = {
@@ -44,45 +44,46 @@ const validationMessages = {
4444
};
4545

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

8788
const messageTypes = {
8889
SUCCESS: "success",

bin/helpers/syncRunner.js

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ const Config = require("./config"),
99
{ table, getBorderCharacters } = require('table'),
1010
chalk = require('chalk');
1111

12-
exports.pollBuildStatus = (bsConfig, buildId) => {
13-
logBuildDetails().then((data) => {
14-
printSpecsStatus();
15-
}).then((data) => {
12+
exports.pollBuildStatus = (bsConfig, buildDetails) => {
13+
logBuildDetails(bsConfig, buildDetails);
14+
printSpecsStatus().then((data) => {
1615
return specsSummary.printSpecsRunSummary(data.specs, data.time, data.machines);
1716
}).then((data) => {
1817
return specDetails.failedSpecsDetails(data);
@@ -22,20 +21,33 @@ exports.pollBuildStatus = (bsConfig, buildId) => {
2221
return resolveExitCode(nonZeroExitCode); // exit code 1
2322
}).finally(() => {
2423
logger.info(Constants.userMessages.BUILD_REPORT_MESSAGE);
25-
logger.info(`${Config.dashboardUrl}${buildId}`);
24+
logger.info(`${Config.dashboardUrl}${buildDetails.dashboard_url}`);
2625
});
2726
};
2827

29-
let logBuildDetails = () => {
30-
28+
let logBuildDetails = (bsConfig, buildDetails) => {
29+
let parallels_enabled = false;
30+
if (bsConfig.run_settings.parallels) {
31+
parallels_enabled = true;
32+
}
33+
let parallelMessage = `Run in parallel: ${parallels_enabled ? 'enabled' : 'disabled'}`;
34+
if (parallels_enabled) parallelMessage = parallelMessage + ` (attempting to run on ${buildDetails.machines} machines)`;
35+
36+
logger.info(`Browser Combinations: ${buildDetails.combinations}`);
37+
logger.info(parallelMessage);
38+
logger.info(`BrowserStack Dashboard: ${buildDetails.dashboard_url}`);
3139
};
3240

3341
let printSpecsStatus = () => {
34-
42+
return new Promise(function (resolve, reject) {
43+
resolve();
44+
});
3545
};
3646

3747
let printSpecsRunSummary = () => {
38-
48+
return new Promise(function (resolve, reject) {
49+
resolve();
50+
});
3951
};
4052

4153
let resolveExitCode = (exitCode) => {

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
})

test/unit/bin/helpers/syncRunner.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
const chai = require("chai"),
2+
sinon = require("sinon"),
3+
chaiAsPromised = require("chai-as-promised"),
4+
rewire = require("rewire");
5+
6+
const logger = require("../../../../bin/helpers/logger").syncCliLogger,
7+
testObjects = require("../../support/fixtures/testObjects");
8+
9+
const syncRunner = rewire("../../../../bin/helpers/syncRunner");
10+
11+
chai.use(chaiAsPromised);
12+
13+
logBuildDetails = syncRunner.__get__("logBuildDetails");
14+
15+
describe("syncRunner", () => {
16+
var sandbox, loggerStub;
17+
18+
beforeEach(() => {
19+
sandbox = sinon.createSandbox();
20+
loggerStub = sinon.stub(logger, "log").callsFake(() => {});
21+
});
22+
23+
afterEach(() => {
24+
sandbox.restore();
25+
sinon.restore();
26+
});
27+
28+
describe("logBuildDetails", () => {
29+
let buildDetails = {
30+
machines: 10,
31+
combinations: 5,
32+
dashboard_url: "random_url",
33+
};
34+
35+
it("parallels defined", () => {
36+
logBuildDetails(testObjects.sampleBsConfigWithParallels, buildDetails);
37+
38+
sinon.assert.calledThrice(loggerStub);
39+
sinon.assert.calledWithMatch(loggerStub, 'info', `Browser Combinations: ${buildDetails.combinations}`);
40+
sinon.assert.calledWithMatch(loggerStub, 'info', `Run in parallel: enabled (attempting to run on ${buildDetails.machines} machines)`);
41+
sinon.assert.calledWithMatch(loggerStub, 'info', `BrowserStack Dashboard: ${buildDetails.dashboard_url}`);
42+
});
43+
it("parallels not defined", () => {
44+
logBuildDetails(testObjects.sampleBsConfig, buildDetails);
45+
46+
sinon.assert.calledThrice(loggerStub);
47+
sinon.assert.calledWithMatch(loggerStub, 'info', `Browser Combinations: ${buildDetails.combinations}`);
48+
sinon.assert.calledWithMatch(loggerStub, 'info', `Run in parallel: disabled`);
49+
sinon.assert.calledWithMatch(loggerStub, 'info', `BrowserStack Dashboard: ${buildDetails.dashboard_url}`);
50+
});
51+
});
52+
});

test/unit/support/fixtures/testObjects.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@ const sampleBsConfig = {
1010
}
1111
};
1212

13+
const sampleBsConfigWithParallels = {
14+
auth: {
15+
username: "random-username",
16+
access_key: "random-access-key",
17+
},
18+
run_settings: {
19+
cypress_proj_dir: "random path",
20+
cypressConfigFilePath: "random path",
21+
cypressProjectDir: "random path",
22+
parallels: 10,
23+
},
24+
};
25+
1326
const initSampleArgs = {
1427
_: ["init"],
1528
p: false,
@@ -114,6 +127,7 @@ const runSampleArgs = {
114127

115128
module.exports = Object.freeze({
116129
sampleBsConfig,
130+
sampleBsConfigWithParallels,
117131
initSampleArgs,
118132
buildInfoSampleArgs,
119133
buildInfoSampleBody,

0 commit comments

Comments
 (0)