Skip to content

Commit fa323b1

Browse files
Sync Cli Log Changes
1 parent 0a07c6a commit fa323b1

File tree

9 files changed

+59
-36
lines changed

9 files changed

+59
-36
lines changed

bin/commands/runs.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ const archiver = require("../helpers/archiver"),
88
Constants = require("../helpers/constants"),
99
utils = require("../helpers/utils"),
1010
fileHelpers = require("../helpers/fileHelpers"),
11-
syncRunner = require("../helpers/syncRunner");
11+
syncRunner = require("../helpers/syncRunner"),
12+
syncCliLogger = require("../helpers/logger").syncCliLogger;
1213

1314
module.exports = function run(args) {
1415
let bsConfigPath = utils.getConfigPath(args.cf);
@@ -44,7 +45,7 @@ module.exports = function run(args) {
4445

4546
// Validate browserstack.json values and parallels specified via arguments
4647
return capabilityHelper.validate(bsConfig, args).then(function (validated) {
47-
logger.info(validated);
48+
// logger.info(validated);
4849

4950
// accept the number of parallels
5051
utils.setParallels(bsConfig, args);
@@ -54,7 +55,6 @@ module.exports = function run(args) {
5455

5556
// Uploaded zip file
5657
return zipUploader.zipUpload(bsConfig, config.fileName).then(function (zip) {
57-
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}`;
@@ -64,19 +64,22 @@ module.exports = function run(args) {
6464
logger.warn(Constants.userMessages.NO_PARALLELS);
6565
}
6666

67-
if (!args.disableNpmWarning && bsConfig.run_settings.npm_dependencies && Object.keys(bsConfig.run_settings.npm_dependencies).length <= 0) logger.warn(Constants.userMessages.NO_NPM_DEPENDENCIES);
68-
67+
if (!args.disableNpmWarning && bsConfig.run_settings.npm_dependencies && Object.keys(bsConfig.run_settings.npm_dependencies).length <= 0) {
68+
logger.warn(Constants.userMessages.NO_NPM_DEPENDENCIES);
69+
logger.warn(Constants.userMessages.NO_NPM_DEPENDENCIES_READ_MORE);
70+
}
6971
if (args.sync) {
7072
syncRunner.pollBuildStatus(bsConfig, data).then((exitCode) => {
7173
utils.sendUsageReport(bsConfig, args, `${message}\n${dashboardLink}`, Constants.messageTypes.SUCCESS, null);
72-
logger.info(Constants.userMessages.BUILD_REPORT_MESSAGE);
73-
logger.info(data.dashboard_url)
74+
syncCliLogger.info(Constants.userMessages.BUILD_REPORT_MESSAGE);
75+
syncCliLogger.info(data.dashboard_url);
7476
process.exit(exitCode);
7577
});
7678
}
7779

7880
logger.info(message);
7981
logger.info(dashboardLink);
82+
if(!args.sync) logger.info(Constants.userMessages.EXIT_SYNC_CLI_MESSAGE.replace("<build-id>",data.build_id));
8083
utils.sendUsageReport(bsConfig, args, `${message}\n${dashboardLink}`, Constants.messageTypes.SUCCESS, null);
8184
return;
8285
}).catch(function (err) {
@@ -88,9 +91,8 @@ module.exports = function run(args) {
8891
// Zip Upload failed
8992
logger.error(err);
9093
logger.error(Constants.userMessages.ZIP_UPLOAD_FAILED);
91-
utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.userMessages.ZIP_UPLOAD_FAILED}`, Constants.messageTypes.ERROR, 'zip_upload_failed');
92-
}).finally(function () {
9394
fileHelpers.deleteZip();
95+
utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.userMessages.ZIP_UPLOAD_FAILED}`, Constants.messageTypes.ERROR, 'zip_upload_failed');
9496
});
9597
}).catch(function (err) {
9698
// Zipping failed

bin/helpers/archiver.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ 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', {
1719
zlib: { level: 9 } // Sets the compression level.
1820
});

bin/helpers/capabilityHelper.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,19 @@ const caps = (bsConfig, zip) => {
3030
}
3131
obj.devices = osBrowserArray;
3232
if (obj.devices.length == 0) reject(Constants.validationMessages.EMPTY_BROWSER_LIST);
33-
logger.info(`Browser list: ${osBrowserArray.toString()}`);
33+
logger.info(`Browsers list: ${osBrowserArray.toString()}`);
3434

3535
// Test suite
3636
if (zip.zip_url && zip.zip_url.split("://")[1].length !== 0) {
3737
obj.test_suite = zip.zip_url.split("://")[1];
3838
} else {
3939
reject("Test suite is empty");
4040
}
41-
logger.info(`Test suite: bs://${obj.test_suite}`);
4241

4342
// Local
4443
obj.local = false;
4544
if (bsConfig.connection_settings && bsConfig.connection_settings.local === true) obj.local = true;
46-
logger.info(`Local is set to: ${obj.local}`);
45+
logger.info(`Local is set to: ${obj.local} (${obj.local ? Constants.userMessages.LOCAL_TRUE : Constants.userMessages.LOCAL_FALSE})`);
4746

4847
// Local Identifier
4948
obj.localIdentifier = null;
@@ -100,6 +99,7 @@ const caps = (bsConfig, zip) => {
10099

101100
const validate = (bsConfig, args) => {
102101
return new Promise(function (resolve, reject) {
102+
logger.info(Constants.userMessages.VALIDATING_CONFIG);
103103
if (!bsConfig) reject(Constants.validationMessages.EMPTY_BROWSERSTACK_JSON);
104104

105105
if (!bsConfig.auth) reject(Constants.validationMessages.INCORRECT_AUTH_PARAMS);

bin/helpers/constants.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const syncCLI = {
22
FAILED_SPEC_DETAILS_COL_HEADER: ['Spec', 'Status', 'Browser', 'BrowserStack Session ID'],
33
LOGS: {
4-
INIT_LOG: "Running Tests: ..."
4+
INIT_LOG: "All tests:"
55
},
66
INITIAL_DELAY_MULTIPLIER: 10
77
};
@@ -17,14 +17,20 @@ const userMessages = {
1717
CONFIG_FILE_CREATED: "BrowserStack Config File created, you can now run browserstack-cypress --config-file run",
1818
CONFIG_FILE_EXISTS: "File already exists, delete the browserstack.json file manually. skipping...",
1919
DIR_NOT_FOUND: "Given path does not exist. Failed to create browserstack.json in %s",
20-
ZIP_DELETE_FAILED: "Could not delete local file.",
21-
ZIP_DELETED: "Zip file deleted successfully.",
20+
ZIP_DELETE_FAILED: "Could not delete tests.zip successfully.",
21+
ZIP_DELETED: "Deleted tests.zip successfully.",
2222
API_DEPRECATED: "This version of API is deprecated, please use latest version of API.",
2323
FAILED_TO_ZIP: "Failed to zip files.",
24-
VISIT_DASHBOARD: "Visit the Automate dashboard for test reporting:",
24+
VISIT_DASHBOARD: "Visit the Automate dashboard for real-time test reporting:",
2525
CONFLICTING_INIT_ARGUMENTS: "Conflicting arguments given. You can use --path only with a file name, and not with a file path.",
26-
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",
27-
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."
26+
NO_PARALLELS: "Your specs will run sequentially on a single machine. Read more about running your specs in parallel here: https://www.browserstack.com/docs/automate/cypress/run-tests-in-parallel",
27+
NO_NPM_DEPENDENCIES: "No npm dependencies specified - your specs might fail if they need any packages to be installed before running.",
28+
NO_NPM_DEPENDENCIES_READ_MORE: "Read more about npm dependencies here: https://www.browserstack.com/docs/automate/cypress/npm-packages. You can suppress this warning by using --disable-npm-warning flag.",
29+
VALIDATING_CONFIG: "Validating the config",
30+
UPLOADING_TESTS: "Uploading the tests to BrowserStack",
31+
LOCAL_TRUE: "you will now be able to test localhost / private URLs",
32+
LOCAL_FALSE: "you won't be able to test localhost / private URLs",
33+
EXIT_SYNC_CLI_MESSAGE: "Exiting the CLI, but your build is still running. You can use the --sync option to keep getting test updates. You can also use the build-info <build-id> command now."
2834
};
2935

3036
const validationMessages = {

bin/helpers/sync/failedSpecsDetails.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ const tablePrinter = require('table'), // { table, getBorderCharacters }
1919
//
2020
let failedSpecsDetails = (data) => {
2121
return new Promise((resolve, reject) => {
22-
if (data.length === 0) resolve(0); // return if no failed/skipped tests.
22+
data.exitCode = 0;
23+
if (data.specs.length === 0) resolve(data); // return if no failed/skipped tests.
2324

2425
let failedSpecs = false;
2526
let specResultHeader = Constants.syncCLI.FAILED_SPEC_DETAILS_COL_HEADER.map((col) => {
@@ -28,16 +29,23 @@ let failedSpecsDetails = (data) => {
2829

2930
let specData = [specResultHeader]; // 2-D array
3031

31-
data.forEach((spec) => {
32+
data.specs.forEach((spec) => {
3233
if (spec.status.toLowerCase() === 'passed') {
3334
return;
3435
}
3536
if (spec.status && spec.status.toLowerCase() === 'failed' && !failedSpecs)
3637
failedSpecs = true;
3738

38-
let specStatus = (spec.status && spec.status.toLowerCase() === 'failed') ?
39-
chalk.red(spec.status) : chalk.yellow(spec.status);
40-
specData.push([spec.specName, specStatus, spec.combination, spec.sessionId]);
39+
let specStatus =
40+
spec.status && spec.status.toLowerCase() === 'failed'
41+
? chalk.red(spec.status)
42+
: chalk.yellow(spec.status);
43+
specData.push([
44+
spec.specName,
45+
specStatus,
46+
spec.combination,
47+
spec.sessionId,
48+
]);
4149
});
4250

4351
let config = {
@@ -61,11 +69,11 @@ let failedSpecsDetails = (data) => {
6169

6270
let result = tablePrinter.table(specData, config);
6371

64-
logger.info('Failed / skipped test report');
72+
logger.info('\nFailed / skipped test report:');
6573
logger.info(result);
6674

67-
if (failedSpecs) reject(1); // specs failed, send exitCode as 1
68-
resolve(0); // No Specs failed, maybe skipped, but not failed, send exitCode as 0
75+
if (failedSpecs) data.exitCode = 1 ; // specs failed, send exitCode as 1
76+
resolve(data); // No Specs failed, maybe skipped, but not failed, send exitCode as 0
6977
});
7078
}
7179

bin/helpers/sync/specsSummary.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const logger = require("../logger").syncCliLogger;
1616
// {specName: 'spec8.alias.js', status: 'Skipped', combination: 'Win 10 / Chrome 78', sessionId: '3d3rdf3r...'}
1717
// ]
1818
//
19-
let printSpecsRunSummary = (data, time, machines) => {
19+
let printSpecsRunSummary = (data, machines) => {
2020
return new Promise((resolve, _reject) => {
2121
let summary = {
2222
total: 0,
@@ -25,14 +25,14 @@ let printSpecsRunSummary = (data, time, machines) => {
2525
skipped: 0
2626
};
2727

28-
data.forEach((spec) => {
28+
data.specs.forEach((spec) => {
2929
specSummaryCount(summary, spec.status.toLowerCase());
3030
});
3131

3232
logger.info(`Total tests: ${summary.total}, passed: ${summary.passed}, failed: ${summary.failed}, skipped: ${summary.skipped}`);
33-
logger.info(`Done in ${time/1000} seconds using ${machines} machines\n`);
33+
logger.info(`Done in ${data.duration/1000} seconds using ${machines} machines\n`);
3434

35-
resolve(data);
35+
resolve(data.exitCode);
3636
})
3737
};
3838

bin/helpers/sync/syncSpecsLogs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ let showSpecsStatus = (data) => {
126126

127127
let printInitialLog = () => {
128128
startTime = Date.now();
129-
logger.info(Constants.syncCLI.LOGS.INIT_LOG)
129+
logger.info(`\n${Constants.syncCLI.LOGS.INIT_LOG}`)
130130
n = Constants.syncCLI.INITIAL_DELAY_MULTIPLIER
131131
}
132132

bin/helpers/syncRunner.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ const Config = require("./config"),
1212

1313
exports.pollBuildStatus = (bsConfig, buildDetails) => {
1414
return new Promise((resolve, reject) => {
15-
logBuildDetails(bsConfig, buildDetails);
15+
//logBuildDetails(bsConfig, buildDetails);
1616
syncSpecsLogs.printSpecsStatus(bsConfig, buildDetails).then((data) => {
17-
return specsSummary.printSpecsRunSummary(data.specs, data.duration, buildDetails.machines);
18-
}).then((data) => {
1917
return specDetails.failedSpecsDetails(data);
18+
// return specsSummary.printSpecsRunSummary(data.specs, data.duration, buildDetails.machines);
19+
}).then((data) => {
20+
return specsSummary.printSpecsRunSummary(data, buildDetails.machines);
21+
// return specDetails.failedSpecsDetails(data);
2022
}).then((successExitCode) => {
2123
resolve(successExitCode); // exit code 0
2224
}).catch((nonZeroExitCode) => {

bin/helpers/zipUpload.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ const config = require("./config"),
44
fs = require("fs"),
55
logger = require("./logger").winstonLogger,
66
Constants = require("./constants"),
7-
utils = require("./utils");
7+
utils = require("./utils"),
8+
fileHelpers = require("./fileHelpers");
89

910
const uploadCypressZip = (bsConfig, filePath) => {
1011
return new Promise(function (resolve, reject) {
12+
logger.info(Constants.userMessages.UPLOADING_TESTS);
1113
let options = {
1214
url: config.uploadUrl,
1315
auth: {
@@ -41,7 +43,8 @@ const uploadCypressZip = (bsConfig, filePath) => {
4143
reject(Constants.userMessages.ZIP_UPLOADER_NOT_REACHABLE);
4244
}
4345
} else {
44-
logger.info(`Zip uploaded with url: ${responseData.zip_url}`);
46+
logger.info(`Uploaded tests successfully (${responseData.zip_url})`);
47+
fileHelpers.deleteZip();
4548
resolve(responseData);
4649
}
4750
}

0 commit comments

Comments
 (0)