diff --git a/bin/helpers/buildArtifacts.js b/bin/helpers/buildArtifacts.js index 3d476295..e4aacd6b 100644 --- a/bin/helpers/buildArtifacts.js +++ b/bin/helpers/buildArtifacts.js @@ -15,7 +15,7 @@ const decompress = require('decompress'); let BUILD_ARTIFACTS_TOTAL_COUNT = 0; let BUILD_ARTIFACTS_FAIL_COUNT = 0; -const parseAndDownloadArtifacts = async (buildId, data) => { +const parseAndDownloadArtifacts = async (buildId, data, bsConfig, args, rawArgs, buildReportData) => { return new Promise(async (resolve, reject) => { let all_promises = []; let combs = Object.keys(data); @@ -28,7 +28,14 @@ const parseAndDownloadArtifacts = async (buildId, data) => { let fileName = 'build_artifacts.zip'; BUILD_ARTIFACTS_TOTAL_COUNT += 1; all_promises.push(downloadAndUnzip(filePath, fileName, data[comb][sessionId]).catch((error) => { - BUILD_ARTIFACTS_FAIL_COUNT += 1; + if (error === Constants.userMessages.DOWNLOAD_BUILD_ARTIFACTS_NOT_FOUND) { + // Don't consider build artifact 404 error as a failure + let warningMessage = Constants.userMessages.DOWNLOAD_BUILD_ARTIFACTS_NOT_FOUND.replace('', sessionId); + logger.warn(warningMessage); + utils.sendUsageReport(bsConfig, args, warningMessage, Constants.messageTypes.ERROR, 'build_artifacts_not_found', buildReportData, rawArgs); + } else { + BUILD_ARTIFACTS_FAIL_COUNT += 1; + } // delete malformed zip if present let tmpFilePath = path.join(filePath, fileName); if(fs.existsSync(tmpFilePath)){ @@ -99,6 +106,9 @@ const downloadAndUnzip = async (filePath, fileName, url) => { request.get(url).on('response', function(response) { if(response.statusCode != 200) { + if (response.statusCode === 404) { + reject(Constants.userMessages.DOWNLOAD_BUILD_ARTIFACTS_NOT_FOUND); + } reject(); } else { //ensure that the user can call `then()` only when the file has @@ -220,7 +230,7 @@ exports.downloadBuildArtifacts = async (bsConfig, buildId, args, rawArgs, buildR process.exitCode = Constants.ERROR_EXIT_CODE; } else { await createDirectories(buildId, buildDetails); - await parseAndDownloadArtifacts(buildId, buildDetails); + await parseAndDownloadArtifacts(buildId, buildDetails, bsConfig, args, rawArgs, buildReportData); if (BUILD_ARTIFACTS_FAIL_COUNT > 0) { messageType = Constants.messageTypes.ERROR; message = Constants.userMessages.DOWNLOAD_BUILD_ARTIFACTS_FAILED.replace('', buildId).replace('', BUILD_ARTIFACTS_FAIL_COUNT); diff --git a/bin/helpers/constants.js b/bin/helpers/constants.js index cc65ff48..70dac61c 100644 --- a/bin/helpers/constants.js +++ b/bin/helpers/constants.js @@ -94,7 +94,9 @@ const userMessages = { SPEC_LIMIT_WARNING: "You might not see all your results on the dashboard because of high spec count, please consider reducing the number of spec files in this folder.", DOWNLOAD_BUILD_ARTIFACTS_FAILED: - "Downloading build artifacts for the build failed for machines.", + "Downloading build artifact(s) for the build failed for machines.", + DOWNLOAD_BUILD_ARTIFACTS_NOT_FOUND: + "Build artifact(s) for the session was either not generated or not uploaded.", ASYNC_DOWNLOADS: "Test artifacts as specified under 'downloads' can be downloaded after the build has completed its run, using 'browserstack-cypress generate-downloads '", DOWNLOAD_BUILD_ARTIFACTS_SUCCESS: diff --git a/bin/helpers/utils.js b/bin/helpers/utils.js index a8401418..bcddcf98 100644 --- a/bin/helpers/utils.js +++ b/bin/helpers/utils.js @@ -1314,25 +1314,29 @@ exports.readBsConfigJSON = (bsConfigPath) => { } exports.getCypressConfigFile = (bsConfig) => { - let cypressConfigFile = undefined; - if (bsConfig.run_settings.cypressTestSuiteType === Constants.CYPRESS_V10_AND_ABOVE_TYPE) { - if (bsConfig.run_settings.cypress_config_filename.endsWith("cypress.config.js")) { + try { + let cypressConfigFile = undefined; + if (bsConfig.run_settings.cypressTestSuiteType === Constants.CYPRESS_V10_AND_ABOVE_TYPE) { + if (bsConfig.run_settings.cypress_config_filename.endsWith("cypress.config.js")) { + if (bsConfig.run_settings.cypress_config_file && bsConfig.run_settings.cypress_config_filename !== 'false') { + cypressConfigFile = require(path.resolve(bsConfig.run_settings.cypressConfigFilePath)); + } else if (bsConfig.run_settings.cypressProjectDir) { + cypressConfigFile = require(path.join(bsConfig.run_settings.cypressProjectDir, bsConfig.run_settings.cypress_config_filename)); + } + } else { + cypressConfigFile = {}; + } + } else { if (bsConfig.run_settings.cypress_config_file && bsConfig.run_settings.cypress_config_filename !== 'false') { - cypressConfigFile = require(path.resolve(bsConfig.run_settings.cypressConfigFilePath)); + cypressConfigFile = JSON.parse(fs.readFileSync(bsConfig.run_settings.cypressConfigFilePath)) } else if (bsConfig.run_settings.cypressProjectDir) { - cypressConfigFile = require(path.join(bsConfig.run_settings.cypressProjectDir, bsConfig.run_settings.cypress_config_filename)); + cypressConfigFile = JSON.parse(fs.readFileSync(path.join(bsConfig.run_settings.cypressProjectDir, bsConfig.run_settings.cypress_config_filename))); } - } else { - cypressConfigFile = {}; - } - } else { - if (bsConfig.run_settings.cypress_config_file && bsConfig.run_settings.cypress_config_filename !== 'false') { - cypressConfigFile = JSON.parse(fs.readFileSync(bsConfig.run_settings.cypressConfigFilePath)) - } else if (bsConfig.run_settings.cypressProjectDir) { - cypressConfigFile = JSON.parse(fs.readFileSync(path.join(bsConfig.run_settings.cypressProjectDir, bsConfig.run_settings.cypress_config_filename))); } + return cypressConfigFile; + } catch (err) { + return {} } - return cypressConfigFile; } exports.setCLIMode = (bsConfig, args) => {