Skip to content

Commit 855d6f6

Browse files
Karan NagpalKaran Nagpal
authored andcommitted
handle cypressProjectDir while fetching json and global var
1 parent b067ef2 commit 855d6f6

File tree

3 files changed

+23
-20
lines changed

3 files changed

+23
-20
lines changed

bin/commands/runs.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ module.exports = function run(args) {
149149
utils.handleSyncExit(exitCode, data.dashboard_url);
150150
});
151151
});
152-
} else {
153-
logger.info(Constants.userMessages.ASYNC_DOWNLOADS.replace('<build-id>', data.build_id));
152+
} else if(!utils.isUndefined(bsConfig.run_settings.downloads) && bsConfig.run_settings.downloads.length) {
153+
logger.info(Constants.userMessages.ASYNC_DOWNLOADS.replace('<build-id>', data.build_id));
154154
}
155155

156156
logger.info(message);

bin/helpers/buildArtifacts.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ const logger = require('./logger').winstonLogger,
1212
config = require("./config");
1313

1414

15+
let BUILD_ARTIFACTS_TOTAL_COUNT = 0;
16+
let BUILD_ARTIFACTS_FAIL_COUNT = 0;
17+
1518
const parseAndDownloadArtifacts = async (buildId, data) => {
1619
return new Promise(async (resolve, reject) => {
1720
let all_promises = [];
@@ -23,9 +26,9 @@ const parseAndDownloadArtifacts = async (buildId, data) => {
2326
let sessionId = sessions[j];
2427
let filePath = path.join('./', 'build_artifacts', buildId, comb, sessionId);
2528
let fileName = 'build_artifacts.zip';
26-
process.env.BUILD_ARTIFACTS_TOTAL_COUNT = Number(process.env.BUILD_ARTIFACTS_TOTAL_COUNT) + 1
29+
BUILD_ARTIFACTS_TOTAL_COUNT += 1;
2730
all_promises.push(downloadAndUnzip(filePath, fileName, data[comb][sessionId]).catch((error) => {
28-
process.env.BUILD_ARTIFACTS_FAIL_COUNT = Number(process.env.BUILD_ARTIFACTS_FAIL_COUNT) + 1;
31+
BUILD_ARTIFACTS_FAIL_COUNT = BUILD_ARTIFACTS_FAIL_COUNT + 1;
2932
reject(error);
3033
}));
3134
}
@@ -142,8 +145,8 @@ const sendUpdatesToBstack = async (bsConfig, buildId, args, options) => {
142145
let data = {
143146
feature_usage: {
144147
downloads: {
145-
eligible_download_folders: Number(process.env.BUILD_ARTIFACTS_TOTAL_COUNT),
146-
successfully_downloaded_folders: Number(process.env.BUILD_ARTIFACTS_TOTAL_COUNT) - Number(process.env.BUILD_ARTIFACTS_FAIL_COUNT)
148+
eligible_download_folders: BUILD_ARTIFACTS_TOTAL_COUNT,
149+
successfully_downloaded_folders: BUILD_ARTIFACTS_TOTAL_COUNT - BUILD_ARTIFACTS_FAIL_COUNT
147150
},
148151
reporter: reporter
149152
}
@@ -157,8 +160,8 @@ const sendUpdatesToBstack = async (bsConfig, buildId, args, options) => {
157160
}
158161

159162
exports.downloadBuildArtifacts = async (bsConfig, buildId, args) => {
160-
process.env.BUILD_ARTIFACTS_FAIL_COUNT = 0;
161-
process.env.BUILD_ARTIFACTS_TOTAL_COUNT = 0;
163+
BUILD_ARTIFACTS_FAIL_COUNT = 0;
164+
BUILD_ARTIFACTS_TOTAL_COUNT = 0;
162165

163166
let url = `${config.buildUrl}${buildId}/build_artifacts`;
164167
let options = {
@@ -182,9 +185,9 @@ exports.downloadBuildArtifacts = async (bsConfig, buildId, args) => {
182185
await createDirectories(buildId, buildDetails);
183186
await parseAndDownloadArtifacts(buildId, buildDetails);
184187

185-
if (process.env.BUILD_ARTIFACTS_FAIL_COUNT > 0) {
188+
if (BUILD_ARTIFACTS_FAIL_COUNT > 0) {
186189
messageType = Constants.messageTypes.ERROR;
187-
message = Constants.userMessages.DOWNLOAD_BUILD_ARTIFACTS_FAILED.replace('<build-id>', buildId).replace('<machine-count>', process.env.BUILD_ARTIFACTS_FAIL_COUNT);
190+
message = Constants.userMessages.DOWNLOAD_BUILD_ARTIFACTS_FAILED.replace('<build-id>', buildId).replace('<machine-count>', BUILD_ARTIFACTS_FAIL_COUNT);
188191
logger.error(message);
189192
} else {
190193
messageType = Constants.messageTypes.SUCCESS;
@@ -198,13 +201,12 @@ exports.downloadBuildArtifacts = async (bsConfig, buildId, args) => {
198201
messageType = Constants.messageTypes.ERROR;
199202
errorCode = 'api_failed_build_artifacts';
200203

201-
if (process.env.BUILD_ARTIFACTS_FAIL_COUNT > 0) {
204+
if (BUILD_ARTIFACTS_FAIL_COUNT > 0) {
202205
messageType = Constants.messageTypes.ERROR;
203-
message = Constants.userMessages.DOWNLOAD_BUILD_ARTIFACTS_FAILED.replace('<build-id>', buildId).replace('<machine-count>', process.env.BUILD_ARTIFACTS_FAIL_COUNT);
206+
message = Constants.userMessages.DOWNLOAD_BUILD_ARTIFACTS_FAILED.replace('<build-id>', buildId).replace('<machine-count>', BUILD_ARTIFACTS_FAIL_COUNT);
204207
logger.error(message);
205208
} else {
206209
logger.error('Downloading the build artifacts failed.');
207-
logger.error(err);
208210
}
209211

210212
utils.sendUsageReport(bsConfig, args, err, messageType, errorCode);

bin/helpers/utils.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -752,14 +752,15 @@ exports.setOtherConfigs = (bsConfig, args) => {
752752
}
753753

754754
exports.getCypressJSON = (bsConfig) => {
755-
if (
756-
bsConfig.run_settings.cypress_config_file &&
757-
bsConfig.run_settings.cypress_config_filename !== 'false'
758-
) {
759-
let cypressJSON = JSON.parse(
755+
let cypressJSON = undefined;
756+
if (bsConfig.run_settings.cypress_config_file && bsConfig.run_settings.cypress_config_filename !== 'false') {
757+
cypressJSON = JSON.parse(
760758
fs.readFileSync(bsConfig.run_settings.cypressConfigFilePath)
761759
);
762-
return cypressJSON;
760+
} else if (bsConfig.run_settings.cypressProjectDir) {
761+
cypressJSON = JSON.parse(
762+
fs.readFileSync(path.join(bsConfig.run_settings.cypressProjectDir, 'cypress.json'))
763+
);
763764
}
764-
return undefined;
765+
return cypressJSON;
765766
}

0 commit comments

Comments
 (0)