From dfdf8cdb99a63311448a4d7dbbe778256447c073 Mon Sep 17 00:00:00 2001 From: roshan04 Date: Mon, 20 Dec 2021 18:04:00 +0530 Subject: [PATCH 01/19] priting error message while buildartifacts fails --- bin/helpers/buildArtifacts.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bin/helpers/buildArtifacts.js b/bin/helpers/buildArtifacts.js index 906af833..9945f3e5 100644 --- a/bin/helpers/buildArtifacts.js +++ b/bin/helpers/buildArtifacts.js @@ -10,6 +10,7 @@ const logger = require('./logger').winstonLogger, utils = require("./utils"), Constants = require("./constants"), config = require("./config"); +const { inspect } = require('util'); let BUILD_ARTIFACTS_TOTAL_COUNT = 0; @@ -203,6 +204,8 @@ exports.downloadBuildArtifacts = async (bsConfig, buildId, args, rawArgs) => { await sendUpdatesToBstack(bsConfig, buildId, args, options, rawArgs); utils.sendUsageReport(bsConfig, args, message, messageType, null, null, rawArgs); } catch (err) { + + logger.error(err.message); messageType = Constants.messageTypes.ERROR; errorCode = 'api_failed_build_artifacts'; From 8860953948b3cd22e55a6a24ba87d7cdd800e4ed Mon Sep 17 00:00:00 2001 From: roshan04 Date: Mon, 20 Dec 2021 18:05:28 +0530 Subject: [PATCH 02/19] removing inspect --- bin/helpers/buildArtifacts.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bin/helpers/buildArtifacts.js b/bin/helpers/buildArtifacts.js index 9945f3e5..710d5ad5 100644 --- a/bin/helpers/buildArtifacts.js +++ b/bin/helpers/buildArtifacts.js @@ -10,7 +10,6 @@ const logger = require('./logger').winstonLogger, utils = require("./utils"), Constants = require("./constants"), config = require("./config"); -const { inspect } = require('util'); let BUILD_ARTIFACTS_TOTAL_COUNT = 0; @@ -204,8 +203,6 @@ exports.downloadBuildArtifacts = async (bsConfig, buildId, args, rawArgs) => { await sendUpdatesToBstack(bsConfig, buildId, args, options, rawArgs); utils.sendUsageReport(bsConfig, args, message, messageType, null, null, rawArgs); } catch (err) { - - logger.error(err.message); messageType = Constants.messageTypes.ERROR; errorCode = 'api_failed_build_artifacts'; @@ -218,6 +215,7 @@ exports.downloadBuildArtifacts = async (bsConfig, buildId, args, rawArgs) => { } utils.sendUsageReport(bsConfig, args, err, messageType, errorCode, null, rawArgs); + logger.error(err.message); process.exitCode = Constants.ERROR_EXIT_CODE; } }; From 950142c10740410bf7566f91b418769088c6c882 Mon Sep 17 00:00:00 2001 From: roshan04 Date: Tue, 21 Dec 2021 18:28:23 +0530 Subject: [PATCH 03/19] added changes for request module --- bin/helpers/buildArtifacts.js | 117 ++++++++++++++++++++++------------ 1 file changed, 77 insertions(+), 40 deletions(-) diff --git a/bin/helpers/buildArtifacts.js b/bin/helpers/buildArtifacts.js index 710d5ad5..052e8071 100644 --- a/bin/helpers/buildArtifacts.js +++ b/bin/helpers/buildArtifacts.js @@ -11,6 +11,10 @@ const logger = require('./logger').winstonLogger, Constants = require("./constants"), config = require("./config"); +const request = require('request'); +const { inspect } = require('util'); +const { reject } = require('async'); + let BUILD_ARTIFACTS_TOTAL_COUNT = 0; let BUILD_ARTIFACTS_FAIL_COUNT = 0; @@ -95,17 +99,14 @@ const downloadAndUnzip = async (filePath, fileName, url) => { let tmpFilePath = path.join(filePath, fileName); const writer = fs.createWriteStream(tmpFilePath); - return axios({ - method: 'get', - url: url, - responseType: 'stream', - }).then(response => { - + console.log(`roshan1: url ${url}`) + console.log(`roshan inside downloadAndUnzip`) + return request.get(url).on('response', function(response) { //ensure that the user can call `then()` only when the file has //been downloaded entirely. - + console.log(`roshan1: response ${inspect(response)}`) return new Promise(async (resolve, reject) => { - response.data.pipe(writer); + response.pipe(writer); let error = null; writer.on('error', err => { error = err; @@ -135,7 +136,7 @@ const unzipFile = async (filePath, fileName) => { } const sendUpdatesToBstack = async (bsConfig, buildId, args, options, rawArgs) => { - let url = `${config.buildUrl}${buildId}/build_artifacts/status`; + options.url = `${config.buildUrl}${buildId}/build_artifacts/status`; let cypressJSON = utils.getCypressJSON(bsConfig); @@ -156,19 +157,38 @@ const sendUpdatesToBstack = async (bsConfig, buildId, args, options, rawArgs) => } } + options.formData = data; + try { - await axios.post(url, data, options); + let responseData = null; + request.post(options, function (err, resp, data) { + if(err) { + utils.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'api_failed_build_artifacts_status_update', null, rawArgs); + } else { + try { + responseData = JSON.parse(data); + } catch(e) { + responseData = {}; + } + if (resp.statusCode != 200) { + if (responseData && responseData["error"]) { + utils.sendUsageReport(bsConfig, args, responseData["error"], Constants.messageTypes.ERROR, 'api_failed_build_artifacts_status_update', null, rawArgs); + } + } + } + }); } catch (err) { utils.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'api_failed_build_artifacts_status_update', null, rawArgs); } } exports.downloadBuildArtifacts = async (bsConfig, buildId, args, rawArgs) => { + console.log('hello brother') BUILD_ARTIFACTS_FAIL_COUNT = 0; BUILD_ARTIFACTS_TOTAL_COUNT = 0; - let url = `${config.buildUrl}${buildId}/build_artifacts`; let options = { + url: `${config.buildUrl}${buildId}/build_artifacts`, auth: { username: bsConfig.auth.username, password: bsConfig.auth.access_key, @@ -183,39 +203,56 @@ exports.downloadBuildArtifacts = async (bsConfig, buildId, args, rawArgs) => { let errorCode = null; try { - const res = await axios.get(url, options); - let buildDetails = res.data; - - await createDirectories(buildId, buildDetails); - await parseAndDownloadArtifacts(buildId, buildDetails); - - if (BUILD_ARTIFACTS_FAIL_COUNT > 0) { - messageType = Constants.messageTypes.ERROR; - message = Constants.userMessages.DOWNLOAD_BUILD_ARTIFACTS_FAILED.replace('', buildId).replace('', BUILD_ARTIFACTS_FAIL_COUNT); - logger.error(message); + let buildDetails = null; + request.get(options, async function (err, resp, body) { + if(err) { + utils.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'api_failed_build_artifacts', null, rawArgs); process.exitCode = Constants.ERROR_EXIT_CODE; } else { - messageType = Constants.messageTypes.SUCCESS; - message = Constants.userMessages.DOWNLOAD_BUILD_ARTIFACTS_SUCCESS.replace('', buildId).replace('', process.cwd()); - logger.info(message); + try { + buildDetails = JSON.parse(body); + if(resp.statusCode != 200) { + logger.error('Downloading the build artifacts failed.'); + logger.error(`Error: Request failed with status code ${resp.statusCode}`) + utils.sendUsageReport(bsConfig, args, buildDetails, Constants.messageTypes.ERROR, 'api_failed_build_artifacts', null, rawArgs); + process.exitCode = Constants.ERROR_EXIT_CODE; + } else { + await createDirectories(buildId, buildDetails); + await parseAndDownloadArtifacts(buildId, buildDetails); + console.log(`roshan1 making request passed1 ${inspect(buildDetails)}`); + if (BUILD_ARTIFACTS_FAIL_COUNT > 0) { + messageType = Constants.messageTypes.ERROR; + message = Constants.userMessages.DOWNLOAD_BUILD_ARTIFACTS_FAILED.replace('', buildId).replace('', BUILD_ARTIFACTS_FAIL_COUNT); + logger.error(message); + process.exitCode = Constants.ERROR_EXIT_CODE; + } else { + messageType = Constants.messageTypes.SUCCESS; + message = Constants.userMessages.DOWNLOAD_BUILD_ARTIFACTS_SUCCESS.replace('', buildId).replace('', process.cwd()); + logger.info(message); + } + await sendUpdatesToBstack(bsConfig, buildId, args, options, rawArgs); + utils.sendUsageReport(bsConfig, args, message, messageType, null, null, rawArgs); + } + } catch (err) { + messageType = Constants.messageTypes.ERROR; + errorCode = 'api_failed_build_artifacts'; + if (BUILD_ARTIFACTS_FAIL_COUNT > 0) { + messageType = Constants.messageTypes.ERROR; + message = Constants.userMessages.DOWNLOAD_BUILD_ARTIFACTS_FAILED.replace('', buildId).replace('', BUILD_ARTIFACTS_FAIL_COUNT); + logger.error(message); + } else { + logger.error('Downloading the build artifacts failed.'); + } + utils.sendUsageReport(bsConfig, args, err, messageType, errorCode, null, rawArgs); + logger.error(err.message); + logger.error(`Error: Request failed with status code ${resp.statusCode}`) + process.exitCode = Constants.ERROR_EXIT_CODE; + } } - - await sendUpdatesToBstack(bsConfig, buildId, args, options, rawArgs); - utils.sendUsageReport(bsConfig, args, message, messageType, null, null, rawArgs); + }); } catch (err) { - messageType = Constants.messageTypes.ERROR; - errorCode = 'api_failed_build_artifacts'; - - if (BUILD_ARTIFACTS_FAIL_COUNT > 0) { - messageType = Constants.messageTypes.ERROR; - message = Constants.userMessages.DOWNLOAD_BUILD_ARTIFACTS_FAILED.replace('', buildId).replace('', BUILD_ARTIFACTS_FAIL_COUNT); - logger.error(message); - } else { - logger.error('Downloading the build artifacts failed.'); - } - - utils.sendUsageReport(bsConfig, args, err, messageType, errorCode, null, rawArgs); - logger.error(err.message); + console.log(`roshan1: error here ${err}`) + utils.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'api_failed_build_artifacts', null, rawArgs); process.exitCode = Constants.ERROR_EXIT_CODE; } }; From d267eb52dfc441db0b68d3d2b88934ba3b39c503 Mon Sep 17 00:00:00 2001 From: roshan04 Date: Tue, 21 Dec 2021 18:54:12 +0530 Subject: [PATCH 04/19] handle promises errors --- bin/helpers/buildArtifacts.js | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/bin/helpers/buildArtifacts.js b/bin/helpers/buildArtifacts.js index 052e8071..6accca63 100644 --- a/bin/helpers/buildArtifacts.js +++ b/bin/helpers/buildArtifacts.js @@ -99,13 +99,10 @@ const downloadAndUnzip = async (filePath, fileName, url) => { let tmpFilePath = path.join(filePath, fileName); const writer = fs.createWriteStream(tmpFilePath); - console.log(`roshan1: url ${url}`) - console.log(`roshan inside downloadAndUnzip`) - return request.get(url).on('response', function(response) { - //ensure that the user can call `then()` only when the file has - //been downloaded entirely. - console.log(`roshan1: response ${inspect(response)}`) - return new Promise(async (resolve, reject) => { + return new Promise(async (resolve, reject) => { + request.get(url).on('response', function(response) { + //ensure that the user can call `then()` only when the file has + //been downloaded entirely. response.pipe(writer); let error = null; writer.on('error', err => { @@ -183,7 +180,6 @@ const sendUpdatesToBstack = async (bsConfig, buildId, args, options, rawArgs) => } exports.downloadBuildArtifacts = async (bsConfig, buildId, args, rawArgs) => { - console.log('hello brother') BUILD_ARTIFACTS_FAIL_COUNT = 0; BUILD_ARTIFACTS_TOTAL_COUNT = 0; @@ -219,7 +215,6 @@ exports.downloadBuildArtifacts = async (bsConfig, buildId, args, rawArgs) => { } else { await createDirectories(buildId, buildDetails); await parseAndDownloadArtifacts(buildId, buildDetails); - console.log(`roshan1 making request passed1 ${inspect(buildDetails)}`); if (BUILD_ARTIFACTS_FAIL_COUNT > 0) { messageType = Constants.messageTypes.ERROR; message = Constants.userMessages.DOWNLOAD_BUILD_ARTIFACTS_FAILED.replace('', buildId).replace('', BUILD_ARTIFACTS_FAIL_COUNT); @@ -251,7 +246,6 @@ exports.downloadBuildArtifacts = async (bsConfig, buildId, args, rawArgs) => { } }); } catch (err) { - console.log(`roshan1: error here ${err}`) utils.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'api_failed_build_artifacts', null, rawArgs); process.exitCode = Constants.ERROR_EXIT_CODE; } From ff3727d28bde1401c8e3c381fa7a41984548b99e Mon Sep 17 00:00:00 2001 From: roshan04 Date: Wed, 22 Dec 2021 11:42:22 +0530 Subject: [PATCH 05/19] following the approach of promises of request --- bin/commands/runs.js | 6 +- bin/helpers/buildArtifacts.js | 245 ++++++++++++++++++---------------- 2 files changed, 134 insertions(+), 117 deletions(-) diff --git a/bin/commands/runs.js b/bin/commands/runs.js index 2c42cd46..f405a42f 100644 --- a/bin/commands/runs.js +++ b/bin/commands/runs.js @@ -177,7 +177,11 @@ module.exports = function run(args, rawArgs) { // download build artifacts if (utils.nonEmptyArray(bsConfig.run_settings.downloads)) { - await downloadBuildArtifacts(bsConfig, data.build_id, args, rawArgs); + try { + await downloadBuildArtifacts(bsConfig, data.build_id, args, rawArgs); + } catch (err) { + logger.error(err); + } } // Generate custom report! diff --git a/bin/helpers/buildArtifacts.js b/bin/helpers/buildArtifacts.js index 6accca63..92cca4dd 100644 --- a/bin/helpers/buildArtifacts.js +++ b/bin/helpers/buildArtifacts.js @@ -12,8 +12,6 @@ const logger = require('./logger').winstonLogger, config = require("./config"); const request = require('request'); -const { inspect } = require('util'); -const { reject } = require('async'); let BUILD_ARTIFACTS_TOTAL_COUNT = 0; @@ -100,26 +98,35 @@ const downloadAndUnzip = async (filePath, fileName, url) => { const writer = fs.createWriteStream(tmpFilePath); return new Promise(async (resolve, reject) => { - request.get(url).on('response', function(response) { - //ensure that the user can call `then()` only when the file has - //been downloaded entirely. - response.pipe(writer); - let error = null; - writer.on('error', err => { - error = err; - writer.close(); - reject(err); - }); - writer.on('close', async () => { - if (!error) { - await unzipFile(filePath, fileName); - fs.unlinkSync(tmpFilePath); - resolve(true); + try { + request.get(url).on('response', function(response) { + + if(response.statusCode != 200) { + reject(); + } else { + //ensure that the user can call `then()` only when the file has + //been downloaded entirely. + response.pipe(writer); + let error = null; + writer.on('error', err => { + error = err; + writer.close(); + reject(err); + }); + writer.on('close', async () => { + if (!error) { + await unzipFile(filePath, fileName); + fs.unlinkSync(tmpFilePath); + resolve(true); + } + //no need to call the reject here, as it will have been called in the + //'error' stream; + }); } - //no need to call the reject here, as it will have been called in the - //'error' stream; }); - }); + } catch (err) { + reject(err); + } }); } @@ -133,120 +140,126 @@ const unzipFile = async (filePath, fileName) => { } const sendUpdatesToBstack = async (bsConfig, buildId, args, options, rawArgs) => { - options.url = `${config.buildUrl}${buildId}/build_artifacts/status`; + options.url = `${config.buildUrl}${buildId}/build_artifacts/status`; - let cypressJSON = utils.getCypressJSON(bsConfig); + let cypressJSON = utils.getCypressJSON(bsConfig); - let reporter = null; - if(!utils.isUndefined(args.reporter)) { - reporter = args.reporter; - } else if(cypressJSON !== undefined){ - reporter = cypressJSON.reporter; - } - - let data = { - feature_usage: { - downloads: { - eligible_download_folders: BUILD_ARTIFACTS_TOTAL_COUNT, - successfully_downloaded_folders: BUILD_ARTIFACTS_TOTAL_COUNT - BUILD_ARTIFACTS_FAIL_COUNT - }, - reporter: reporter + let reporter = null; + if(!utils.isUndefined(args.reporter)) { + reporter = args.reporter; + } else if(cypressJSON !== undefined){ + reporter = cypressJSON.reporter; } - } - options.formData = data; + let data = { + feature_usage: { + downloads: { + eligible_download_folders: BUILD_ARTIFACTS_TOTAL_COUNT, + successfully_downloaded_folders: BUILD_ARTIFACTS_TOTAL_COUNT - BUILD_ARTIFACTS_FAIL_COUNT + }, + reporter: reporter + } + } - try { + options.formData = data.toString(); let responseData = null; - request.post(options, function (err, resp, data) { - if(err) { - utils.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'api_failed_build_artifacts_status_update', null, rawArgs); - } else { - try { - responseData = JSON.parse(data); - } catch(e) { - responseData = {}; - } - if (resp.statusCode != 200) { - if (responseData && responseData["error"]) { - utils.sendUsageReport(bsConfig, args, responseData["error"], Constants.messageTypes.ERROR, 'api_failed_build_artifacts_status_update', null, rawArgs); + return new Promise (async (resolve, reject) => { + try { + request.post(options, function (err, resp, data) { + if(err) { + utils.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'api_failed_build_artifacts_status_update', null, rawArgs); + reject(err); + } else { + try { + responseData = JSON.parse(data); + } catch(e) { + responseData = {}; + } + if (resp.statusCode != 200) { + if (responseData && responseData["error"]) { + utils.sendUsageReport(bsConfig, args, responseData["error"], Constants.messageTypes.ERROR, 'api_failed_build_artifacts_status_update', null, rawArgs); + reject(responseData["error"]) + } + } } - } + resolve() + }); + } catch(err) { + utils.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'api_failed_build_artifacts_status_update', null, rawArgs); + reject(err); } }); - } catch (err) { - utils.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'api_failed_build_artifacts_status_update', null, rawArgs); - } } exports.downloadBuildArtifacts = async (bsConfig, buildId, args, rawArgs) => { - BUILD_ARTIFACTS_FAIL_COUNT = 0; - BUILD_ARTIFACTS_TOTAL_COUNT = 0; - - let options = { - url: `${config.buildUrl}${buildId}/build_artifacts`, - auth: { - username: bsConfig.auth.username, - password: bsConfig.auth.access_key, - }, - headers: { - 'User-Agent': utils.getUserAgent(), - }, - }; - - let message = null; - let messageType = null; - let errorCode = null; - - try { - let buildDetails = null; - request.get(options, async function (err, resp, body) { - if(err) { - utils.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'api_failed_build_artifacts', null, rawArgs); - process.exitCode = Constants.ERROR_EXIT_CODE; - } else { - try { - buildDetails = JSON.parse(body); - if(resp.statusCode != 200) { - logger.error('Downloading the build artifacts failed.'); - logger.error(`Error: Request failed with status code ${resp.statusCode}`) - utils.sendUsageReport(bsConfig, args, buildDetails, Constants.messageTypes.ERROR, 'api_failed_build_artifacts', null, rawArgs); - process.exitCode = Constants.ERROR_EXIT_CODE; - } else { - await createDirectories(buildId, buildDetails); - await parseAndDownloadArtifacts(buildId, buildDetails); + return new Promise ( async (resolve, reject) => { + BUILD_ARTIFACTS_FAIL_COUNT = 0; + BUILD_ARTIFACTS_TOTAL_COUNT = 0; + + let options = { + url: `${config.buildUrl}${buildId}/build_artifacts`, + auth: { + username: bsConfig.auth.username, + password: bsConfig.auth.access_key, + }, + headers: { + 'User-Agent': utils.getUserAgent(), + }, + }; + + let message = null; + let messageType = null; + let errorCode = null; + + try { + let buildDetails = null; + request.get(options, async function (err, resp, body) { + if(err) { + utils.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'api_failed_build_artifacts', null, rawArgs); + process.exitCode = Constants.ERROR_EXIT_CODE; + } else { + try { + buildDetails = JSON.parse(body); + if(resp.statusCode != 200) { + logger.error('Downloading the build artifacts failed.'); + logger.error(`Error: Request failed with status code ${resp.statusCode}`) + utils.sendUsageReport(bsConfig, args, buildDetails, Constants.messageTypes.ERROR, 'api_failed_build_artifacts', null, rawArgs); + process.exitCode = Constants.ERROR_EXIT_CODE; + } else { + await createDirectories(buildId, buildDetails); + await parseAndDownloadArtifacts(buildId, buildDetails); + if (BUILD_ARTIFACTS_FAIL_COUNT > 0) { + messageType = Constants.messageTypes.ERROR; + message = Constants.userMessages.DOWNLOAD_BUILD_ARTIFACTS_FAILED.replace('', buildId).replace('', BUILD_ARTIFACTS_FAIL_COUNT); + logger.error(message); + process.exitCode = Constants.ERROR_EXIT_CODE; + } else { + messageType = Constants.messageTypes.SUCCESS; + message = Constants.userMessages.DOWNLOAD_BUILD_ARTIFACTS_SUCCESS.replace('', buildId).replace('', process.cwd()); + logger.info(message); + } + await sendUpdatesToBstack(bsConfig, buildId, args, options, rawArgs) + utils.sendUsageReport(bsConfig, args, message, messageType, null, null, rawArgs); + } + } catch (err) { + messageType = Constants.messageTypes.ERROR; + errorCode = 'api_failed_build_artifacts'; if (BUILD_ARTIFACTS_FAIL_COUNT > 0) { messageType = Constants.messageTypes.ERROR; message = Constants.userMessages.DOWNLOAD_BUILD_ARTIFACTS_FAILED.replace('', buildId).replace('', BUILD_ARTIFACTS_FAIL_COUNT); logger.error(message); - process.exitCode = Constants.ERROR_EXIT_CODE; } else { - messageType = Constants.messageTypes.SUCCESS; - message = Constants.userMessages.DOWNLOAD_BUILD_ARTIFACTS_SUCCESS.replace('', buildId).replace('', process.cwd()); - logger.info(message); + logger.error('Downloading the build artifacts failed.'); } - await sendUpdatesToBstack(bsConfig, buildId, args, options, rawArgs); - utils.sendUsageReport(bsConfig, args, message, messageType, null, null, rawArgs); - } - } catch (err) { - messageType = Constants.messageTypes.ERROR; - errorCode = 'api_failed_build_artifacts'; - if (BUILD_ARTIFACTS_FAIL_COUNT > 0) { - messageType = Constants.messageTypes.ERROR; - message = Constants.userMessages.DOWNLOAD_BUILD_ARTIFACTS_FAILED.replace('', buildId).replace('', BUILD_ARTIFACTS_FAIL_COUNT); - logger.error(message); - } else { - logger.error('Downloading the build artifacts failed.'); + utils.sendUsageReport(bsConfig, args, err, messageType, errorCode, null, rawArgs); + logger.error(`Error: Request failed with status code ${resp.statusCode}`) + process.exitCode = Constants.ERROR_EXIT_CODE; } - utils.sendUsageReport(bsConfig, args, err, messageType, errorCode, null, rawArgs); - logger.error(err.message); - logger.error(`Error: Request failed with status code ${resp.statusCode}`) - process.exitCode = Constants.ERROR_EXIT_CODE; } - } - }); - } catch (err) { - utils.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'api_failed_build_artifacts', null, rawArgs); - process.exitCode = Constants.ERROR_EXIT_CODE; - } + }); + } catch (err) { + utils.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'api_failed_build_artifacts', null, rawArgs); + process.exitCode = Constants.ERROR_EXIT_CODE; + } + }); }; From 6ad54f52a145a1d31a817e94571e0de2db8024de Mon Sep 17 00:00:00 2001 From: roshan04 Date: Thu, 23 Dec 2021 11:39:30 +0530 Subject: [PATCH 06/19] handling flow for sync mode --- bin/commands/runs.js | 6 +----- bin/helpers/a.js | 48 ++++++++++++++++++++++++++++++++++++++++++++ package.json | 11 ++++++---- 3 files changed, 56 insertions(+), 9 deletions(-) create mode 100644 bin/helpers/a.js diff --git a/bin/commands/runs.js b/bin/commands/runs.js index f405a42f..2c42cd46 100644 --- a/bin/commands/runs.js +++ b/bin/commands/runs.js @@ -177,11 +177,7 @@ module.exports = function run(args, rawArgs) { // download build artifacts if (utils.nonEmptyArray(bsConfig.run_settings.downloads)) { - try { - await downloadBuildArtifacts(bsConfig, data.build_id, args, rawArgs); - } catch (err) { - logger.error(err); - } + await downloadBuildArtifacts(bsConfig, data.build_id, args, rawArgs); } // Generate custom report! diff --git a/bin/helpers/a.js b/bin/helpers/a.js new file mode 100644 index 00000000..d4ed0c06 --- /dev/null +++ b/bin/helpers/a.js @@ -0,0 +1,48 @@ +// with proxy +let a = { + path: 'https://api.browserstack.com/automate/cypress/v1/builds/8a4ec797f6565b72d84345bb507acd0f3a84f194/build_artifacts', + method: 'GET', + headers: { + Accept: 'application/json, text/plain, */*', + 'User-Agent': 'BStack-Cypress-CLI/1.10.0 (x64/darwin/20.6.0)', + host: 'api.browserstack.com' + }, + agent: undefined, + agents: { http: undefined, https: undefined }, + auth: 'roshanni_70sPLl:qN7mJW7aZ8P5Gnu1XtwX', + hostname: 'localhost', + port: '8889', + host: 'localhost', + beforeRedirect: [Function: beforeRedirect] +} +let c = { + path: '/automate/cypress/v1/builds/8a4ec797f6565b72d84345bb507acd0f3a84f194/build_artifacts', + method: 'GET', + headers: { + Accept: 'application/json, text/plain, */*', + 'User-Agent': 'BStack-Cypress-CLI/1.10.0 (x64/darwin/20.6.0)', + host: 'api.browserstack.com' + }, + agent: undefined, + agents: { http: undefined, https: undefined }, + auth: 'roshanni_70sPLl:qN7mJW7aZ8P5Gnu1XtwX', + hostname: 'localhost', + port: '8889', + host: 'localhost', + beforeRedirect: [Function: beforeRedirect] +} + +// without proxy +let b = { + path: '/automate/cypress/v1/builds/8a4ec797f6565b72d84345bb507acd0f3a84f194/build_artifacts', + method: 'GET', + headers: { + Accept: 'application/json, text/plain, */*', + 'User-Agent': 'BStack-Cypress-CLI/1.10.0 (x64/darwin/20.6.0)' + }, + agent: undefined, + agents: { http: undefined, https: undefined }, + auth: 'roshanni_70sPLl:qN7mJW7aZ8P5Gnu1XtwX', + hostname: 'api.browserstack.com', + port: null +} \ No newline at end of file diff --git a/package.json b/package.json index be13de88..ae343df4 100644 --- a/package.json +++ b/package.json @@ -14,21 +14,24 @@ "dependencies": { "archiver": "^5.2.0", "async": "^3.2.0", + "axios": "^0.20.0", + "axios-curlirize": "^1.3.7", "browserstack-local": "^1.4.8", "chalk": "^4.1.0", "fs-extra": "^8.1.0", "getmac": "^5.17.0", "glob": "^7.1.6", "mkdirp": "^1.0.3", + "node-fetch-with-proxy": "^0.1.6", "request": "^2.88.0", "requestretry": "^4.1.0", + "socks-proxy-agent": "^6.1.1", "table": "^5.4.6", + "unzipper": "^0.10.11", + "update-notifier": "^5.1.0", "uuid": "^8.3.2", "winston": "^2.3.1", - "yargs": "^14.2.3", - "axios": "^0.21.1", - "unzipper": "^0.10.11", - "update-notifier": "^5.1.0" + "yargs": "^14.2.3" }, "repository": { "type": "git", From c35bf56ed1e5bb9a8c6bafe68ec93eb1d6ee9958 Mon Sep 17 00:00:00 2001 From: roshan04 Date: Thu, 23 Dec 2021 11:44:31 +0530 Subject: [PATCH 07/19] removing unwanted changes --- package.json | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index ae343df4..be13de88 100644 --- a/package.json +++ b/package.json @@ -14,24 +14,21 @@ "dependencies": { "archiver": "^5.2.0", "async": "^3.2.0", - "axios": "^0.20.0", - "axios-curlirize": "^1.3.7", "browserstack-local": "^1.4.8", "chalk": "^4.1.0", "fs-extra": "^8.1.0", "getmac": "^5.17.0", "glob": "^7.1.6", "mkdirp": "^1.0.3", - "node-fetch-with-proxy": "^0.1.6", "request": "^2.88.0", "requestretry": "^4.1.0", - "socks-proxy-agent": "^6.1.1", "table": "^5.4.6", - "unzipper": "^0.10.11", - "update-notifier": "^5.1.0", "uuid": "^8.3.2", "winston": "^2.3.1", - "yargs": "^14.2.3" + "yargs": "^14.2.3", + "axios": "^0.21.1", + "unzipper": "^0.10.11", + "update-notifier": "^5.1.0" }, "repository": { "type": "git", From 94fffe563fe50636a3354af9c4515e64da045661 Mon Sep 17 00:00:00 2001 From: roshan04 Date: Thu, 23 Dec 2021 11:47:43 +0530 Subject: [PATCH 08/19] removing unwanted files --- bin/helpers/a.js | 48 ------------------------------------------------ 1 file changed, 48 deletions(-) delete mode 100644 bin/helpers/a.js diff --git a/bin/helpers/a.js b/bin/helpers/a.js deleted file mode 100644 index d4ed0c06..00000000 --- a/bin/helpers/a.js +++ /dev/null @@ -1,48 +0,0 @@ -// with proxy -let a = { - path: 'https://api.browserstack.com/automate/cypress/v1/builds/8a4ec797f6565b72d84345bb507acd0f3a84f194/build_artifacts', - method: 'GET', - headers: { - Accept: 'application/json, text/plain, */*', - 'User-Agent': 'BStack-Cypress-CLI/1.10.0 (x64/darwin/20.6.0)', - host: 'api.browserstack.com' - }, - agent: undefined, - agents: { http: undefined, https: undefined }, - auth: 'roshanni_70sPLl:qN7mJW7aZ8P5Gnu1XtwX', - hostname: 'localhost', - port: '8889', - host: 'localhost', - beforeRedirect: [Function: beforeRedirect] -} -let c = { - path: '/automate/cypress/v1/builds/8a4ec797f6565b72d84345bb507acd0f3a84f194/build_artifacts', - method: 'GET', - headers: { - Accept: 'application/json, text/plain, */*', - 'User-Agent': 'BStack-Cypress-CLI/1.10.0 (x64/darwin/20.6.0)', - host: 'api.browserstack.com' - }, - agent: undefined, - agents: { http: undefined, https: undefined }, - auth: 'roshanni_70sPLl:qN7mJW7aZ8P5Gnu1XtwX', - hostname: 'localhost', - port: '8889', - host: 'localhost', - beforeRedirect: [Function: beforeRedirect] -} - -// without proxy -let b = { - path: '/automate/cypress/v1/builds/8a4ec797f6565b72d84345bb507acd0f3a84f194/build_artifacts', - method: 'GET', - headers: { - Accept: 'application/json, text/plain, */*', - 'User-Agent': 'BStack-Cypress-CLI/1.10.0 (x64/darwin/20.6.0)' - }, - agent: undefined, - agents: { http: undefined, https: undefined }, - auth: 'roshanni_70sPLl:qN7mJW7aZ8P5Gnu1XtwX', - hostname: 'api.browserstack.com', - port: null -} \ No newline at end of file From 3a688823c1f79eabeba36950a7464651b1210c3c Mon Sep 17 00:00:00 2001 From: roshan04 Date: Thu, 23 Dec 2021 16:07:13 +0530 Subject: [PATCH 09/19] handling custom report requests and buil stop api --- bin/helpers/buildArtifacts.js | 209 ++++++++++++++++------------------ bin/helpers/reporterHTML.js | 81 ++++++++++--- bin/helpers/utils.js | 121 ++++++++++---------- 3 files changed, 227 insertions(+), 184 deletions(-) diff --git a/bin/helpers/buildArtifacts.js b/bin/helpers/buildArtifacts.js index 92cca4dd..efe7a3b5 100644 --- a/bin/helpers/buildArtifacts.js +++ b/bin/helpers/buildArtifacts.js @@ -98,35 +98,31 @@ const downloadAndUnzip = async (filePath, fileName, url) => { const writer = fs.createWriteStream(tmpFilePath); return new Promise(async (resolve, reject) => { - try { - request.get(url).on('response', function(response) { - - if(response.statusCode != 200) { - reject(); - } else { - //ensure that the user can call `then()` only when the file has - //been downloaded entirely. - response.pipe(writer); - let error = null; - writer.on('error', err => { - error = err; - writer.close(); - reject(err); - }); - writer.on('close', async () => { - if (!error) { - await unzipFile(filePath, fileName); - fs.unlinkSync(tmpFilePath); - resolve(true); - } - //no need to call the reject here, as it will have been called in the - //'error' stream; - }); - } - }); - } catch (err) { - reject(err); - } + request.get(url).on('response', function(response) { + + if(response.statusCode != 200) { + reject(); + } else { + //ensure that the user can call `then()` only when the file has + //been downloaded entirely. + response.pipe(writer); + let error = null; + writer.on('error', err => { + error = err; + writer.close(); + reject(err); + }); + writer.on('close', async () => { + if (!error) { + await unzipFile(filePath, fileName); + fs.unlinkSync(tmpFilePath); + resolve(true); + } + //no need to call the reject here, as it will have been called in the + //'error' stream; + }); + } + }); }); } @@ -140,55 +136,50 @@ const unzipFile = async (filePath, fileName) => { } const sendUpdatesToBstack = async (bsConfig, buildId, args, options, rawArgs) => { - options.url = `${config.buildUrl}${buildId}/build_artifacts/status`; + options.url = `${config.buildUrl}${buildId}/build_artifacts/status`; - let cypressJSON = utils.getCypressJSON(bsConfig); + let cypressJSON = utils.getCypressJSON(bsConfig); - let reporter = null; - if(!utils.isUndefined(args.reporter)) { - reporter = args.reporter; - } else if(cypressJSON !== undefined){ - reporter = cypressJSON.reporter; - } + let reporter = null; + if(!utils.isUndefined(args.reporter)) { + reporter = args.reporter; + } else if(cypressJSON !== undefined){ + reporter = cypressJSON.reporter; + } - let data = { - feature_usage: { - downloads: { - eligible_download_folders: BUILD_ARTIFACTS_TOTAL_COUNT, - successfully_downloaded_folders: BUILD_ARTIFACTS_TOTAL_COUNT - BUILD_ARTIFACTS_FAIL_COUNT - }, - reporter: reporter - } + let data = { + feature_usage: { + downloads: { + eligible_download_folders: BUILD_ARTIFACTS_TOTAL_COUNT, + successfully_downloaded_folders: BUILD_ARTIFACTS_TOTAL_COUNT - BUILD_ARTIFACTS_FAIL_COUNT + }, + reporter: reporter } + } - options.formData = data.toString(); - let responseData = null; - return new Promise (async (resolve, reject) => { - try { - request.post(options, function (err, resp, data) { - if(err) { - utils.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'api_failed_build_artifacts_status_update', null, rawArgs); - reject(err); - } else { - try { - responseData = JSON.parse(data); - } catch(e) { - responseData = {}; - } - if (resp.statusCode != 200) { - if (responseData && responseData["error"]) { - utils.sendUsageReport(bsConfig, args, responseData["error"], Constants.messageTypes.ERROR, 'api_failed_build_artifacts_status_update', null, rawArgs); - reject(responseData["error"]) - } - } - } - resolve() - }); - } catch(err) { + options.formData = data.toString(); + let responseData = null; + return new Promise (async (resolve, reject) => { + request.post(options, function (err, resp, data) { + if(err) { utils.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'api_failed_build_artifacts_status_update', null, rawArgs); reject(err); + } else { + try { + responseData = JSON.parse(data); + } catch(e) { + responseData = {}; + } + if (resp.statusCode != 200) { + if (responseData && responseData["error"]) { + utils.sendUsageReport(bsConfig, args, responseData["error"], Constants.messageTypes.ERROR, 'api_failed_build_artifacts_status_update', null, rawArgs); + reject(responseData["error"]) + } + } } + resolve() }); + }); } exports.downloadBuildArtifacts = async (bsConfig, buildId, args, rawArgs) => { @@ -210,56 +201,50 @@ exports.downloadBuildArtifacts = async (bsConfig, buildId, args, rawArgs) => { let message = null; let messageType = null; let errorCode = null; - - try { - let buildDetails = null; - request.get(options, async function (err, resp, body) { - if(err) { - utils.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'api_failed_build_artifacts', null, rawArgs); - process.exitCode = Constants.ERROR_EXIT_CODE; - } else { - try { - buildDetails = JSON.parse(body); - if(resp.statusCode != 200) { - logger.error('Downloading the build artifacts failed.'); - logger.error(`Error: Request failed with status code ${resp.statusCode}`) - utils.sendUsageReport(bsConfig, args, buildDetails, Constants.messageTypes.ERROR, 'api_failed_build_artifacts', null, rawArgs); - process.exitCode = Constants.ERROR_EXIT_CODE; - } else { - await createDirectories(buildId, buildDetails); - await parseAndDownloadArtifacts(buildId, buildDetails); - if (BUILD_ARTIFACTS_FAIL_COUNT > 0) { - messageType = Constants.messageTypes.ERROR; - message = Constants.userMessages.DOWNLOAD_BUILD_ARTIFACTS_FAILED.replace('', buildId).replace('', BUILD_ARTIFACTS_FAIL_COUNT); - logger.error(message); - process.exitCode = Constants.ERROR_EXIT_CODE; - } else { - messageType = Constants.messageTypes.SUCCESS; - message = Constants.userMessages.DOWNLOAD_BUILD_ARTIFACTS_SUCCESS.replace('', buildId).replace('', process.cwd()); - logger.info(message); - } - await sendUpdatesToBstack(bsConfig, buildId, args, options, rawArgs) - utils.sendUsageReport(bsConfig, args, message, messageType, null, null, rawArgs); - } - } catch (err) { - messageType = Constants.messageTypes.ERROR; - errorCode = 'api_failed_build_artifacts'; + let buildDetails = null; + request.get(options, async function (err, resp, body) { + if(err) { + utils.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'api_failed_build_artifacts', null, rawArgs); + process.exitCode = Constants.ERROR_EXIT_CODE; + } else { + try { + buildDetails = JSON.parse(body); + if(resp.statusCode != 200) { + logger.error('Downloading the build artifacts failed.'); + logger.error(`Error: Request failed with status code ${resp.statusCode}`) + utils.sendUsageReport(bsConfig, args, buildDetails, Constants.messageTypes.ERROR, 'api_failed_build_artifacts', null, rawArgs); + process.exitCode = Constants.ERROR_EXIT_CODE; + } else { + await createDirectories(buildId, buildDetails); + await parseAndDownloadArtifacts(buildId, buildDetails); if (BUILD_ARTIFACTS_FAIL_COUNT > 0) { messageType = Constants.messageTypes.ERROR; message = Constants.userMessages.DOWNLOAD_BUILD_ARTIFACTS_FAILED.replace('', buildId).replace('', BUILD_ARTIFACTS_FAIL_COUNT); logger.error(message); + process.exitCode = Constants.ERROR_EXIT_CODE; } else { - logger.error('Downloading the build artifacts failed.'); + messageType = Constants.messageTypes.SUCCESS; + message = Constants.userMessages.DOWNLOAD_BUILD_ARTIFACTS_SUCCESS.replace('', buildId).replace('', process.cwd()); + logger.info(message); } - utils.sendUsageReport(bsConfig, args, err, messageType, errorCode, null, rawArgs); - logger.error(`Error: Request failed with status code ${resp.statusCode}`) - process.exitCode = Constants.ERROR_EXIT_CODE; + await sendUpdatesToBstack(bsConfig, buildId, args, options, rawArgs) + utils.sendUsageReport(bsConfig, args, message, messageType, null, null, rawArgs); + } + } catch (err) { + messageType = Constants.messageTypes.ERROR; + errorCode = 'api_failed_build_artifacts'; + if (BUILD_ARTIFACTS_FAIL_COUNT > 0) { + messageType = Constants.messageTypes.ERROR; + message = Constants.userMessages.DOWNLOAD_BUILD_ARTIFACTS_FAILED.replace('', buildId).replace('', BUILD_ARTIFACTS_FAIL_COUNT); + logger.error(message); + } else { + logger.error('Downloading the build artifacts failed.'); } + utils.sendUsageReport(bsConfig, args, err, messageType, errorCode, null, rawArgs); + logger.error(`Error: Request failed with status code ${resp.statusCode}`) + process.exitCode = Constants.ERROR_EXIT_CODE; } - }); - } catch (err) { - utils.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'api_failed_build_artifacts', null, rawArgs); - process.exitCode = Constants.ERROR_EXIT_CODE; - } + } + }); }); }; diff --git a/bin/helpers/reporterHTML.js b/bin/helpers/reporterHTML.js index af732e5a..aecfd7bd 100644 --- a/bin/helpers/reporterHTML.js +++ b/bin/helpers/reporterHTML.js @@ -235,24 +235,74 @@ async function cypressReportData(report_data) { return report_data; } +function getConfigJsonResponse(combination) { + return new Promise(async (resolve, reject) => { + configJsonResponse = null; + configJsonError = false + request.get(combination.tests.config_json , function(err, resp, body) { + if(err) { + configJsonError = true; + reject([configJsonResponse, configJsonError]); + } else { + if(resp.statusCode != 200) { + configJsonError = true; + reject([configJsonResponse, configJsonError]); + } else { + try { + configJsonResponse = JSON.parse(body); + } catch (err) { + configJsonError = true + reject([configJsonResponse, configJsonError]); + } + } + } + resolve([configJsonResponse, configJsonError]); + }); + }); +} + +function getResultsJsonResponse(combination) { + return new Promise(async (resolve, reject) => { + resultsJsonResponse = null + resultsJsonError = false; + request.get(combination.tests.result_json , function(err, resp, body) { + if(err) { + resultsJsonError = true; + reject([resultsJsonResponse, resultsJsonError]); + } else { + if(resp.statusCode != 200) { + resultsJsonError = true; + reject([resultsJsonResponse, resultsJsonError]); + } else { + try { + resultsJsonResponse = JSON.parse(body); + } catch (err) { + resultsJsonError = true + reject([resultsJsonResponse, resultsJsonError]); + } + } + } + resolve([resultsJsonResponse, resultsJsonError]); + }); + }); +} + function generateCypressCombinationSpecReportDataWithConfigJson(combination){ return new Promise(async (resolve, reject) => { try { let configJsonError, resultsJsonError; - let [configJsonResponse, resultsJsonResponse] = await axios.all([ - axios.get(combination.tests.config_json).catch(function (error) { - configJsonError = true; - }), - axios.get(combination.tests.result_json).catch(function(error){ - resultsJsonError = true; - }) - ]); + let configJson, resultsJson; + + await Promise.all([getConfigJsonResponse(combination), getResultsJsonResponse(combination)]).then(function (successResult) { + [configJson, configJsonError, resultsJson, resultsJsonError] = successResult; + }).catch(function (failureResult) { + [configJson, configJsonError, resultsJson, resultsJsonError] = failureResult; + }); + if(resultsJsonError || configJsonError){ resolve(); } let tests = {}; - let configJson = configJsonResponse.data; - let resultsJson = resultsJsonResponse.data; if(utils.isUndefined(configJson.tests) || utils.isUndefined(resultsJson.tests)){ resolve(); } @@ -287,14 +337,15 @@ function generateCypressCombinationSpecReportDataWithConfigJson(combination){ function generateCypressCombinationSpecReportDataWithoutConfigJson(combination){ return new Promise(async (resolve, reject) => { try { - let resultsJsonError; - let resultsJsonResponse = await axios.get(combination.tests.result_json).catch(function(error){ - resultsJsonError = true; - }); + let resultsJson ,resultsJsonError; + await getResultsJsonResponse(combination).then(function (successResult) { + [resultsJson, resultsJsonError] = successResult + }).catch( function (failureResult) { + [resultsJson, resultsJsonError] = failureResult + }) if(resultsJsonError || utils.isUndefined(resultsJsonResponse)){ resolve(); } - let resultsJson = resultsJsonResponse.data; let sessionTests = []; if(utils.isUndefined(resultsJson.tests)){ resolve(); diff --git a/bin/helpers/utils.js b/bin/helpers/utils.js index 4e9c982e..3edd3c3b 100644 --- a/bin/helpers/utils.js +++ b/bin/helpers/utils.js @@ -954,67 +954,74 @@ exports.setCLIMode = (bsConfig, args) => { } exports.stopBrowserStackBuild = async (bsConfig, args, buildId, rawArgs) => { - let url = config.buildStopUrl + buildId; - let options = { - url: url, - auth: { - username: bsConfig["auth"]["username"], - password: bsConfig["auth"]["access_key"], - }, - headers: { - 'User-Agent': this.getUserAgent(), - }, - }; - - let message = null; - let messageType = null; - let errorCode = null; - try{ - let resp = await axios.post(url, {} , options); + let that = this; + return new Promise(function (resolve, reject) { + let url = config.buildStopUrl + buildId; + let options = { + url: url, + auth: { + username: bsConfig["auth"]["username"], + password: bsConfig["auth"]["access_key"], + }, + headers: { + 'User-Agent': that.getUserAgent(), + }, + }; + let message = null; + let messageType = null; + let errorCode = null; let build = null; - if(resp.data){ - build = resp.data; - } - - if (resp.status == 299) { - messageType = Constants.messageTypes.INFO; - errorCode = 'api_deprecated'; - - if (build) { - message = build.message; + request.post(options, function(err, resp, data) { + if(err) { + message = Constants.userMessages.BUILD_STOP_FAILED; + messageType = Constants.messageTypes.ERROR; + errorCode = 'api_failed_build_stop'; logger.info(message); } else { - message = Constants.userMessages.API_DEPRECATED; - logger.info(message); - } - } else if (resp.status != 200) { - messageType = Constants.messageTypes.ERROR; - errorCode = 'api_failed_build_stop'; - - if (build) { - message = `${ - Constants.userMessages.BUILD_STOP_FAILED - } with error: \n${JSON.stringify(build, null, 2)}`; - logger.error(message); - if (build.message === 'Unauthorized') errorCode = 'api_auth_failed'; - } else { - message = Constants.userMessages.BUILD_STOP_FAILED; - logger.error(message); + try { + build = JSON.parse(data); + if (resp.statusCode == 299) { + messageType = Constants.messageTypes.INFO; + errorCode = 'api_deprecated'; + + if (build) { + message = build.message; + logger.info(message); + } else { + message = Constants.userMessages.API_DEPRECATED; + logger.info(message); + } + } else if (resp.statusCode != 200) { + messageType = Constants.messageTypes.ERROR; + errorCode = 'api_failed_build_stop'; + + if (build) { + message = `${ + Constants.userMessages.BUILD_STOP_FAILED + } with error: \n${JSON.stringify(build, null, 2)}`; + logger.error(message); + if (build.message === 'Unauthorized') errorCode = 'api_auth_failed'; + } else { + message = Constants.userMessages.BUILD_STOP_FAILED; + logger.error(message); + } + } else { + messageType = Constants.messageTypes.SUCCESS; + message = `${JSON.stringify(build, null, 2)}`; + logger.info(message); + } + } catch(err) { + console.log(err); + message = Constants.userMessages.BUILD_STOP_FAILED; + messageType = Constants.messageTypes.ERROR; + errorCode = 'api_failed_build_stop'; + logger.info(message); + } finally { + that.sendUsageReport(bsConfig, args, message, messageType, errorCode, null, rawArgs); + } } - } else { - messageType = Constants.messageTypes.SUCCESS; - message = `${JSON.stringify(build, null, 2)}`; - logger.info(message); - } - } catch(err){ - console.log(err); - message = Constants.userMessages.BUILD_STOP_FAILED; - messageType = Constants.messageTypes.ERROR; - errorCode = 'api_failed_build_stop'; - logger.info(message); - } finally { - this.sendUsageReport(bsConfig, args, message, messageType, errorCode, null, rawArgs); - } + }); + }); } exports.setProcessHooks = (buildId, bsConfig, bsLocal, args) => { From 36608b2aed489de042e1236a9b7f39d274e5259a Mon Sep 17 00:00:00 2001 From: roshan04 Date: Thu, 23 Dec 2021 16:57:32 +0530 Subject: [PATCH 10/19] handled sync mode for custom reports --- bin/helpers/buildArtifacts.js | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/helpers/buildArtifacts.js b/bin/helpers/buildArtifacts.js index efe7a3b5..73d922a7 100644 --- a/bin/helpers/buildArtifacts.js +++ b/bin/helpers/buildArtifacts.js @@ -245,6 +245,7 @@ exports.downloadBuildArtifacts = async (bsConfig, buildId, args, rawArgs) => { process.exitCode = Constants.ERROR_EXIT_CODE; } } + resolve(); }); }); }; From dbdaee2331ade404eedbfeb494758e70f896409e Mon Sep 17 00:00:00 2001 From: roshan04 Date: Thu, 23 Dec 2021 18:41:57 +0530 Subject: [PATCH 11/19] added specs for changes --- bin/helpers/reporterHTML.js | 4 +- bin/helpers/utils.js | 2 +- test/unit/bin/helpers/reporterHTML.js | 47 ++++++++++---------- test/unit/bin/helpers/utils.js | 54 +++++++++++------------ test/unit/support/fixtures/testObjects.js | 4 +- 5 files changed, 55 insertions(+), 56 deletions(-) diff --git a/bin/helpers/reporterHTML.js b/bin/helpers/reporterHTML.js index aecfd7bd..29a9264b 100644 --- a/bin/helpers/reporterHTML.js +++ b/bin/helpers/reporterHTML.js @@ -294,9 +294,9 @@ function generateCypressCombinationSpecReportDataWithConfigJson(combination){ let configJson, resultsJson; await Promise.all([getConfigJsonResponse(combination), getResultsJsonResponse(combination)]).then(function (successResult) { - [configJson, configJsonError, resultsJson, resultsJsonError] = successResult; + [[configJson, configJsonError], [resultsJson, resultsJsonError]] = successResult; }).catch(function (failureResult) { - [configJson, configJsonError, resultsJson, resultsJsonError] = failureResult; + [[configJson, configJsonError], [resultsJson, resultsJsonError]] = failureResult; }); if(resultsJsonError || configJsonError){ diff --git a/bin/helpers/utils.js b/bin/helpers/utils.js index 3edd3c3b..74e1ec66 100644 --- a/bin/helpers/utils.js +++ b/bin/helpers/utils.js @@ -18,7 +18,6 @@ const usageReporting = require("./usageReporting"), pkg = require('../../package.json'); const request = require('request'); -const axios = require("axios"); exports.validateBstackJson = (bsConfigPath) => { return new Promise(function (resolve, reject) { @@ -1021,6 +1020,7 @@ exports.stopBrowserStackBuild = async (bsConfig, args, buildId, rawArgs) => { } } }); + resolve(); }); } diff --git a/test/unit/bin/helpers/reporterHTML.js b/test/unit/bin/helpers/reporterHTML.js index 16e0d0b5..4c3be0a8 100644 --- a/test/unit/bin/helpers/reporterHTML.js +++ b/test/unit/bin/helpers/reporterHTML.js @@ -276,6 +276,7 @@ describe("reportHTML", () => { describe("Modify Cypress Report Data", ()=> { const reporterHTML = rewire('../../../../bin/helpers/reporterHTML'); const cypressReportData = reporterHTML.__get__('cypressReportData'); + let getMock = sinon.mock(request); const cypress_report_data_with_config = { cypress_version: "6.8.0", rows: { @@ -307,32 +308,32 @@ describe("reportHTML", () => { } } it("Generate Report Data for cypress version > 6", async ()=>{ - let configResponse = { data: { - tests: [ + let configResponse = { + "tests": [ { - clientId: "r3", - title:[ + "clientId": "r3", + "title":[ "file_name", "test_case" ] } ] - } } - let resultsResponse = { data: { - tests: [ + } + let resultsResponse = { + "tests": [ { - clientId: "r3", - state: "passed", - attempts:[ + "clientId": "r3", + "state": "passed", + "attempts":[ { "state": "passed", - "wallClockDuration": 62 + "wallClockDuration": "62" } ] } ] - } } - let expectedResponse = { + } + let expectedResponse = { cypress_version: "6.8.0", rows:{ "todo.spec.js": { @@ -344,18 +345,17 @@ describe("reportHTML", () => { }] } } - } - let axiosGetStub = sandbox.stub(axios, "get") - let axiosConfigStub = axiosGetStub.withArgs("config_json").resolves(configResponse); - let axiosResultStub = axiosGetStub.withArgs("result_json").resolves(resultsResponse); + } + let getConfigJsonResponse = getMock.expects('get').withArgs("config_json").yields(undefined, { statusCode: 200 }, JSON.stringify(configResponse)); + let getResultsJsonResponse = getMock.expects('get').withArgs("result_json").yields(undefined, { statusCode: 200 }, JSON.stringify(resultsResponse)); let result = await cypressReportData(cypress_report_data_with_config); - sinon.assert.calledOnce(axiosConfigStub); - sinon.assert.calledOnce(axiosResultStub); + sinon.assert.calledOnce(getConfigJsonResponse); + sinon.assert.calledOnce(getResultsJsonResponse); expect(JSON.stringify(result)).to.be.equal(JSON.stringify(expectedResponse)); }); it("Generate Report Data for cypress version < 6", async ()=>{ - let resultsResponse = { data: { + let resultsResponse = { tests: [ { clientId: "r3", @@ -372,7 +372,7 @@ describe("reportHTML", () => { ] } ] - } } + } let expectedResponse = { cypress_version: "5.6.0", rows:{ @@ -386,10 +386,9 @@ describe("reportHTML", () => { } } } - let axiosGetStub = sandbox.stub(axios, "get") - let axiosResultStub = axiosGetStub.withArgs("result_json").resolves(resultsResponse); + let getResultsJsonResponse = getMock.expects('get').withArgs("result_json").yields(undefined, { statusCode: 200 }, JSON.stringify(resultsResponse)); let result = await cypressReportData(cypress_report_data_without_config); - sinon.assert.calledOnce(axiosResultStub); + sinon.assert.calledOnce(getResultsJsonResponse); expect(JSON.stringify(result)).to.be.equal(JSON.stringify(expectedResponse)); }); }); diff --git a/test/unit/bin/helpers/utils.js b/test/unit/bin/helpers/utils.js index f0fb3d04..6aaeed5f 100644 --- a/test/unit/bin/helpers/utils.js +++ b/test/unit/bin/helpers/utils.js @@ -11,8 +11,7 @@ const chai = require('chai'), chalk = require('chalk'), os = require("os"), crypto = require('crypto'), - fs = require('fs'), - axios = require('axios'); + fs = require('fs'); const getmac = require('getmac').default; const usageReporting = require('../../../../bin/helpers/usageReporting'); const utils = require('../../../../bin/helpers/utils'), @@ -2555,7 +2554,7 @@ describe('utils', () => { }); describe('stopBrowserStackBuild', () => { - let axiosPostStub, getUserAgentStub, sendUsageReportStub, message, messageType, errorCode; + let getUserAgentStub, sendUsageReportStub, message, messageType, errorCode; let bsConfig = testObjects.sampleBsConfig; let args = {}; let rawArgs = {}; @@ -2563,12 +2562,10 @@ describe('utils', () => { let body = testObjects.buildStopSampleBody; beforeEach(() => { - axiosPostStub = sandbox.stub(axios, "post"); getUserAgentStub = sinon.stub(utils, 'getUserAgent').returns('user-agent'); sendUsageReportStub = sinon.stub(utils, 'sendUsageReport'); }); afterEach(()=>{ - axiosPostStub.restore(); getUserAgentStub.restore(); sendUsageReportStub.restore(); sandbox.restore(); @@ -2576,54 +2573,56 @@ describe('utils', () => { it('message thrown if API deprecated', async () => { let api_deprecated_response = { - status: 299 + statusCode: 299 } message = constant.userMessages.API_DEPRECATED; messageType = constant.messageTypes.INFO; errorCode = 'api_deprecated'; - axiosPostStub.resolves(api_deprecated_response); + let requestStub = sinon.stub(request, 'post').yields(undefined, api_deprecated_response, null); await utils.stopBrowserStackBuild(bsConfig, args, buildId, rawArgs); - sinon.assert.calledOnce(axiosPostStub); + sinon.assert.calledOnce(requestStub); sinon.assert.calledOnce(getUserAgentStub); sinon.assert.calledOnceWithExactly(sendUsageReportStub, bsConfig, args, message, messageType, errorCode, null, rawArgs); + requestStub.restore(); }); it('message thrown if build returned', async () => { let api_deprecated_response = { - status: 299, - data: body + statusCode: 299, } message = body.message; messageType = constant.messageTypes.INFO; errorCode = 'api_deprecated'; - axiosPostStub.resolves(api_deprecated_response); + let requestStub = sinon.stub(request, 'post').yields(undefined, api_deprecated_response, JSON.stringify(body)); await utils.stopBrowserStackBuild(bsConfig, args, buildId, rawArgs); - sinon.assert.calledOnce(axiosPostStub); + sinon.assert.calledOnce(requestStub); sinon.assert.calledOnce(getUserAgentStub); sinon.assert.calledOnceWithExactly(sendUsageReportStub, bsConfig, args, message, messageType, errorCode, null, rawArgs); + requestStub.restore(); }); it('message thrown if statusCode != 200', async () => { let non_200_status_response = { - status: 400 + statusCode: 400 } message = constant.userMessages.BUILD_STOP_FAILED; messageType = constant.messageTypes.ERROR; errorCode = 'api_failed_build_stop'; - axiosPostStub.resolves(non_200_status_response); + let requestStub = sinon.stub(request, 'post').yields(undefined, non_200_status_response, null); await utils.stopBrowserStackBuild(bsConfig, args, buildId, rawArgs); - sinon.assert.calledOnce(axiosPostStub); + sinon.assert.calledOnce(requestStub); sinon.assert.calledOnce(getUserAgentStub); sinon.assert.calledOnceWithExactly(sendUsageReportStub, bsConfig, args, message, messageType, errorCode, null, rawArgs); + requestStub.restore(); }); it('message thrown if statusCode != 200 and user unauthorized', async () => { let body_with_message = { ...body, - message: "Unauthorized", + "message": "Unauthorized", }; let non_200_status_response = { - status: 401, + statusCode: 401, data: body_with_message } @@ -2632,17 +2631,17 @@ describe('utils', () => { } with error: \n${JSON.stringify(body_with_message, null, 2)}`; messageType = constant.messageTypes.ERROR; errorCode = 'api_auth_failed'; - axiosPostStub.resolves(non_200_status_response); + let requestStub = sinon.stub(request, 'post').yields(undefined, non_200_status_response, JSON.stringify(body_with_message)); await utils.stopBrowserStackBuild(bsConfig, args, buildId, rawArgs); - sinon.assert.calledOnce(axiosPostStub); + sinon.assert.calledOnce(requestStub); sinon.assert.calledOnce(getUserAgentStub); sinon.assert.calledOnceWithExactly(sendUsageReportStub, bsConfig, args, message, messageType, errorCode, null, rawArgs); + requestStub.restore(); }); it('message thrown if statusCode != 200 and build is present', async () => { let non_200_status_response = { - status: 402, - data: body + statusCode: 402, } message = `${ @@ -2650,27 +2649,28 @@ describe('utils', () => { } with error: \n${JSON.stringify(body, null, 2)}`; messageType = constant.messageTypes.ERROR; errorCode = 'api_failed_build_stop'; - axiosPostStub.resolves(non_200_status_response); + let requestStub = sinon.stub(request, 'post').yields(undefined, non_200_status_response, JSON.stringify(body)); await utils.stopBrowserStackBuild(bsConfig, args, buildId, rawArgs); - sinon.assert.calledOnce(axiosPostStub); + sinon.assert.calledOnce(requestStub); sinon.assert.calledOnce(getUserAgentStub); sinon.assert.calledOnceWithExactly(sendUsageReportStub, bsConfig, args, message, messageType, errorCode, null, rawArgs); + requestStub.restore(); }); it('message thrown if API success', async () => { let success_response = { - status: 200, - data: body + statusCode: 200, } message = `${JSON.stringify(body, null, 2)}`; messageType = constant.messageTypes.SUCCESS; errorCode = null; - axiosPostStub.resolves(success_response); + let requestStub = sinon.stub(request, 'post').yields(undefined, success_response, JSON.stringify(body)); await utils.stopBrowserStackBuild(bsConfig, args, buildId, rawArgs); - sinon.assert.calledOnce(axiosPostStub); + sinon.assert.calledOnce(requestStub); sinon.assert.calledOnce(getUserAgentStub); sinon.assert.calledOnceWithExactly(sendUsageReportStub, bsConfig, args, message, messageType, errorCode, null, rawArgs); + requestStub.restore(); }); }); diff --git a/test/unit/support/fixtures/testObjects.js b/test/unit/support/fixtures/testObjects.js index 51312b06..f3155e55 100644 --- a/test/unit/support/fixtures/testObjects.js +++ b/test/unit/support/fixtures/testObjects.js @@ -151,8 +151,8 @@ const buildStopSampleRawArgs = { }; const buildStopSampleBody = { - message: "stopped 1 sessions", - stopped_session_count: 1, + "message": "stopped 1 sessions", + "stopped_session_count": "1" }; const sampleCapsData = { From 53b096ac8d071b41a7c4685d470027651ef26b96 Mon Sep 17 00:00:00 2001 From: roshan04 Date: Thu, 23 Dec 2021 20:00:25 +0530 Subject: [PATCH 12/19] fixed failing spec changes --- test/unit/bin/helpers/reporterHTML.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/unit/bin/helpers/reporterHTML.js b/test/unit/bin/helpers/reporterHTML.js index 4c3be0a8..d81e7903 100644 --- a/test/unit/bin/helpers/reporterHTML.js +++ b/test/unit/bin/helpers/reporterHTML.js @@ -276,7 +276,7 @@ describe("reportHTML", () => { describe("Modify Cypress Report Data", ()=> { const reporterHTML = rewire('../../../../bin/helpers/reporterHTML'); const cypressReportData = reporterHTML.__get__('cypressReportData'); - let getMock = sinon.mock(request); + let getMock; const cypress_report_data_with_config = { cypress_version: "6.8.0", rows: { @@ -307,6 +307,12 @@ describe("reportHTML", () => { } } } + beforeEach(() =>{ + getMock = sinon.mock(request); + }) + afterEach(() =>{ + getMock.restore(); + }) it("Generate Report Data for cypress version > 6", async ()=>{ let configResponse = { "tests": [ From 2c672e20befec86f23d8f4f9aa37d024815a1747 Mon Sep 17 00:00:00 2001 From: roshan04 Date: Thu, 23 Dec 2021 20:26:29 +0530 Subject: [PATCH 13/19] handled async stop req --- bin/helpers/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/helpers/utils.js b/bin/helpers/utils.js index 74e1ec66..5affe046 100644 --- a/bin/helpers/utils.js +++ b/bin/helpers/utils.js @@ -1019,8 +1019,8 @@ exports.stopBrowserStackBuild = async (bsConfig, args, buildId, rawArgs) => { that.sendUsageReport(bsConfig, args, message, messageType, errorCode, null, rawArgs); } } + resolve(); }); - resolve(); }); } From 419e6d0aec2ac6406354f1a135a8be11fef97c8a Mon Sep 17 00:00:00 2001 From: roshan04 Date: Mon, 27 Dec 2021 11:26:10 +0530 Subject: [PATCH 14/19] removing axios lib from package.json --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index be13de88..0c15fad1 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,6 @@ "uuid": "^8.3.2", "winston": "^2.3.1", "yargs": "^14.2.3", - "axios": "^0.21.1", "unzipper": "^0.10.11", "update-notifier": "^5.1.0" }, From 2017d608c135c16f781dc8d91ac6d9296569f647 Mon Sep 17 00:00:00 2001 From: Karan Nagpal Date: Tue, 28 Dec 2021 11:43:19 +0530 Subject: [PATCH 15/19] merge master --- bin/helpers/zipUpload.js | 51 +++++++++++++++++++++++++++++++++++++--- package.json | 8 ++++--- 2 files changed, 53 insertions(+), 6 deletions(-) diff --git a/bin/helpers/zipUpload.js b/bin/helpers/zipUpload.js index fcd5145a..a0872f14 100644 --- a/bin/helpers/zipUpload.js +++ b/bin/helpers/zipUpload.js @@ -1,6 +1,11 @@ 'use strict'; + +const request = require("request"), + fs = require("fs"); + +const cliProgress = require('cli-progress'); + const config = require("./config"), - request = require("request"), logger = require("./logger").winstonLogger, Constants = require("./constants"), utils = require("./utils"); @@ -16,11 +21,29 @@ const uploadSuits = (bsConfig, filePath, opts) => { return resolve({}); } - logger.info(opts.messages.uploading); + let size = fs.lstatSync(filePath).size; + + // create new progress bar + let bar1 = new cliProgress.SingleBar({ + format: `${filePath} [{bar}] {percentage}% | ETA: {eta}s | Speed: {speed} kbps | Duration: {duration}s`, + hideCursor: true, + }); + + bar1.start(100, 0, { + speed: "N/A" + }); + + bar1.on('start', () => { + }); + + bar1.on('stop', () => { + }); let options = utils.generateUploadParams(bsConfig, filePath, opts.md5Data, opts.fileDetails) let responseData = null; - request.post(options, function (err, resp, body) { + var r = request.post(options, function (err, resp, body) { + clearInterval(q); + if (err) { reject(err); } else { @@ -52,6 +75,10 @@ const uploadSuits = (bsConfig, filePath, opts) => { } } } else { + bar1.update(100, { + speed: ((size / (Date.now() - startTime)) / 125).toFixed(2) //kbits per sec + }); + bar1.stop(); logger.info(`${opts.messages.uploadingSuccess} (${responseData[opts.md5ReturnKey]})`); opts.cleanupMethod(); responseData["time"] = Date.now() - startTime; @@ -59,6 +86,15 @@ const uploadSuits = (bsConfig, filePath, opts) => { } } }); + + var q = setInterval(function () { + let dispatched = r.req.connection._bytesDispatched; + let percent = dispatched * 100.0 / size; + bar1.update(percent, { + speed: ((dispatched / (Date.now() - startTime)) / 125).toFixed(2) //kbits per sec + }); + }, 150); + }); } @@ -68,6 +104,15 @@ const uploadCypressZip = (bsConfig, md5data, packageData) => { let obj = {} const zipOptions = utils.generateUploadOptions('zip', md5data, packageData); const npmOptions = utils.generateUploadOptions('npm', md5data, packageData); + + if (!zipOptions.urlPresent && zipOptions.archivePresent) { + logger.info(zipOptions.messages.uploading); + } + + if (!npmOptions.urlPresent && npmOptions.archivePresent) { + logger.info(npmOptions.messages.uploading); + } + let zipUpload = uploadSuits(bsConfig, config.fileName, zipOptions); let npmPackageUpload = uploadSuits(bsConfig, config.packageFileName, npmOptions); Promise.all([zipUpload, npmPackageUpload]).then(function (uploads) { diff --git a/package.json b/package.json index 0c15fad1..3000408f 100644 --- a/package.json +++ b/package.json @@ -14,8 +14,10 @@ "dependencies": { "archiver": "^5.2.0", "async": "^3.2.0", + "axios": "^0.21.1", "browserstack-local": "^1.4.8", "chalk": "^4.1.0", + "cli-progress": "^3.9.1", "fs-extra": "^8.1.0", "getmac": "^5.17.0", "glob": "^7.1.6", @@ -23,11 +25,11 @@ "request": "^2.88.0", "requestretry": "^4.1.0", "table": "^5.4.6", + "unzipper": "^0.10.11", + "update-notifier": "^5.1.0", "uuid": "^8.3.2", "winston": "^2.3.1", - "yargs": "^14.2.3", - "unzipper": "^0.10.11", - "update-notifier": "^5.1.0" + "yargs": "^14.2.3" }, "repository": { "type": "git", From 02c2bb9494d3a25f1eea499de7b708950ad5a729 Mon Sep 17 00:00:00 2001 From: Karan Nagpal Date: Fri, 10 Dec 2021 15:01:11 +0530 Subject: [PATCH 16/19] fix tests and add size in bar --- bin/helpers/zipUpload.js | 2 +- test/unit/bin/helpers/zipUpload.js | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/bin/helpers/zipUpload.js b/bin/helpers/zipUpload.js index a0872f14..5acbba40 100644 --- a/bin/helpers/zipUpload.js +++ b/bin/helpers/zipUpload.js @@ -25,7 +25,7 @@ const uploadSuits = (bsConfig, filePath, opts) => { // create new progress bar let bar1 = new cliProgress.SingleBar({ - format: `${filePath} [{bar}] {percentage}% | ETA: {eta}s | Speed: {speed} kbps | Duration: {duration}s`, + format: `${filePath} [{bar}] {percentage}% | ETA: {eta}s | Speed: {speed} kbps | Duration: {duration}s [${(size / 1000000).toFixed(2)} MB]`, hideCursor: true, }); diff --git a/test/unit/bin/helpers/zipUpload.js b/test/unit/bin/helpers/zipUpload.js index 4dba979e..9028c620 100644 --- a/test/unit/bin/helpers/zipUpload.js +++ b/test/unit/bin/helpers/zipUpload.js @@ -2,12 +2,14 @@ const chai = require("chai"), chaiAsPromised = require("chai-as-promised"), sinon = require("sinon"), + fs = require('fs'), request = require("request"); const logger = require("../../../../bin/helpers/logger").winstonLogger, constant = require('../../../../bin/helpers/constants'); -const rewire = require("rewire"); +const rewire = require("rewire"), + cliProgress = require('cli-progress'); chai.use(chaiAsPromised); logger.transports["console.info"].silent = true; @@ -15,8 +17,19 @@ logger.transports["console.info"].silent = true; describe("zipUpload", () => { let sandbox; + let barStub; + beforeEach(() => { sandbox = sinon.createSandbox(); + + barStub = { + start: sinon.stub(), + stop: sinon.stub(), + update: sinon.stub(), + on: sinon.stub(), + } + + sinon.stub(cliProgress, 'SingleBar').returns(barStub); }); afterEach(() => { @@ -36,6 +49,11 @@ describe("zipUpload", () => { loggerStub = { info: sandbox.stub().returns(null) }; + sinon.stub(fs, 'lstatSync').returns({ size: 123 }); + }); + + afterEach(() => { + fs.lstatSync.restore(); }); it("reject with error", () => { From 28d4fe7139792d7f59bb09d99e727a1be86c4a21 Mon Sep 17 00:00:00 2001 From: Karan Nagpal Date: Mon, 27 Dec 2021 11:54:39 +0530 Subject: [PATCH 17/19] remove axios from package.json --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index 3000408f..ac48475a 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,6 @@ "dependencies": { "archiver": "^5.2.0", "async": "^3.2.0", - "axios": "^0.21.1", "browserstack-local": "^1.4.8", "chalk": "^4.1.0", "cli-progress": "^3.9.1", From 0587f03aac8256594e8385cdceea3458610c4c72 Mon Sep 17 00:00:00 2001 From: Karan Nagpal Date: Tue, 28 Dec 2021 11:37:21 +0530 Subject: [PATCH 18/19] remove axios imports --- bin/helpers/buildArtifacts.js | 3 +-- bin/helpers/reporterHTML.js | 3 +-- test/unit/bin/helpers/reporterHTML.js | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/bin/helpers/buildArtifacts.js b/bin/helpers/buildArtifacts.js index 73d922a7..1be18432 100644 --- a/bin/helpers/buildArtifacts.js +++ b/bin/helpers/buildArtifacts.js @@ -3,8 +3,7 @@ const fs = require('fs'), path = require('path'); -const axios = require('axios'), - unzipper = require('unzipper'); +const unzipper = require('unzipper'); const logger = require('./logger').winstonLogger, utils = require("./utils"), diff --git a/bin/helpers/reporterHTML.js b/bin/helpers/reporterHTML.js index 29a9264b..875d3200 100644 --- a/bin/helpers/reporterHTML.js +++ b/bin/helpers/reporterHTML.js @@ -4,8 +4,7 @@ const fs = require('fs'), logger = require('./logger').winstonLogger, utils = require("./utils"), Constants = require('./constants'), - config = require("./config"), - axios = require("axios"); + config = require("./config"); let templatesDir = path.join(__dirname, '../', 'templates'); diff --git a/test/unit/bin/helpers/reporterHTML.js b/test/unit/bin/helpers/reporterHTML.js index d81e7903..9bea002f 100644 --- a/test/unit/bin/helpers/reporterHTML.js +++ b/test/unit/bin/helpers/reporterHTML.js @@ -2,8 +2,7 @@ const { expect } = require("chai"); const chai = require("chai"), chaiAsPromised = require("chai-as-promised"), sinon = require('sinon'), - rewire = require('rewire'), - axios = require('axios'); + rewire = require('rewire'); const fs = require('fs'), path = require('path'), From 2f71cd479698a25c92549d063790516b9f433d06 Mon Sep 17 00:00:00 2001 From: Karan Nagpal Date: Tue, 28 Dec 2021 14:13:15 +0530 Subject: [PATCH 19/19] add logging if skipping uploading --- bin/helpers/constants.js | 2 ++ bin/helpers/zipUpload.js | 3 +++ 2 files changed, 5 insertions(+) diff --git a/bin/helpers/constants.js b/bin/helpers/constants.js index 30dea4c7..f758d963 100644 --- a/bin/helpers/constants.js +++ b/bin/helpers/constants.js @@ -43,6 +43,8 @@ const userMessages = { UPLOADING_TESTS_SUCCESS: "Uploaded tests successfully", UPLOADING_NPM_PACKAGES: "Uploading required node_modules to BrowserStack", UPLOADING_NPM_PACKAGES_SUCCESS: "Uploaded node_modules successfully", + SKIP_UPLOADING_TESTS: "Skipping zip upload since BrowserStack already has your test suite that has not changed since the last run.", + SKIP_UPLOADING_NPM_PACKAGES: "Skipping the upload of node_modules since BrowserStack has already cached your npm dependencies that have not changed since the last run.", LOCAL_TRUE: "you will now be able to test localhost / private URLs", LOCAL_FALSE: "you won't be able to test localhost / private URLs", EXIT_SYNC_CLI_MESSAGE: "Exiting the CLI, but your build is still running. You can use the --sync option to keep getting test updates. You can also use the build-info command now.", diff --git a/bin/helpers/zipUpload.js b/bin/helpers/zipUpload.js index 5acbba40..dabea8fa 100644 --- a/bin/helpers/zipUpload.js +++ b/bin/helpers/zipUpload.js @@ -105,6 +105,9 @@ const uploadCypressZip = (bsConfig, md5data, packageData) => { const zipOptions = utils.generateUploadOptions('zip', md5data, packageData); const npmOptions = utils.generateUploadOptions('npm', md5data, packageData); + if(zipOptions.urlPresent) logger.info(Constants.userMessages.SKIP_UPLOADING_TESTS); + if(npmOptions.urlPresent) logger.info(Constants.userMessages.SKIP_UPLOADING_NPM_PACKAGES); + if (!zipOptions.urlPresent && zipOptions.archivePresent) { logger.info(zipOptions.messages.uploading); }