From f6e89305182229643bc809f2bdf7bf47b05ee464 Mon Sep 17 00:00:00 2001 From: roshan04 Date: Fri, 24 Feb 2023 14:23:57 +0530 Subject: [PATCH 1/5] support cyp network logs --- bin/commands/runs.js | 3 +++ bin/helpers/utils.js | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/bin/commands/runs.js b/bin/commands/runs.js index 18d64936..320a9d6b 100644 --- a/bin/commands/runs.js +++ b/bin/commands/runs.js @@ -82,6 +82,9 @@ module.exports = function run(args, rawArgs) { //accept the local from env variable if provided utils.setLocal(bsConfig, args); + //set network logs + utils.setNetworkLogs(bsConfig); + // set Local Mode (on-demand/ always-on) utils.setLocalMode(bsConfig, args); diff --git a/bin/helpers/utils.js b/bin/helpers/utils.js index 6616816f..940551c2 100644 --- a/bin/helpers/utils.js +++ b/bin/helpers/utils.js @@ -1025,6 +1025,14 @@ exports.getNetworkErrorMessage = (dashboard_url) => { return chalk.red(message) } +exports.setNetworkLogs = (bsConfig) => { + if(bsConfig.run_settings.networkLogs == 'true' || bsConfig.run_settings.networkLogs == true) { + bsConfig.run_settings.networkLogs = 'true' + } else { + bsConfig.run_settings.networkLogs = 'false' + } +} + exports.versionChangedMessage = (preferredVersion, actualVersion, frameworkUpgradeMessage = '') => { let message = Constants.userMessages.CYPRESS_VERSION_CHANGED.replace("", preferredVersion); message = message.replace("", actualVersion); From 8e41ae4bc5be0c0c919eb353a8ff18ac9acb09e3 Mon Sep 17 00:00:00 2001 From: roshan04 Date: Wed, 8 Mar 2023 14:22:24 +0530 Subject: [PATCH 2/5] added rspec for utils --- test/unit/bin/helpers/utils.js | 46 ++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/test/unit/bin/helpers/utils.js b/test/unit/bin/helpers/utils.js index 4ee15936..7288c54d 100644 --- a/test/unit/bin/helpers/utils.js +++ b/test/unit/bin/helpers/utils.js @@ -3148,6 +3148,52 @@ describe('utils', () => { }); }); + describe('setNetworkLogs', () => { + it('should return true if networkLogs is passed as boolean true', () => { + let bsConfig = { + run_settings: { networkLogs: true } + }; + let expectResult = { + run_settings: { networkLogs: 'true' } + } + utils.setNetworkLogs(bsConfig); + expect(bsConfig).to.be.eql(expectResult); + }); + + it('should return true if networkLogs is passed as string true', () => { + let bsConfig = { + run_settings: { networkLogs: "true" } + }; + let expectResult = { + run_settings: { networkLogs: "true" } + } + utils.setNetworkLogs(bsConfig); + expect(bsConfig).to.be.eql(expectResult); + }); + + it('should return false if networkLogs is passed as any other non true value', () => { + let bsConfig = { + run_settings: { networkLogs: "abc" } + }; + let expectResult = { + run_settings: { networkLogs: "false" } + } + utils.setNetworkLogs(bsConfig); + expect(bsConfig).to.be.eql(expectResult); + }); + + it('should return false if networkLogs is not passed', () => { + let bsConfig = { + run_settings: { } + }; + let expectResult = { + run_settings: { networkLogs: "false" } + } + utils.setNetworkLogs(bsConfig); + expect(bsConfig).to.be.eql(expectResult); + }); + }); + describe('isSpecTimeoutArgPassed', () => { let searchForOptionStub; beforeEach(() => { From c33beab22191c5a219b5178447880b191b9171cc Mon Sep 17 00:00:00 2001 From: roshan04 Date: Wed, 8 Mar 2023 23:28:00 +0530 Subject: [PATCH 3/5] added logger --- bin/helpers/config.json | 11 +++++------ bin/helpers/utils.js | 1 + 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bin/helpers/config.json b/bin/helpers/config.json index 83596c99..37da37bd 100644 --- a/bin/helpers/config.json +++ b/bin/helpers/config.json @@ -1,7 +1,6 @@ { - "uploadUrl": "https://api-cloud.browserstack.com/automate-frameworks/cypress/upload", - "rails_host": "https://api.browserstack.com", - "dashboardUrl": "https://automate.browserstack.com/dashboard/v2/builds/", - "usageReportingUrl": "https://eds.browserstack.com:443/send_event_cy_internal", - "localTestingListUrl": "https://www.browserstack.com/local/v1/list" -} + "uploadUrl": "https://api-cloud-k8s-devcypress.bsstag.com/automate-frameworks/cypress/upload", + "rails_host": "https://apik8s-devcypress.bsstag.com", + "dashboardUrl": "https://automate-k8s-devcypress.bsstag.com/dashboard/v2/builds/", + "usageReportingUrl": "https://google.com" +} \ No newline at end of file diff --git a/bin/helpers/utils.js b/bin/helpers/utils.js index 67a2f3e3..3ab06fb1 100644 --- a/bin/helpers/utils.js +++ b/bin/helpers/utils.js @@ -1051,6 +1051,7 @@ exports.setNetworkLogs = (bsConfig) => { } else { bsConfig.run_settings.networkLogs = 'false' } + logger.debug(`Networks logs value: ${bsConfig.run_settings.networkLogs}`); } exports.versionChangedMessage = (preferredVersion, actualVersion, frameworkUpgradeMessage = '') => { From 3da355a2cb9832781ef1b3caca51032920e7605b Mon Sep 17 00:00:00 2001 From: roshan04 Date: Wed, 8 Mar 2023 23:33:52 +0530 Subject: [PATCH 4/5] added rspec for runs --- test/unit/bin/commands/runs.js | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/test/unit/bin/commands/runs.js b/test/unit/bin/commands/runs.js index 0f093a7f..b9213c4f 100644 --- a/test/unit/bin/commands/runs.js +++ b/test/unit/bin/commands/runs.js @@ -124,6 +124,7 @@ describe("runs", () => { setRecordCapsStub = sandbox.stub().returns(undefined); setNodeVersionStub = sandbox.stub(); setBuildTagsStub = sandbox.stub(); + setNetworkLogsStub = sandbox.stub(); }); afterEach(() => { @@ -170,7 +171,8 @@ describe("runs", () => { setRecordCaps: setRecordCapsStub, setDebugMode: setDebugModeStub, setNodeVersion: setNodeVersionStub, - setBuildTags: setBuildTagsStub + setBuildTags: setBuildTagsStub, + setNetworkLogs: setNetworkLogsStub }, '../helpers/capabilityHelper': { validate: capabilityValidatorStub @@ -221,6 +223,7 @@ describe("runs", () => { sinon.assert.calledOnce(setRecordCapsStub); sinon.assert.calledOnce(setNodeVersionStub); sinon.assert.calledOnce(setBuildTagsStub); + sinon.assert.calledOnce(setNetworkLogsStub); sinon.assert.calledOnceWithExactly( sendUsageReportStub, bsConfig, @@ -284,6 +287,7 @@ describe("runs", () => { setRecordCapsStub = sandbox.stub().returns(undefined); setNodeVersionStub = sandbox.stub(); setBuildTagsStub = sandbox.stub(); + setNetworkLogsStub = sandbox.stub(); }); afterEach(() => { @@ -333,7 +337,8 @@ describe("runs", () => { setRecordCaps: setRecordCapsStub, setDebugMode: setDebugModeStub, setNodeVersion: setNodeVersionStub, - setBuildTags: setBuildTagsStub + setBuildTags: setBuildTagsStub, + setNetworkLogs: setNetworkLogsStub }, '../helpers/capabilityHelper': { validate: capabilityValidatorStub, @@ -403,6 +408,7 @@ describe("runs", () => { sinon.assert.calledOnce(setRecordCapsStub); sinon.assert.calledOnce(setNodeVersionStub); sinon.assert.calledOnce(setBuildTagsStub); + sinon.assert.calledOnce(setNetworkLogsStub); sinon.assert.calledOnceWithExactly( sendUsageReportStub, bsConfig, @@ -468,6 +474,7 @@ describe("runs", () => { setRecordCapsStub = sandbox.stub().returns(undefined); setNodeVersionStub = sandbox.stub(); setBuildTagsStub = sandbox.stub(); + setNetworkLogsStub = sandbox.stub(); }); afterEach(() => { @@ -518,7 +525,8 @@ describe("runs", () => { setRecordCaps: setRecordCapsStub, setDebugMode: setDebugModeStub, setNodeVersion: setNodeVersionStub, - setBuildTags: setBuildTagsStub + setBuildTags: setBuildTagsStub, + setNetworkLogs: setNetworkLogsStub }, '../helpers/capabilityHelper': { validate: capabilityValidatorStub, @@ -590,6 +598,7 @@ describe("runs", () => { sinon.assert.calledOnce(setRecordCapsStub); sinon.assert.calledOnce(setNodeVersionStub); sinon.assert.calledOnce(setBuildTagsStub); + sinon.assert.calledOnce(setNetworkLogsStub); sinon.assert.calledOnceWithExactly( sendUsageReportStub, bsConfig, @@ -660,6 +669,7 @@ describe("runs", () => { setRecordCapsStub = sandbox.stub().returns(undefined); setNodeVersionStub = sandbox.stub(); setBuildTagsStub = sandbox.stub(); + setNetworkLogsStub = sandbox.stub(); }); afterEach(() => { @@ -711,7 +721,8 @@ describe("runs", () => { setRecordCaps: setRecordCapsStub, setDebugMode: setDebugModeStub, setNodeVersion: setNodeVersionStub, - setBuildTags: setBuildTagsStub + setBuildTags: setBuildTagsStub, + setNetworkLogs: setNetworkLogsStub }, '../helpers/capabilityHelper': { validate: capabilityValidatorStub, @@ -793,7 +804,7 @@ describe("runs", () => { sinon.assert.calledOnce(setRecordCapsStub); sinon.assert.calledOnce(setNodeVersionStub); sinon.assert.calledOnce(setBuildTagsStub); - + sinon.assert.calledOnce(setNetworkLogsStub); sinon.assert.calledOnceWithExactly( sendUsageReportStub, bsConfig, @@ -877,6 +888,7 @@ describe("runs", () => { setRecordCapsStub = sandbox.stub().returns(undefined); setNodeVersionStub = sandbox.stub(); setBuildTagsStub = sandbox.stub(); + setNetworkLogsStub = sandbox.stub(); }); afterEach(() => { @@ -936,7 +948,8 @@ describe("runs", () => { setRecordCaps: setRecordCapsStub, setDebugMode: setDebugModeStub, setNodeVersion: setNodeVersionStub, - setBuildTags: setBuildTagsStub + setBuildTags: setBuildTagsStub, + setNetworkLogs: setNetworkLogsStub }, '../helpers/capabilityHelper': { validate: capabilityValidatorStub, @@ -1035,6 +1048,7 @@ describe("runs", () => { sinon.assert.calledOnce(setRecordCapsStub); sinon.assert.calledOnce(setNodeVersionStub); sinon.assert.calledOnce(setBuildTagsStub); + sinon.assert.calledOnce(setNetworkLogsStub); sinon.assert.match( sendUsageReportStub.getCall(0).args, [ From 1059aba3b2b142f5bec2c97e7e7c22a470675576 Mon Sep 17 00:00:00 2001 From: roshan04 Date: Wed, 8 Mar 2023 23:35:33 +0530 Subject: [PATCH 5/5] removed unnecessary changes --- bin/helpers/config.json | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/bin/helpers/config.json b/bin/helpers/config.json index 37da37bd..83596c99 100644 --- a/bin/helpers/config.json +++ b/bin/helpers/config.json @@ -1,6 +1,7 @@ { - "uploadUrl": "https://api-cloud-k8s-devcypress.bsstag.com/automate-frameworks/cypress/upload", - "rails_host": "https://apik8s-devcypress.bsstag.com", - "dashboardUrl": "https://automate-k8s-devcypress.bsstag.com/dashboard/v2/builds/", - "usageReportingUrl": "https://google.com" -} \ No newline at end of file + "uploadUrl": "https://api-cloud.browserstack.com/automate-frameworks/cypress/upload", + "rails_host": "https://api.browserstack.com", + "dashboardUrl": "https://automate.browserstack.com/dashboard/v2/builds/", + "usageReportingUrl": "https://eds.browserstack.com:443/send_event_cy_internal", + "localTestingListUrl": "https://www.browserstack.com/local/v1/list" +}