Skip to content

Commit bc90d98

Browse files
Merge pull request #181 from roshan04/Cypress_cli_instrumentation_raw_logs
Cypress cli instrumentation raw logs
2 parents 79bc657 + 84c724a commit bc90d98

File tree

19 files changed

+204
-131
lines changed

19 files changed

+204
-131
lines changed

bin/commands/generateDownloads.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const logger = require("../helpers/logger").winstonLogger,
66
downloadBuildArtifacts = require('../helpers/buildArtifacts').downloadBuildArtifacts;
77

88

9-
module.exports = async function generateDownloads(args) {
9+
module.exports = async function generateDownloads(args, rawArgs) {
1010
let bsConfigPath = utils.getConfigPath(args.cf);
1111

1212
return utils.validateBstackJson(bsConfigPath).then(async function (bsConfig) {
@@ -28,12 +28,12 @@ module.exports = async function generateDownloads(args) {
2828
let errorCode = null;
2929
let buildId = args._[1];
3030

31-
await downloadBuildArtifacts(bsConfig, buildId, args);
32-
utils.sendUsageReport(bsConfig, args, Constants.usageReportingConstants.GENERATE_DOWNLOADS, messageType, errorCode);
31+
await downloadBuildArtifacts(bsConfig, buildId, args, rawArgs);
32+
utils.sendUsageReport(bsConfig, args, Constants.usageReportingConstants.GENERATE_DOWNLOADS, messageType, errorCode, null, rawArgs);
3333
}).catch(function (err) {
3434
logger.error(err);
3535
utils.setUsageReportingFlag(null, args.disableUsageReporting);
36-
utils.sendUsageReport(null, args, err.message, Constants.messageTypes.ERROR, utils.getErrorCodeFromErr(err));
36+
utils.sendUsageReport(null, args, err.message, Constants.messageTypes.ERROR, utils.getErrorCodeFromErr(err), null, rawArgs);
3737
process.exitCode = Constants.ERROR_EXIT_CODE;
3838
});
3939
};

bin/commands/generateReport.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const logger = require("../helpers/logger").winstonLogger,
66
reporterHTML = require('../helpers/reporterHTML');
77

88

9-
module.exports = function generateReport(args) {
9+
module.exports = function generateReport(args, rawArgs) {
1010
let bsConfigPath = utils.getConfigPath(args.cf);
1111
let reportGenerator = reporterHTML.reportGenerator;
1212

@@ -29,12 +29,12 @@ module.exports = function generateReport(args) {
2929
let errorCode = null;
3030
let buildId = args._[1];
3131

32-
reportGenerator(bsConfig, buildId, args);
33-
utils.sendUsageReport(bsConfig, args, 'generate-report called', messageType, errorCode);
32+
reportGenerator(bsConfig, buildId, args, rawArgs);
33+
utils.sendUsageReport(bsConfig, args, 'generate-report called', messageType, errorCode, null, rawArgs);
3434
}).catch(function (err) {
3535
logger.error(err);
3636
utils.setUsageReportingFlag(null, args.disableUsageReporting);
37-
utils.sendUsageReport(null, args, err.message, Constants.messageTypes.ERROR, utils.getErrorCodeFromErr(err));
37+
utils.sendUsageReport(null, args, err.message, Constants.messageTypes.ERROR, utils.getErrorCodeFromErr(err), null, rawArgs);
3838
process.exitCode = Constants.ERROR_EXIT_CODE;
3939
});
4040
};

bin/commands/info.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const config = require("../helpers/config"),
66
Constants = require("../helpers/constants"),
77
utils = require("../helpers/utils");
88

9-
module.exports = function info(args) {
9+
module.exports = function info(args, rawArgs) {
1010
let bsConfigPath = utils.getConfigPath(args.cf);
1111

1212
return utils.validateBstackJson(bsConfigPath).then(function (bsConfig) {
@@ -90,12 +90,12 @@ module.exports = function info(args) {
9090
logger.info(message);
9191
}
9292
}
93-
utils.sendUsageReport(bsConfig, args, message, messageType, errorCode);
93+
utils.sendUsageReport(bsConfig, args, message, messageType, errorCode, null, rawArgs);
9494
});
9595
}).catch(function (err) {
9696
logger.error(err);
9797
utils.setUsageReportingFlag(null, args.disableUsageReporting);
98-
utils.sendUsageReport(null, args, err.message, Constants.messageTypes.ERROR, utils.getErrorCodeFromErr(err));
98+
utils.sendUsageReport(null, args, err.message, Constants.messageTypes.ERROR, utils.getErrorCodeFromErr(err), null, rawArgs);
9999
process.exitCode = Constants.ERROR_EXIT_CODE;
100100
})
101101
}

