From da2c8c174db2c6d80d21758d8e46f3f211490699 Mon Sep 17 00:00:00 2001 From: Prajwal Dhawarikar Date: Mon, 13 Mar 2023 17:46:28 +0530 Subject: [PATCH 1/3] Add warn message --- bin/helpers/capabilityHelper.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bin/helpers/capabilityHelper.js b/bin/helpers/capabilityHelper.js index 4e6cb2bd..eebe4317 100644 --- a/bin/helpers/capabilityHelper.js +++ b/bin/helpers/capabilityHelper.js @@ -286,6 +286,9 @@ const validate = (bsConfig, args) => { if (!Utils.isUndefined(bsConfig.run_settings.nodeVersion) && typeof(bsConfig.run_settings.nodeVersion) === 'string' && !bsConfig.run_settings.nodeVersion.match(/^(\d+\.)?(\d+\.)?(\*|\d+)$/)) logger.warn(Constants.validationMessages.NODE_VERSION_PARSING_ERROR); + if(!Utils.isUndefined(cypressConfigFile.port)) { + logger.warn(`The requested port number ${cypressConfigFile.port} is ignored. The default BrowserStack port will be used for this execution`); + } resolve(cypressConfigFile); }); } From 81028314560cd32fd316c2b690c1ec6025d9544d Mon Sep 17 00:00:00 2001 From: Prajwal Dhawarikar Date: Tue, 14 Mar 2023 14:04:20 +0530 Subject: [PATCH 2/3] Added UT --- test/unit/bin/helpers/capabilityHelper.js | 24 ++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/test/unit/bin/helpers/capabilityHelper.js b/test/unit/bin/helpers/capabilityHelper.js index 59beed8b..56ade625 100644 --- a/test/unit/bin/helpers/capabilityHelper.js +++ b/test/unit/bin/helpers/capabilityHelper.js @@ -962,11 +962,20 @@ describe("capabilityHelper.js", () => { run_settings: { cypress_proj_dir: "random path", cypressConfigFilePath: "random path", - cypressProjectDir: "random path" + cypressProjectDir: "random path", + cypress_config_filename: "cypress.json", + spec_timeout: 10, + cypressTestSuiteType: Constants.CYPRESS_V9_AND_OLDER_TYPE }, connection_settings: {local: false} }; + loggerWarningSpy = sinon.stub(logger, 'warn'); + }); + + afterEach(function() { + loggerWarningSpy.restore(); }); + it("validate cypress json is present", () => { //Stub for cypress json validation sinon.stub(fs, 'existsSync').returns(false); @@ -1046,6 +1055,19 @@ describe("capabilityHelper.js", () => { }); }); + it("should warn if port is passed in cypress config file", async () => { + //Stub for cypress json validation + sinon.stub(fs, 'existsSync').returns(true); + sinon.stub(fs, 'readFileSync').returns('{ "port": 23455}'); + + await capabilityHelper + .validate(bsConfig, { parallels: 2 }) + + sinon.assert.calledWith(loggerWarningSpy, `The requested port number 23455 is ignored. The default BrowserStack port will be used for this execution`); + fs.existsSync.restore(); + fs.readFileSync.restore(); + }); + context("cypress config file set to false", () => { beforeEach(function() { readFileSpy = sinon.stub(fs, 'readFileSync'); From 5e5cdd2c6cc1557ceb83d5528d3b3f130d04b7c4 Mon Sep 17 00:00:00 2001 From: Prajwal Dhawarikar Date: Tue, 14 Mar 2023 14:15:09 +0530 Subject: [PATCH 3/3] Add warn in constants --- bin/helpers/capabilityHelper.js | 2 +- bin/helpers/constants.js | 4 +++- test/unit/bin/helpers/capabilityHelper.js | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/bin/helpers/capabilityHelper.js b/bin/helpers/capabilityHelper.js index eebe4317..06c9ebee 100644 --- a/bin/helpers/capabilityHelper.js +++ b/bin/helpers/capabilityHelper.js @@ -287,7 +287,7 @@ const validate = (bsConfig, args) => { logger.warn(Constants.validationMessages.NODE_VERSION_PARSING_ERROR); if(!Utils.isUndefined(cypressConfigFile.port)) { - logger.warn(`The requested port number ${cypressConfigFile.port} is ignored. The default BrowserStack port will be used for this execution`); + logger.warn(Constants.userMessages.CYPRESS_PORT_WARNING.replace("", cypressConfigFile.port)); } resolve(cypressConfigFile); }); diff --git a/bin/helpers/constants.js b/bin/helpers/constants.js index cdb19579..eb032384 100644 --- a/bin/helpers/constants.js +++ b/bin/helpers/constants.js @@ -113,7 +113,9 @@ const userMessages = { SPEC_LIMIT_SUCCESS_MESSAGE: "Spec timeout specified as minutes. If any of your specs exceed the specified time limit, it would be forcibly killed by BrowserStack", NO_CONNECTION_WHILE_UPDATING_UPLOAD_PROGRESS_BAR: - "Unable to determine zip upload progress due to undefined/null connection request" + "Unable to determine zip upload progress due to undefined/null connection request", + CYPRESS_PORT_WARNING: + "The requested port number is ignored. The default BrowserStack port will be used for this execution" }; const validationMessages = { diff --git a/test/unit/bin/helpers/capabilityHelper.js b/test/unit/bin/helpers/capabilityHelper.js index 56ade625..b8f7a8b7 100644 --- a/test/unit/bin/helpers/capabilityHelper.js +++ b/test/unit/bin/helpers/capabilityHelper.js @@ -1063,7 +1063,7 @@ describe("capabilityHelper.js", () => { await capabilityHelper .validate(bsConfig, { parallels: 2 }) - sinon.assert.calledWith(loggerWarningSpy, `The requested port number 23455 is ignored. The default BrowserStack port will be used for this execution`); + sinon.assert.calledWith(loggerWarningSpy, Constants.userMessages.CYPRESS_PORT_WARNING.replace('', 23455)); fs.existsSync.restore(); fs.readFileSync.restore(); });