From 99e7748c500e7c700a7052ac68d4830e00c0ac99 Mon Sep 17 00:00:00 2001 From: Roshan Nikam Date: Tue, 16 Nov 2021 18:19:36 +0530 Subject: [PATCH 1/9] added extra columns in cli stats --- bin/commands/runs.js | 14 ++++++++++++-- bin/helpers/usageReporting.js | 10 ++++++++++ bin/helpers/utils.js | 4 ++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/bin/commands/runs.js b/bin/commands/runs.js index a4ee13c4..6de092b6 100644 --- a/bin/commands/runs.js +++ b/bin/commands/runs.js @@ -94,6 +94,9 @@ module.exports = function run(args) { //get the number of spec files let specFiles = utils.getNumberOfSpecFiles(bsConfig, args, cypressJson); + // return the number of parallels user specified + let userSpecifiedParallels = utils.getParallels(bsConfig, args); + // accept the number of parallels utils.setParallels(bsConfig, args, specFiles.length); @@ -132,6 +135,12 @@ module.exports = function run(args) { utils.setProcessHooks(data.build_id, bsConfig, bs_local, args); let message = `${data.message}! ${Constants.userMessages.BUILD_CREATED} with build id: ${data.build_id}`; let dashboardLink = `${Constants.userMessages.VISIT_DASHBOARD} ${data.dashboard_url}`; + let buildReportData = { + 'user_id': data.user_details.id, + 'group_id': data.user_details.group_id, + 'parallels_specified': userSpecifiedParallels, + 'parallels_allotted': bsConfig.run_settings.parallels + }; utils.exportResults(data.build_id, `${config.dashboardUrl}${data.build_id}`); if ((utils.isUndefined(bsConfig.run_settings.parallels) && utils.isUndefined(args.parallels)) || (!utils.isUndefined(bsConfig.run_settings.parallels) && bsConfig.run_settings.parallels == Constants.cliMessages.RUN.DEFAULT_PARALLEL_MESSAGE)) { logger.warn(Constants.userMessages.NO_PARALLELS); @@ -169,7 +178,7 @@ module.exports = function run(args) { // Generate custom report! reportGenerator(bsConfig, data.build_id, args, function(){ - utils.sendUsageReport(bsConfig, args, `${message}\n${dashboardLink}`, Constants.messageTypes.SUCCESS, null); + utils.sendUsageReport(bsConfig, args, `${message}\n${dashboardLink}`, Constants.messageTypes.SUCCESS, null, buildReportData); utils.handleSyncExit(exitCode, data.dashboard_url); }); }); @@ -195,7 +204,8 @@ module.exports = function run(args) { dataToSend.used_auto_local = bsConfig.connection_settings.usedAutoLocal; } } - utils.sendUsageReport(bsConfig, args, `${message}\n${dashboardLink}`, Constants.messageTypes.SUCCESS, null, dataToSend); + buildReportData = { ...buildReportData, ...dataToSend }; + utils.sendUsageReport(bsConfig, args, `${message}\n${dashboardLink}`, Constants.messageTypes.SUCCESS, null, buildReportData); return; }).catch(async function (err) { // Build creation failed diff --git a/bin/helpers/usageReporting.js b/bin/helpers/usageReporting.js index 114013ae..a30372f8 100644 --- a/bin/helpers/usageReporting.js +++ b/bin/helpers/usageReporting.js @@ -181,11 +181,21 @@ function send(args) { data.cypress_version = bsConfig.run_settings.cypress_version } + bsConfig['auth']['username'] = "[REDACTED]" + bsConfig['auth']['access_key'] = "[REDACTED]" + delete args.bstack_config; const payload = { event_type: "cypress_cli_stats", data: { + build_id: data.build_id, + user_id: data.user_id, + group_id: data.group_id, + parallels_specified: data.parallels_specified, + parallels_allotted: data.parallels_allotted, + bstack_json: bsConfig, + run_settings: bsConfig.run_settings, os: _os(), os_version: os_version(), bstack_json_found_in_pwd: bstack_json_found_in_pwd(), diff --git a/bin/helpers/utils.js b/bin/helpers/utils.js index b58ffdee..26b7ffbc 100644 --- a/bin/helpers/utils.js +++ b/bin/helpers/utils.js @@ -138,6 +138,10 @@ exports.setUsageReportingFlag = (bsConfig, disableUsageReporting) => { } }; +exports.getParallels = (bsConfig, args) => { + return args.parallels || bsConfig['run_settings']['parallels']; +} + exports.setParallels = (bsConfig, args, numOfSpecs) => { if (!this.isUndefined(args.parallels)) { bsConfig["run_settings"]["parallels"] = args.parallels; From 5cd5e8f8e030166a946a19175151236e825d6eb4 Mon Sep 17 00:00:00 2001 From: Roshan Nikam Date: Wed, 17 Nov 2021 15:48:18 +0530 Subject: [PATCH 2/9] added required keys to buildreport --- bin/commands/runs.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bin/commands/runs.js b/bin/commands/runs.js index 6de092b6..5a42b72e 100644 --- a/bin/commands/runs.js +++ b/bin/commands/runs.js @@ -136,8 +136,7 @@ module.exports = function run(args) { let message = `${data.message}! ${Constants.userMessages.BUILD_CREATED} with build id: ${data.build_id}`; let dashboardLink = `${Constants.userMessages.VISIT_DASHBOARD} ${data.dashboard_url}`; let buildReportData = { - 'user_id': data.user_details.id, - 'group_id': data.user_details.group_id, + 'user_id': data.user_id, 'parallels_specified': userSpecifiedParallels, 'parallels_allotted': bsConfig.run_settings.parallels }; From f438c85f9fbd777374d2ee65195bf129440fd646 Mon Sep 17 00:00:00 2001 From: Roshan Nikam Date: Wed, 17 Nov 2021 18:17:37 +0530 Subject: [PATCH 3/9] deep copied the bsconfig --- bin/commands/runs.js | 3 +-- bin/helpers/usageReporting.js | 10 ++++------ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/bin/commands/runs.js b/bin/commands/runs.js index 5a42b72e..325c06a0 100644 --- a/bin/commands/runs.js +++ b/bin/commands/runs.js @@ -137,8 +137,7 @@ module.exports = function run(args) { let dashboardLink = `${Constants.userMessages.VISIT_DASHBOARD} ${data.dashboard_url}`; let buildReportData = { 'user_id': data.user_id, - 'parallels_specified': userSpecifiedParallels, - 'parallels_allotted': bsConfig.run_settings.parallels + 'parallels': userSpecifiedParallels }; utils.exportResults(data.build_id, `${config.dashboardUrl}${data.build_id}`); if ((utils.isUndefined(bsConfig.run_settings.parallels) && utils.isUndefined(args.parallels)) || (!utils.isUndefined(bsConfig.run_settings.parallels) && bsConfig.run_settings.parallels == Constants.cliMessages.RUN.DEFAULT_PARALLEL_MESSAGE)) { diff --git a/bin/helpers/usageReporting.js b/bin/helpers/usageReporting.js index a30372f8..abd05d2f 100644 --- a/bin/helpers/usageReporting.js +++ b/bin/helpers/usageReporting.js @@ -173,7 +173,7 @@ function isUsageReportingEnabled() { function send(args) { if (isUsageReportingEnabled() === "true") return; - let bsConfig = args.bstack_config; + let bsConfig = JSON.parse(JSON.stringify(args.bstack_config)); let cli_details = cli_version_and_path(bsConfig); let data = utils.isUndefined(args.data) ? {} : args.data; @@ -182,8 +182,8 @@ function send(args) { } bsConfig['auth']['username'] = "[REDACTED]" - bsConfig['auth']['access_key'] = "[REDACTED]" - + bsConfig['auth']['access_key'] = "[REDACTED]" + delete args.bstack_config; const payload = { @@ -191,9 +191,7 @@ function send(args) { data: { build_id: data.build_id, user_id: data.user_id, - group_id: data.group_id, - parallels_specified: data.parallels_specified, - parallels_allotted: data.parallels_allotted, + parallels: data.parallels, bstack_json: bsConfig, run_settings: bsConfig.run_settings, os: _os(), From 716bb1548205999cdc1f718d13c43fa240a1462c Mon Sep 17 00:00:00 2001 From: Roshan Nikam Date: Thu, 18 Nov 2021 17:46:57 +0530 Subject: [PATCH 4/9] added specs for the changes --- test/unit/bin/commands/runs.js | 17 +++++++++++++++-- test/unit/bin/helpers/utils.js | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/test/unit/bin/commands/runs.js b/test/unit/bin/commands/runs.js index 069ebd24..eef04d62 100644 --- a/test/unit/bin/commands/runs.js +++ b/test/unit/bin/commands/runs.js @@ -206,6 +206,7 @@ describe("runs", () => { beforeEach(() => { sandbox = sinon.createSandbox(); + getParallelsStub = sandbox.stub(); setParallelsStub = sandbox.stub(); warnSpecLimitStub = sandbox.stub(); setUsernameStub = sandbox.stub(); @@ -257,6 +258,7 @@ describe("runs", () => { '../helpers/utils': { validateBstackJson: validateBstackJsonStub, sendUsageReport: sendUsageReportStub, + getParallels: getParallelsStub, setParallels: setParallelsStub, warnSpecLimit: warnSpecLimitStub, setUsername: setUsernameStub, @@ -322,6 +324,7 @@ describe("runs", () => { sinon.assert.calledOnce(setLocalConfigFileStub); sinon.assert.calledOnce(setCypressConfigFilenameStub); sinon.assert.calledOnce(getNumberOfSpecFilesStub); + sinon.assert.calledOnce(getParallelsStub); sinon.assert.calledOnce(setParallelsStub); sinon.assert.calledOnce(warnSpecLimitStub); sinon.assert.calledOnce(setLocalStub); @@ -356,6 +359,7 @@ describe("runs", () => { beforeEach(() => { sandbox = sinon.createSandbox(); validateBstackJsonStub = sandbox.stub(); + getParallelsStub = sandbox.stub(); setParallelsStub = sandbox.stub(); warnSpecLimitStub = sandbox.stub(); setUsernameStub = sandbox.stub(); @@ -407,6 +411,7 @@ describe("runs", () => { '../helpers/utils': { validateBstackJson: validateBstackJsonStub, sendUsageReport: sendUsageReportStub, + getParallels: getParallelsStub, setParallels: setParallelsStub, warnSpecLimit: warnSpecLimitStub, setUsername: setUsernameStub, @@ -472,6 +477,7 @@ describe("runs", () => { sinon.assert.calledOnce(setLocalModeStub); sinon.assert.calledOnce(setLocalConfigFileStub); sinon.assert.calledOnce(getNumberOfSpecFilesStub); + sinon.assert.calledOnce(getParallelsStub); sinon.assert.calledOnce(setParallelsStub); sinon.assert.calledOnce(warnSpecLimitStub); sinon.assert.calledOnce(setLocalStub); @@ -509,6 +515,7 @@ describe("runs", () => { beforeEach(() => { sandbox = sinon.createSandbox(); validateBstackJsonStub = sandbox.stub(); + getParallelsStub = sandbox.stub(); setParallelsStub = sandbox.stub(); warnSpecLimitStub = sandbox.stub(); setUsernameStub = sandbox.stub(); @@ -562,6 +569,7 @@ describe("runs", () => { '../helpers/utils': { validateBstackJson: validateBstackJsonStub, sendUsageReport: sendUsageReportStub, + getParallels: getParallelsStub, setParallels: setParallelsStub, warnSpecLimit: warnSpecLimitStub, setUsername: setUsernameStub, @@ -638,6 +646,7 @@ describe("runs", () => { sinon.assert.calledOnce(validateBstackJsonStub); sinon.assert.calledOnce(capabilityValidatorStub); sinon.assert.calledOnce(getNumberOfSpecFilesStub); + sinon.assert.calledOnce(getParallelsStub); sinon.assert.calledOnce(setParallelsStub); sinon.assert.calledOnce(warnSpecLimitStub); sinon.assert.calledOnce(setLocalStub); @@ -675,6 +684,7 @@ describe("runs", () => { beforeEach(() => { sandbox = sinon.createSandbox(); validateBstackJsonStub = sandbox.stub(); + getParallelsStub = sandbox.stub(); setParallelsStub = sandbox.stub(); warnSpecLimitStub = sandbox.stub() setUsernameStub = sandbox.stub(); @@ -736,7 +746,7 @@ describe("runs", () => { let errorCode = null; let message = `Success! ${Constants.userMessages.BUILD_CREATED} with build id: random_build_id`; let dashboardLink = `${Constants.userMessages.VISIT_DASHBOARD} ${dashboardUrl}`; - let data = {time_components: {}, unique_id: 'random_hash', package_error: 'test', checkmd5_error: 'test', build_id: 'random_build_id'} + let data = { user_id: 1234, parallels: 10, time_components: {}, unique_id: 'random_hash', package_error: 'test', checkmd5_error: 'test', build_id: 'random_build_id'} const runs = proxyquire('../../../../bin/commands/runs', { '../helpers/utils': { @@ -750,6 +760,7 @@ describe("runs", () => { setTestEnvs: setTestEnvsStub, setSystemEnvs: setSystemEnvsStub, setUsageReportingFlag: setUsageReportingFlagStub, + getParallels: getParallelsStub, setParallels: setParallelsStub, warnSpecLimit: warnSpecLimitStub, getConfigPath: getConfigPathStub, @@ -821,7 +832,8 @@ describe("runs", () => { stopLocalBinaryStub.returns(Promise.resolve("nothing")); nonEmptyArrayStub.returns(false); checkErrorStub.returns('test'); - createBuildStub.returns(Promise.resolve({ message: 'Success', build_id: 'random_build_id', dashboard_url: dashboardUrl })); + getParallelsStub.returns(10); + createBuildStub.returns(Promise.resolve({ message: 'Success', build_id: 'random_build_id', dashboard_url: dashboardUrl, user_id: 1234 })); return runs(args) .then(function (_bsConfig) { @@ -834,6 +846,7 @@ describe("runs", () => { sinon.assert.calledOnce(setLocalConfigFileStub); sinon.assert.calledOnce(capabilityValidatorStub); sinon.assert.calledOnce(getNumberOfSpecFilesStub); + sinon.assert.calledOnce(getParallelsStub); sinon.assert.calledOnce(setParallelsStub); sinon.assert.calledOnce(warnSpecLimitStub); sinon.assert.calledOnce(setLocalStub); diff --git a/test/unit/bin/helpers/utils.js b/test/unit/bin/helpers/utils.js index 04538724..62591ecd 100644 --- a/test/unit/bin/helpers/utils.js +++ b/test/unit/bin/helpers/utils.js @@ -239,6 +239,38 @@ describe('utils', () => { }); }); + describe('getparallels', () =>{ + it('should return the parallels specified by the user as arguments', ()=>{ + let bsConfig = { + run_settings: { + parallels: 100, + }, + }; + let args = { + parallels: 200 + }; + expect(utils.getParallels(bsConfig, args)).to.be.eq(200); + }); + + it('should return the parallels specified by the user in bsconfig if not passed as arguments', ()=>{ + let bsConfig = { + run_settings: { + parallels: 100, + }, + }; + let args = {}; + expect(utils.getParallels(bsConfig, args)).to.be.eq(100); + }); + + it('should return the undefined if no parallels specified in bsconfig and arguments', ()=>{ + let bsConfig = { + run_settings: {}, + }; + let args = {}; + expect(utils.getParallels(bsConfig, args)).to.be.eq(undefined); + }); + }); + describe('checkError', () => { it('should return error if exists', () => { expect(utils.checkError({error: "test error"})).to.be.eq("test error"); From 3b31b098c206f27de0a4e18e6f1604d708600f13 Mon Sep 17 00:00:00 2001 From: Roshan Nikam Date: Fri, 19 Nov 2021 11:14:39 +0530 Subject: [PATCH 5/9] added the constant for redacted string --- bin/helpers/constants.js | 5 ++++- bin/helpers/usageReporting.js | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/bin/helpers/constants.js b/bin/helpers/constants.js index 8d19ae84..8924bf23 100644 --- a/bin/helpers/constants.js +++ b/bin/helpers/constants.js @@ -211,6 +211,8 @@ const LATEST_VERSION_SYNTAX_REGEX = /\d*.latest(.\d*)?/gm const ERROR_EXIT_CODE = 1; +const REDACTED = "[REDACTED]"; + module.exports = Object.freeze({ syncCLI, userMessages, @@ -228,5 +230,6 @@ module.exports = Object.freeze({ METADATA_CHAR_BUFFER_PER_SPEC, usageReportingConstants, LATEST_VERSION_SYNTAX_REGEX, - ERROR_EXIT_CODE + ERROR_EXIT_CODE, + REDACTED }); diff --git a/bin/helpers/usageReporting.js b/bin/helpers/usageReporting.js index abd05d2f..25383e8f 100644 --- a/bin/helpers/usageReporting.js +++ b/bin/helpers/usageReporting.js @@ -8,6 +8,8 @@ const cp = require("child_process"), const config = require('./config'), fileLogger = require('./logger').fileLogger, utils = require('./utils'); + +const { REDACTED } = require("./constants"); function get_version(package_name) { try { @@ -181,8 +183,8 @@ function send(args) { data.cypress_version = bsConfig.run_settings.cypress_version } - bsConfig['auth']['username'] = "[REDACTED]" - bsConfig['auth']['access_key'] = "[REDACTED]" + bsConfig['auth']['username'] = REDACTED + bsConfig['auth']['access_key'] = REDACTED delete args.bstack_config; From 07fc992d7a77b29c4fc19e7179878498e9e02255 Mon Sep 17 00:00:00 2001 From: Roshan Nikam Date: Fri, 19 Nov 2021 23:46:16 +0530 Subject: [PATCH 6/9] handled the case of invalid json and invalid paths --- bin/commands/runs.js | 5 +++-- bin/helpers/constants.js | 7 ++++++- bin/helpers/usageReporting.js | 17 ++++++++++------- bin/helpers/utils.js | 4 ++++ 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/bin/commands/runs.js b/bin/commands/runs.js index 325c06a0..ce2542ef 100644 --- a/bin/commands/runs.js +++ b/bin/commands/runs.js @@ -16,7 +16,7 @@ const archiver = require("../helpers/archiver"), downloadBuildArtifacts = require('../helpers/buildArtifacts').downloadBuildArtifacts, updateNotifier = require('update-notifier'), pkg = require('../../package.json'); - + module.exports = function run(args) { let bsConfigPath = utils.getConfigPath(args.cf); //Delete build_results.txt from log folder if already present. @@ -284,7 +284,8 @@ module.exports = function run(args) { }).catch(function (err) { logger.error(err); utils.setUsageReportingFlag(null, args.disableUsageReporting); - utils.sendUsageReport(null, args, err.message, Constants.messageTypes.ERROR, utils.getErrorCodeFromErr(err)); + let bsJsonData = utils.readBsConfigJSON(bsConfigPath); + utils.sendUsageReport(bsJsonData, args, err.message, Constants.messageTypes.ERROR, utils.getErrorCodeFromErr(err)); process.exitCode = Constants.ERROR_EXIT_CODE; }).finally(function(){ updateNotifier({ diff --git a/bin/helpers/constants.js b/bin/helpers/constants.js index 8924bf23..493c25c2 100644 --- a/bin/helpers/constants.js +++ b/bin/helpers/constants.js @@ -209,10 +209,14 @@ const usageReportingConstants = { const LATEST_VERSION_SYNTAX_REGEX = /\d*.latest(.\d*)?/gm +const AUTH_REGEX = /"auth" *: *{[\s\S]*?}/g + const ERROR_EXIT_CODE = 1; const REDACTED = "[REDACTED]"; +const REDACTED_AUTH =`auth: { "username": ${REDACTED}, "access_key": ${REDACTED} }`; + module.exports = Object.freeze({ syncCLI, userMessages, @@ -231,5 +235,6 @@ module.exports = Object.freeze({ usageReportingConstants, LATEST_VERSION_SYNTAX_REGEX, ERROR_EXIT_CODE, - REDACTED + AUTH_REGEX, + REDACTED_AUTH }); diff --git a/bin/helpers/usageReporting.js b/bin/helpers/usageReporting.js index 25383e8f..ccf9dd13 100644 --- a/bin/helpers/usageReporting.js +++ b/bin/helpers/usageReporting.js @@ -9,7 +9,7 @@ const config = require('./config'), fileLogger = require('./logger').fileLogger, utils = require('./utils'); -const { REDACTED } = require("./constants"); +const { AUTH_REGEX, REDACTED_AUTH } = require("./constants"); function get_version(package_name) { try { @@ -176,16 +176,19 @@ function send(args) { if (isUsageReportingEnabled() === "true") return; let bsConfig = JSON.parse(JSON.stringify(args.bstack_config)); + let runSettings = ""; + let sanitizedbsConfig = ""; let cli_details = cli_version_and_path(bsConfig); let data = utils.isUndefined(args.data) ? {} : args.data; if (bsConfig && bsConfig.run_settings) { - data.cypress_version = bsConfig.run_settings.cypress_version + runSettings = bsConfig.run_settings; + data.cypress_version = bsConfig.run_settings.cypress_version; } - bsConfig['auth']['username'] = REDACTED - bsConfig['auth']['access_key'] = REDACTED - + sanitizedbsConfig = `${(typeof bsConfig === 'string') ? bsConfig : + JSON.stringify(bsConfig)}`.replace(AUTH_REGEX, REDACTED_AUTH); + delete args.bstack_config; const payload = { @@ -194,8 +197,8 @@ function send(args) { build_id: data.build_id, user_id: data.user_id, parallels: data.parallels, - bstack_json: bsConfig, - run_settings: bsConfig.run_settings, + bstack_json: sanitizedbsConfig, + run_settings: runSettings, os: _os(), os_version: os_version(), bstack_json_found_in_pwd: bstack_json_found_in_pwd(), diff --git a/bin/helpers/utils.js b/bin/helpers/utils.js index 26b7ffbc..d49a2182 100644 --- a/bin/helpers/utils.js +++ b/bin/helpers/utils.js @@ -912,6 +912,10 @@ exports.setOtherConfigs = (bsConfig, args) => { } } +exports.readBsConfigJSON = (bsConfigPath) => { + return fs.readFileSync(bsConfigPath, 'utf-8'); +} + exports.getCypressJSON = (bsConfig) => { let cypressJSON = undefined; if (bsConfig.run_settings.cypress_config_file && bsConfig.run_settings.cypress_config_filename !== 'false') { From 29b0bdd2782b48bba3cc8175e3e61b3bb3d602be Mon Sep 17 00:00:00 2001 From: Roshan Nikam Date: Mon, 22 Nov 2021 13:54:51 +0530 Subject: [PATCH 7/9] handled check for browserstack json not present --- 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 d49a2182..051dad26 100644 --- a/bin/helpers/utils.js +++ b/bin/helpers/utils.js @@ -913,7 +913,7 @@ exports.setOtherConfigs = (bsConfig, args) => { } exports.readBsConfigJSON = (bsConfigPath) => { - return fs.readFileSync(bsConfigPath, 'utf-8'); + return fs.existsSync(bsConfigPath) ? fs.readFileSync(bsConfigPath, 'utf-8') : null; } exports.getCypressJSON = (bsConfig) => { From 77270862ac9ac64a641a9e8c902fe10397eee8f4 Mon Sep 17 00:00:00 2001 From: Roshan Nikam Date: Mon, 22 Nov 2021 16:00:42 +0530 Subject: [PATCH 8/9] updated the buildid to build_hashed_id --- bin/commands/runs.js | 4 ++-- bin/helpers/usageReporting.js | 2 +- bin/helpers/utils.js | 7 ++++++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/bin/commands/runs.js b/bin/commands/runs.js index ce2542ef..ba911f95 100644 --- a/bin/commands/runs.js +++ b/bin/commands/runs.js @@ -16,7 +16,6 @@ const archiver = require("../helpers/archiver"), downloadBuildArtifacts = require('../helpers/buildArtifacts').downloadBuildArtifacts, updateNotifier = require('update-notifier'), pkg = require('../../package.json'); - module.exports = function run(args) { let bsConfigPath = utils.getConfigPath(args.cf); //Delete build_results.txt from log folder if already present. @@ -135,7 +134,8 @@ module.exports = function run(args) { utils.setProcessHooks(data.build_id, bsConfig, bs_local, args); let message = `${data.message}! ${Constants.userMessages.BUILD_CREATED} with build id: ${data.build_id}`; let dashboardLink = `${Constants.userMessages.VISIT_DASHBOARD} ${data.dashboard_url}`; - let buildReportData = { + let buildReportData = { + 'build_id': data.build_id, 'user_id': data.user_id, 'parallels': userSpecifiedParallels }; diff --git a/bin/helpers/usageReporting.js b/bin/helpers/usageReporting.js index ccf9dd13..c949a274 100644 --- a/bin/helpers/usageReporting.js +++ b/bin/helpers/usageReporting.js @@ -194,7 +194,7 @@ function send(args) { const payload = { event_type: "cypress_cli_stats", data: { - build_id: data.build_id, + build_hashed_id: data.build_id, user_id: data.user_id, parallels: data.parallels, bstack_json: sanitizedbsConfig, diff --git a/bin/helpers/utils.js b/bin/helpers/utils.js index 051dad26..69700a22 100644 --- a/bin/helpers/utils.js +++ b/bin/helpers/utils.js @@ -913,7 +913,12 @@ exports.setOtherConfigs = (bsConfig, args) => { } exports.readBsConfigJSON = (bsConfigPath) => { - return fs.existsSync(bsConfigPath) ? fs.readFileSync(bsConfigPath, 'utf-8') : null; + try { + fs.accessSync(bsConfigPath, fs.constants.R_OK); + return fs.readFileSync(bsConfigPath, 'utf-8'); + } catch (err) { + return null; + } } exports.getCypressJSON = (bsConfig) => { From 795594859204776f52dd1ff8cf75f7dede11e036 Mon Sep 17 00:00:00 2001 From: Roshan Nikam Date: Sat, 4 Dec 2021 10:26:34 +0530 Subject: [PATCH 9/9] corrected failing spec after changes --- test/unit/bin/commands/runs.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/unit/bin/commands/runs.js b/test/unit/bin/commands/runs.js index eef04d62..f7db5c05 100644 --- a/test/unit/bin/commands/runs.js +++ b/test/unit/bin/commands/runs.js @@ -28,6 +28,7 @@ describe("runs", () => { }); getErrorCodeFromErrStub = sandbox.stub().returns("random-error-code"); deleteResultsStub = sandbox.stub(); + readBsConfigJSONStub = sandbox.stub().returns(null); }); afterEach(() => { @@ -47,7 +48,8 @@ describe("runs", () => { sendUsageReport: sendUsageReportStub, setUsageReportingFlag: setUsageReportingFlagStub, getConfigPath: getConfigPathStub, - deleteResults: deleteResultsStub + deleteResults: deleteResultsStub, + readBsConfigJSON: readBsConfigJSONStub }, });