bin/commands/init.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ const fileHelpers = require("../helpers/fileHelpers"),
77
path = require('path');
88

99

10-
function get_path(args) {
10+
function get_path(args, rawArgs) {
1111
if (args._.length > 1 && args.p) {
1212
let filename = args._[1];
1313
if (filename !== path.basename(filename)) {
1414
let message = Constants.userMessages.CONFLICTING_INIT_ARGUMENTS;
1515
logger.error(message);
1616
// set cypress config filename
1717
utils.setCypressConfigFilename(args.bstack_config, args);
18-
utils.sendUsageReport(null, args, message, Constants.messageTypes.ERROR, 'conflicting_path_json_init');
18+
utils.sendUsageReport(null, args, message, Constants.messageTypes.ERROR, 'conflicting_path_json_init', null, rawArgs);
1919
return;
2020
}
2121

@@ -35,9 +35,9 @@ function get_path(args) {
3535
}
3636

3737

38-
module.exports = function init(args) {
38+
module.exports = function init(args, rawArgs) {
3939

40-
let path_to_json = get_path(args);
40+
let path_to_json = get_path(args, rawArgs);
4141
if (path_to_json === undefined) return;
4242

4343
// append .json if filename passed is not of json type
@@ -57,15 +57,15 @@ module.exports = function init(args) {
5757
if (exists) {
5858
let message = Constants.userMessages.CONFIG_FILE_EXISTS;
5959
logger.error(message);
60-
utils.sendUsageReport(null, args, message, Constants.messageTypes.ERROR, 'bstack_json_already_exists');
60+
utils.sendUsageReport(null, args, message, Constants.messageTypes.ERROR, 'bstack_json_already_exists', null, rawArgs);
6161
} else {
6262
fileHelpers.write(config, null, args, utils.configCreated);
6363
}
6464
});
6565
} else {
6666
let message = util.format(Constants.userMessages.DIR_NOT_FOUND, path.dirname(config.path));
6767
logger.error(message);
68-
utils.sendUsageReport(null, args, message, Constants.messageTypes.ERROR, 'path_to_init_not_found');
68+
utils.sendUsageReport(null, args, message, Constants.messageTypes.ERROR, 'path_to_init_not_found', null, rawArgs);
6969
}
7070
});
7171
}

