Skip to content

Commit b696361

Browse files
committed
adding stacktrace on cli and prettifying
1 parent 673b7cb commit b696361

File tree

4 files changed

+31
-38
lines changed

4 files changed

+31
-38
lines changed

bin/commands/runs.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const archiver = require("../helpers/archiver"),
1919
downloadBuildStacktrace = require('../helpers/downloadBuildStacktrace').downloadBuildStacktrace,
2020
updateNotifier = require('update-notifier'),
2121
pkg = require('../../package.json');
22+
const { getStackTraceUrl } = require('../helpers/sync/syncSpecsLogs');
2223

2324
module.exports = function run(args, rawArgs) {
2425
let bsConfigPath = utils.getConfigPath(args.cf);
@@ -172,7 +173,6 @@ module.exports = function run(args, rawArgs) {
172173
if (args.sync) {
173174
syncRunner.pollBuildStatus(bsConfig, data, rawArgs).then(async (exitCode) => {
174175

175-
console.log(`roshan1: the exit code is ${exitCode} :: ${config.buildFailedExitCode}`)
176176
// stop the Local instance
177177
await utils.stopLocalBinary(bsConfig, bs_local, args, rawArgs);
178178

@@ -190,6 +190,11 @@ module.exports = function run(args, rawArgs) {
190190
utils.sendUsageReport(bsConfig, args, `${message}\n${dashboardLink}`, Constants.messageTypes.SUCCESS, null, buildReportData, rawArgs);
191191
utils.handleSyncExit(exitCode, data.dashboard_url);
192192
});
193+
} else {
194+
let stacktraceUrl = getStackTraceUrl();
195+
await downloadBuildStacktrace(stacktraceUrl);
196+
logger.info(Constants.userMessages.BUILD_FAILED_ERROR)
197+
process.exitCode = Constants.ERROR_EXIT_CODE;
193198
}
194199
});
195200
} else if (utils.nonEmptyArray(bsConfig.run_settings.downloads)) {

bin/helpers/constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ const userMessages = {
6161
DOWNLOAD_BUILD_ARTIFACTS_SUCCESS: "Your build artifact(s) have been successfully downloaded in '<user-path>/build_artifacts/<build-id>' directory",
6262
LATEST_SYNTAX_TO_ACTUAL_VERSION_MESSAGE: "Your build will run using Cypress <actualVersion> as you had specified <latestSyntaxVersion>.<frameworkUpgradeMessage> Read more about supported versions here: http://browserstack.com/docs/automate/cypress/supported-versions",
6363
PROCESS_KILL_MESSAGE: "Stopping the CLI and the execution of the build on BrowserStack",
64+
BUILD_FAILED_ERROR: "The above stacktrace has been thrown by Cypress when we tried to run your build. If your test suite requires npm dependencies then please specify them on browserstack.json. Read more at https://www.browserstack.com/docs/automate/cypress/npm-packages. Also, we recommend you to try running the build locally using ‘cypress run’ and if it works fine then please reach out to support at https://www.browserstack.com/contact#technical-support"
6465
};
6566

6667
const validationMessages = {

bin/helpers/downloadBuildStacktrace.js

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,23 @@
11
'use strict'
2-
3-
const request = require('request');
4-
const { inspect } = require('util');
2+
const fs = require('fs'),
3+
request = require('request'),
4+
{ inspect } = require('util'),
5+
Constants = require("./constants"),
6+
chalk = require('chalk');
57

68
const downloadBuildStacktrace = async (url) => {
7-
let tmpFilePath = path.join("a", "fileName");
8-
const writer = fs.createWriteStream(tmpFilePath);
9+
let writer = fs.createWriteStream('a.txt');
910
return new Promise(async (resolve, reject) => {
10-
request.get(url).on('response', function(response) {
11-
12-
if(response.statusCode != 200) {
13-
reject();
14-
} else {
15-
//ensure that the user can call `then()` only when the file has
16-
//been downloaded entirely.
17-
console.log(`roshan1: the response is ${inspect(response)}`);
18-
response.pipe(writer);
19-
let error = null;
20-
writer.on('error', err => {
21-
error = err;
22-
writer.close();
23-
reject(err);
24-
});
25-
writer.on('close', async () => {
26-
if (!error) {
27-
await unzipFile("a", "fileName");
28-
fs.unlinkSync(tmpFilePath);
29-
resolve(true);
30-
}
31-
//no need to call the reject here, as it will have been called in the
32-
//'error' stream;
33-
});
34-
}
35-
});
11+
request.get(url).on('data', (data) => {
12+
console.log(chalk.bold(data.toString()));
13+
}).on('error', (err) => {
14+
reject();
15+
}).on('end', () => {
16+
let terminalWidth = (process.stdout.columns) * 0.9;
17+
let lineSeparator = "\n" + "-".repeat(terminalWidth);
18+
console.log(lineSeparator)
19+
resolve();
20+
})
3621
});
3722
};
3823

bin/helpers/sync/syncSpecsLogs.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@ const request = require("request"),
99
tableStream = require('table').createStream,
1010
chalk = require('chalk');
1111

12-
const downloadBuildStacktrace = require('../downloadBuildStacktrace').downloadBuildStacktrace
13-
1412
const { inspect } = require('util');
1513
let whileLoop = true, whileTries = config.retries, options, timeout = 3000, n = 2, tableConfig, stream, endTime, startTime = Date.now(), buildStarted = false;
1614
let specSummary = {
15+
"buildError": null,
1716
"specs": [],
1817
"duration": null
1918
}
@@ -108,10 +107,8 @@ let printSpecsStatus = (bsConfig, buildDetails, rawArgs) => {
108107
whileProcess(callback)
109108
},
110109
function(err, result) { // when loop ends
111-
console.log(`roshan1: the error is ${inspect(err)}`)
112110
if (err) {
113111
if(err.status == 204) {
114-
115112
reject(specSummary.exitCode);
116113
} else {
117114
utils.sendUsageReport(bsConfig, {}, `buildId: ${buildDetails.build_id}`, 'error', 'sync_cli_error', err, rawArgs);
@@ -163,15 +160,19 @@ let whileProcess = (whilstCallback) => {
163160
});
164161
}
165162

163+
let getStackTraceUrl = () => {
164+
return specSummary.buildError
165+
}
166+
166167
let showSpecsStatus = (data) => {
167168
let specData = JSON.parse(data);
168169
specData.forEach(specDetails => {
169-
console.log(`specDetails ${inspect(specDetails)}`);
170170
if (specDetails == "created") {
171171
return;
172172
} else if (specDetails["stacktrace_url"]) {
173173
specSummary.exitCode = config.buildFailedExitCode;
174-
downloadBuildStacktrace(specDetails["stacktrace_url"]);
174+
specSummary.buildError = specDetails["stacktrace_url"]
175+
console.log(chalk.bold.red(specDetails["message"]));
175176
} else {
176177
if(!buildStarted) {
177178
buildStarted = true
@@ -226,3 +227,4 @@ let getStatus = (status) => {
226227
}
227228

228229
exports.printSpecsStatus = printSpecsStatus;
230+
exports.getStackTraceUrl = getStackTraceUrl;

0 commit comments

Comments
 (0)