Skip to content

Commit 4f8add1

Browse files
authored
Merge pull request #884 from browserstack/HST-1587-cypress-custom-report
Custom Report Support for Automate Turboscale
2 parents f1b31b6 + 58123f5 commit 4f8add1

File tree

5 files changed

+21
-11
lines changed

5 files changed

+21
-11
lines changed

bin/commands/generateReport.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ const logger = require("../helpers/logger").winstonLogger,
55
utils = require("../helpers/utils"),
66
reporterHTML = require('../helpers/reporterHTML'),
77
getInitialDetails = require('../helpers/getInitialDetails').getInitialDetails;
8-
8+
const { isTurboScaleSession } = require('../helpers/atsHelper');
99

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

14-
return utils.validateBstackJson(bsConfigPath).then(function (bsConfig) {
14+
return utils.validateBstackJson(bsConfigPath).then(async function (bsConfig) {
1515
// setting setDefaults to {} if not present and set via env variables or via args.
1616
utils.setDefaults(bsConfig, args);
1717

@@ -21,9 +21,9 @@ module.exports = function generateReport(args, rawArgs) {
2121
// accept the access key from command line if provided
2222
utils.setAccessKey(bsConfig, args);
2323

24-
getInitialDetails(bsConfig, args, rawArgs).then((buildReportData) => {
25-
26-
utils.setUsageReportingFlag(bsConfig, args.disableUsageReporting);
24+
try {
25+
let buildReportData = isTurboScaleSession(bsConfig) ? null : await getInitialDetails(bsConfig, args, rawArgs);
26+
utils.setUsageReportingFlag(bsConfig, args.disableUsageReporting);
2727

2828
// set cypress config filename
2929
utils.setCypressConfigFilename(bsConfig, args);
@@ -34,9 +34,9 @@ module.exports = function generateReport(args, rawArgs) {
3434

3535
reportGenerator(bsConfig, buildId, args, rawArgs, buildReportData);
3636
utils.sendUsageReport(bsConfig, args, 'generate-report called', messageType, errorCode, buildReportData, rawArgs);
37-
}).catch((err) => {
37+
} catch(err) {
3838
logger.warn(err);
39-
});
39+
};
4040
}).catch(function (err) {
4141
logger.error(err);
4242
utils.setUsageReportingFlag(null, args.disableUsageReporting);

bin/commands/runs.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -365,10 +365,10 @@ module.exports = function run(args, rawArgs) {
365365
await new Promise(resolve => setTimeout(resolve, 5000));
366366

367367
// download build artifacts
368-
if (exitCode != Constants.BUILD_FAILED_EXIT_CODE && !turboScaleSession) {
368+
if (exitCode != Constants.BUILD_FAILED_EXIT_CODE) {
369369
if (utils.nonEmptyArray(bsConfig.run_settings.downloads)) {
370370
logger.debug("Downloading build artifacts");
371-
await downloadBuildArtifacts(bsConfig, data.build_id, args, rawArgs, buildReportData);
371+
await downloadBuildArtifacts(bsConfig, data.build_id, args, rawArgs, buildReportData, turboScaleSession);
372372
}
373373

374374
// Generate custom report!

bin/helpers/buildArtifacts.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -213,13 +213,15 @@ const sendUpdatesToBstack = async (bsConfig, buildId, args, options, rawArgs, bu
213213
});
214214
}
215215

216-
exports.downloadBuildArtifacts = async (bsConfig, buildId, args, rawArgs, buildReportData = null) => {
216+
exports.downloadBuildArtifacts = async (bsConfig, buildId, args, rawArgs, buildReportData = null, isTurboScaleSession = false) => {
217217
return new Promise ( async (resolve, reject) => {
218218
BUILD_ARTIFACTS_FAIL_COUNT = 0;
219219
BUILD_ARTIFACTS_TOTAL_COUNT = 0;
220220

221221
let options = {
222-
url: `${config.buildUrl}${buildId}/build_artifacts`,
222+
url: isTurboScaleSession
223+
? `${config.turboScaleBuildsUrl}/${buildId}/build_artifacts`
224+
: `${config.buildUrl}${buildId}/build_artifacts`,
223225
auth: {
224226
username: bsConfig.auth.username,
225227
password: bsConfig.auth.access_key,

bin/helpers/capabilityHelper.js

+3
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ const caps = (bsConfig, zip) => {
131131
obj.run_settings = JSON.stringify(bsConfig.run_settings);
132132
}
133133

134+
obj.cypress_cli_user_agent = Utils.getUserAgent();
135+
logger.info(`Cypress CLI User Agent: ${obj.cypress_cli_user_agent}`);
136+
134137
if(obj.parallels === Constants.cliMessages.RUN.DEFAULT_PARALLEL_MESSAGE) obj.parallels = undefined
135138

136139
if (obj.project) logger.info(`Project name is: ${obj.project}`);

bin/helpers/reporterHTML.js

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const fs = require('fs'),
66
Constants = require('./constants'),
77
config = require("./config"),
88
decompress = require('decompress');
9+
const { isTurboScaleSession } = require('../helpers/atsHelper');
910

1011
let reportGenerator = (bsConfig, buildId, args, rawArgs, buildReportData, cb) => {
1112
let options = {
@@ -19,6 +20,10 @@ let reportGenerator = (bsConfig, buildId, args, rawArgs, buildReportData, cb) =>
1920
},
2021
};
2122

23+
if (isTurboScaleSession(bsConfig)) {
24+
options.url = `${config.turboScaleBuildsUrl}/${buildId}/custom_report`;
25+
}
26+
2227
logger.debug('Started fetching the build json and html reports.');
2328

2429
return request.get(options, async function (err, resp, body) {

0 commit comments

Comments
 (0)