bin/commands/runs.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const archiver = require("../helpers/archiver"),
1818
downloadBuildArtifacts = require('../helpers/buildArtifacts').downloadBuildArtifacts,
1919
updateNotifier = require('update-notifier'),
2020
pkg = require('../../package.json');
21-
module.exports = function run(args) {
21+
module.exports = function run(args, rawArgs) {
2222
let bsConfigPath = utils.getConfigPath(args.cf);
2323
//Delete build_results.txt from log folder if already present.
2424
initTimeComponents();
@@ -102,7 +102,7 @@ module.exports = function run(args) {
102102
utils.setParallels(bsConfig, args, specFiles.length);
103103

104104
// warn if specFiles cross our limit
105-
utils.warnSpecLimit(bsConfig, args, specFiles);
105+
utils.warnSpecLimit(bsConfig, args, specFiles, rawArgs);
106106
markBlockEnd('preArchiveSteps');
107107
markBlockStart('checkAlreadyUploaded');
108108
return checkUploaded.checkUploadedMd5(bsConfig, args, {markBlockStart, markBlockEnd}).then(function (md5data) {
@@ -130,7 +130,7 @@ module.exports = function run(args) {
130130
// Create build
131131
//setup Local Testing
132132
markBlockStart('localSetup');
133-
let bs_local = await utils.setupLocalTesting(bsConfig, args);
133+
let bs_local = await utils.setupLocalTesting(bsConfig, args, rawArgs);
134134
markBlockEnd('localSetup');
135135
markBlockStart('createBuild');
136136
return build.createBuild(bsConfig, zip).then(function (data) {
@@ -166,22 +166,22 @@ module.exports = function run(args) {
166166

167167

168168
if (args.sync) {
169-
syncRunner.pollBuildStatus(bsConfig, data).then(async (exitCode) => {
169+
syncRunner.pollBuildStatus(bsConfig, data, rawArgs).then(async (exitCode) => {
170170

171171
// stop the Local instance
172-
await utils.stopLocalBinary(bsConfig, bs_local, args);
172+
await utils.stopLocalBinary(bsConfig, bs_local, args, rawArgs);
173173

174174
// waiting for 5 secs for upload to complete (as a safety measure)
175175
await new Promise(resolve => setTimeout(resolve, 5000));
176176

177177
// download build artifacts
178178
if (utils.nonEmptyArray(bsConfig.run_settings.downloads)) {
179-
await downloadBuildArtifacts(bsConfig, data.build_id, args);
179+
await downloadBuildArtifacts(bsConfig, data.build_id, args, rawArgs);
180180
}
181181

182182
// Generate custom report!
183-
reportGenerator(bsConfig, data.build_id, args, function(){
184-
utils.sendUsageReport(bsConfig, args, `${message}\n${dashboardLink}`, Constants.messageTypes.SUCCESS, null, buildReportData);
183+
reportGenerator(bsConfig, data.build_id, args, rawArgs, function(){
184+
utils.sendUsageReport(bsConfig, args, `${message}\n${dashboardLink}`, Constants.messageTypes.SUCCESS, null, buildReportData, rawArgs);
185185
utils.handleSyncExit(exitCode, data.dashboard_url);
186186
});
187187
});
@@ -210,30 +210,30 @@ module.exports = function run(args) {
210210
}
211211
}
212212
buildReportData = { ...buildReportData, ...dataToSend };
213-
utils.sendUsageReport(bsConfig, args, `${message}\n${dashboardLink}`, Constants.messageTypes.SUCCESS, null, buildReportData);
213+
utils.sendUsageReport(bsConfig, args, `${message}\n${dashboardLink}`, Constants.messageTypes.SUCCESS, null, buildReportData, rawArgs);
214214
return;
215215
}).catch(async function (err) {
216216
// Build creation failed
217217
logger.error(err);
218218
// stop the Local instance
219-
await utils.stopLocalBinary(bsConfig, bs_local, args);
219+
await utils.stopLocalBinary(bsConfig, bs_local, args, rawArgs);
220220

221-
utils.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'build_failed');
221+
utils.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'build_failed', null, rawArgs);
222222
process.exitCode = Constants.ERROR_EXIT_CODE;
223223
});
224224
}).catch(function (err) {
225225
// Zip Upload failed | Local Start failed
226226
logger.error(err);
227227
if(err === Constants.userMessages.LOCAL_START_FAILED){
228-
utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.userMessages.LOCAL_START_FAILED}`, Constants.messageTypes.ERROR, 'local_start_failed');
228+
utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.userMessages.LOCAL_START_FAILED}`, Constants.messageTypes.ERROR, 'local_start_failed', null, rawArgs);
229229
} else {
230230
logger.error(Constants.userMessages.ZIP_UPLOAD_FAILED);
231231
fileHelpers.deleteZip();
232-
utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.userMessages.ZIP_UPLOAD_FAILED}`, Constants.messageTypes.ERROR, 'zip_upload_failed');
232+
utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.userMessages.ZIP_UPLOAD_FAILED}`, Constants.messageTypes.ERROR, 'zip_upload_failed', null, rawArgs);
233233
try {
234234
fileHelpers.deletePackageArchieve();
235235
} catch (err) {
236-
utils.sendUsageReport(bsConfig, args, Constants.userMessages.NPM_DELETE_FAILED, Constants.messageTypes.ERROR, 'npm_deletion_failed');
236+
utils.sendUsageReport(bsConfig, args, Constants.userMessages.NPM_DELETE_FAILED, Constants.messageTypes.ERROR, 'npm_deletion_failed', null, rawArgs);
237237
}
238238
}
239239
process.exitCode = Constants.ERROR_EXIT_CODE;
@@ -242,36 +242,36 @@ module.exports = function run(args) {
242242
// Zipping failed
243243
logger.error(err);
244244
logger.error(Constants.userMessages.FAILED_TO_ZIP);
245-
utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.userMessages.FAILED_TO_ZIP}`, Constants.messageTypes.ERROR, 'zip_creation_failed');
245+
utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.userMessages.FAILED_TO_ZIP}`, Constants.messageTypes.ERROR, 'zip_creation_failed', null, rawArgs);
246246
try {
247247
fileHelpers.deleteZip();
248248
} catch (err) {
249-
utils.sendUsageReport(bsConfig, args, Constants.userMessages.ZIP_DELETE_FAILED, Constants.messageTypes.ERROR, 'zip_deletion_failed');
249+
utils.sendUsageReport(bsConfig, args, Constants.userMessages.ZIP_DELETE_FAILED, Constants.messageTypes.ERROR, 'zip_deletion_failed', null, rawArgs);
250250
}
251251
try {
252252
fileHelpers.deletePackageArchieve();
253253
} catch (err) {
254-
utils.sendUsageReport(bsConfig, args, Constants.userMessages.NPM_DELETE_FAILED, Constants.messageTypes.ERROR, 'npm_deletion_failed');
254+
utils.sendUsageReport(bsConfig, args, Constants.userMessages.NPM_DELETE_FAILED, Constants.messageTypes.ERROR, 'npm_deletion_failed', null, rawArgs);
255255
}
256256
process.exitCode = Constants.ERROR_EXIT_CODE;
257257
});
258258
}).catch(function (err) {
259259
// package installer failed
260260
logger.error(err);
261261
logger.error(Constants.userMessages.FAILED_CREATE_NPM_ARCHIVE);
262-
utils.sendUsageReport(bsConfig, args, Constants.userMessages.FAILED_CREATE_NPM_ARCHIVE, Constants.messageTypes.ERROR, 'npm_package_archive_failed');
262+
utils.sendUsageReport(bsConfig, args, Constants.userMessages.FAILED_CREATE_NPM_ARCHIVE, Constants.messageTypes.ERROR, 'npm_package_archive_failed', null, rawArgs);
263263
try {
264264
fileHelpers.deletePackageArchieve();
265265
} catch (err) {
266-
utils.sendUsageReport(bsConfig, args, Constants.userMessages.NPM_DELETE_FAILED, Constants.messageTypes.ERROR, 'npm_deletion_failed');
266+
utils.sendUsageReport(bsConfig, args, Constants.userMessages.NPM_DELETE_FAILED, Constants.messageTypes.ERROR, 'npm_deletion_failed', null, rawArgs);
267267
}
268268
process.exitCode = Constants.ERROR_EXIT_CODE;
269269
});
270270
}).catch(function (err) {
271271
// md5 check failed
272272
logger.error(err);
273273
logger.error(Constants.userMessages.FAILED_MD5_CHECK);
274-
utils.sendUsageReport(bsConfig, args, Constants.userMessages.MD5_CHECK_FAILED, Constants.messageTypes.ERROR, 'zip_already_uploaded_failed');
274+
utils.sendUsageReport(bsConfig, args, Constants.userMessages.MD5_CHECK_FAILED, Constants.messageTypes.ERROR, 'zip_already_uploaded_failed', null, rawArgs);
275275
process.exitCode = Constants.ERROR_EXIT_CODE;
276276
});
277277
}).catch(function (err) {
@@ -285,14 +285,14 @@ module.exports = function run(args) {
285285
}
286286

287287
let error_code = utils.getErrorCodeFromMsg(err);
288-
utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.validationMessages.NOT_VALID}`, Constants.messageTypes.ERROR, error_code);
288+
utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.validationMessages.NOT_VALID}`, Constants.messageTypes.ERROR, error_code, null, rawArgs);
289289
process.exitCode = Constants.ERROR_EXIT_CODE;
290290
});
291291
}).catch(function (err) {
292292
logger.error(err);
293293
utils.setUsageReportingFlag(null, args.disableUsageReporting);
294294
let bsJsonData = utils.readBsConfigJSON(bsConfigPath);
295-
utils.sendUsageReport(bsJsonData, args, err.message, Constants.messageTypes.ERROR, utils.getErrorCodeFromErr(err));
295+
utils.sendUsageReport(bsJsonData, args, err.message, Constants.messageTypes.ERROR, utils.getErrorCodeFromErr(err), null, rawArgs);
296296
process.exitCode = Constants.ERROR_EXIT_CODE;
297297
}).finally(function(){
298298
updateNotifier({

bin/commands/stop.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const config = require("../helpers/config"),
66
Constants = require("../helpers/constants"),
77
utils = require("../helpers/utils");
88

9-
module.exports = function stop(args) {
9+
module.exports = function stop(args, rawArgs) {
1010
let bsConfigPath = utils.getConfigPath(args.cf);
1111

1212
return utils.validateBstackJson(bsConfigPath).then(async function (bsConfig) {
@@ -25,12 +25,12 @@ module.exports = function stop(args) {
2525

2626
let buildId = args._[1];
2727

28-
await utils.stopBrowserStackBuild(bsConfig, args, buildId);
28+
await utils.stopBrowserStackBuild(bsConfig, args, buildId, rawArgs);
2929

3030
}).catch(function (err) {
3131
logger.error(err);
3232
utils.setUsageReportingFlag(null, args.disableUsageReporting);
33-
utils.sendUsageReport(null, args, err.message, Constants.messageTypes.ERROR, utils.getErrorCodeFromErr(err));
33+
utils.sendUsageReport(null, args, err.message, Constants.messageTypes.ERROR, utils.getErrorCodeFromErr(err), null, rawArgs);
3434
process.exitCode = Constants.ERROR_EXIT_CODE;
3535
})
3636
}

bin/helpers/buildArtifacts.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ const unzipFile = async (filePath, fileName) => {
134134
});
135135
}
136136

137-
const sendUpdatesToBstack = async (bsConfig, buildId, args, options) => {
137+
const sendUpdatesToBstack = async (bsConfig, buildId, args, options, rawArgs) => {
138138
let url = `${config.buildUrl}${buildId}/build_artifacts/status`;
139139

140140
let cypressJSON = utils.getCypressJSON(bsConfig);
@@ -159,11 +159,11 @@ const sendUpdatesToBstack = async (bsConfig, buildId, args, options) => {
159159
try {
160160
await axios.post(url, data, options);
161161
} catch (err) {
162-
utils.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'api_failed_build_artifacts_status_update');
162+
utils.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'api_failed_build_artifacts_status_update', null, rawArgs);
163163
}
164164
}
165165

166-
exports.downloadBuildArtifacts = async (bsConfig, buildId, args) => {
166+
exports.downloadBuildArtifacts = async (bsConfig, buildId, args, rawArgs) => {
167167
BUILD_ARTIFACTS_FAIL_COUNT = 0;
168168
BUILD_ARTIFACTS_TOTAL_COUNT = 0;
169169

@@ -200,8 +200,8 @@ exports.downloadBuildArtifacts = async (bsConfig, buildId, args) => {
200200
logger.info(message);
201201
}
202202

203-
await sendUpdatesToBstack(bsConfig, buildId, args, options);
204-
utils.sendUsageReport(bsConfig, args, message, messageType, null);
203+
await sendUpdatesToBstack(bsConfig, buildId, args, options, rawArgs);
204+
utils.sendUsageReport(bsConfig, args, message, messageType, null, null, rawArgs);
205205
} catch (err) {
206206
messageType = Constants.messageTypes.ERROR;
207207
errorCode = 'api_failed_build_artifacts';
@@ -214,7 +214,7 @@ exports.downloadBuildArtifacts = async (bsConfig, buildId, args) => {
214214
logger.error('Downloading the build artifacts failed.');
215215
}
216216

217-
utils.sendUsageReport(bsConfig, args, err, messageType, errorCode);
217+
utils.sendUsageReport(bsConfig, args, err, messageType, errorCode, null, rawArgs);
218218
process.exitCode = Constants.ERROR_EXIT_CODE;
219219
}
220220
};

bin/helpers/reporterHTML.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ function buildSpecStats(specMeta) {
8989
return specStats;
9090
}
9191

92-
let reportGenerator = (bsConfig, buildId, args, cb) => {
92+
let reportGenerator = (bsConfig, buildId, args, rawArgs, cb) => {
9393
let options = {
9494
url: `${config.buildUrl}${buildId}/custom_report`,
9595
auth: {
@@ -115,7 +115,7 @@ let reportGenerator = (bsConfig, buildId, args, cb) => {
115115
logger.error('Generating the build report failed.');
116116
logger.error(message);
117117

118-
utils.sendUsageReport(bsConfig, args, message, messageType, errorCode);
118+
utils.sendUsageReport(bsConfig, args, message, messageType, errorCode, null, rawArgs);
119119
return;
120120
} else {
121121
try {
@@ -167,7 +167,7 @@ let reportGenerator = (bsConfig, buildId, args, cb) => {
167167
await renderReportHTML(build);
168168
logger.info(message);
169169
}
170-
utils.sendUsageReport(bsConfig, args, message, messageType, errorCode);
170+
utils.sendUsageReport(bsConfig, args, message, messageType, errorCode, null, rawArgs);
171171
if (cb){
172172
cb();
173173
}

bin/helpers/sync/syncSpecsLogs.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ let setNoWrapParams = () => {
9090
}
9191
};
9292

93-
let printSpecsStatus = (bsConfig, buildDetails) => {
93+
let printSpecsStatus = (bsConfig, buildDetails, rawArgs) => {
9494
setNoWrapParams();
9595
return new Promise((resolve, reject) => {
9696
options = getOptions(bsConfig.auth, buildDetails.build_id)
@@ -106,7 +106,7 @@ let printSpecsStatus = (bsConfig, buildDetails) => {
106106
},
107107
function(err, result) { // when loop ends
108108
if (err) {
109-
utils.sendUsageReport(bsConfig, {}, `buildId: ${buildDetails.build_id}`, 'error', 'sync_cli_error', err);
109+
utils.sendUsageReport(bsConfig, {}, `buildId: ${buildDetails.build_id}`, 'error', 'sync_cli_error', err, rawArgs);
110110
}
111111
logger.info(lineSeparator);
112112
specSummary.duration = endTime - startTime

0 commit comments

Comments
 (0)