diff --git a/bin/commands/runs.js b/bin/commands/runs.js index 863fd6ad..dc91679e 100644 --- a/bin/commands/runs.js +++ b/bin/commands/runs.js @@ -184,6 +184,9 @@ module.exports = function run(args, rawArgs) { // set record feature caps utils.setRecordCaps(bsConfig, args, cypressConfigFile); + // set the interactive debugging capability + utils.setInteractiveCapability(bsConfig); + // warn if specFiles cross our limit utils.warnSpecLimit(bsConfig, args, specFiles, rawArgs, buildReportData); markBlockEnd('preArchiveSteps'); diff --git a/bin/helpers/capabilityHelper.js b/bin/helpers/capabilityHelper.js index 5d9adfe4..6ea88ec9 100644 --- a/bin/helpers/capabilityHelper.js +++ b/bin/helpers/capabilityHelper.js @@ -242,6 +242,23 @@ const validate = (bsConfig, args) => { addCypressZipStartLocation(bsConfig.run_settings); } + // check if Interactive Capabilities Caps passed is correct or not + if(!Utils.isUndefined(bsConfig.run_settings.interactive_debugging) && !Utils.isUndefined(bsConfig.run_settings.interactiveDebugging)) { + if(Utils.isConflictingBooleanValues(bsConfig.run_settings.interactive_debugging, bsConfig.run_settings.interactiveDebugging)) { + reject(Constants.userMessages.CYPRESS_INTERACTIVE_SESSION_CONFLICT_VALUES); + } else if(Utils.isNonBooleanValue(bsConfig.run_settings.interactive_debugging) && Utils.isNonBooleanValue(bsConfig.run_settings.interactiveDebugging)) { + logger.warn('You have passed an invalid value to the interactive_debugging capability. Proceeding with the default value (True).'); + } + } else if(!Utils.isUndefined(bsConfig.run_settings.interactive_debugging)) { + if(Utils.isNonBooleanValue(bsConfig.run_settings.interactive_debugging)) { + logger.warn('You have passed an invalid value to the interactive_debugging capability. Proceeding with the default value (True).'); + } + } else if(!Utils.isUndefined(bsConfig.run_settings.interactiveDebugging)) { + if(Utils.isNonBooleanValue(bsConfig.run_settings.interactiveDebugging)) { + logger.warn('You have passed an invalid value to the interactive_debugging capability. Proceeding with the default value (True).'); + } + } + // check if two config files are present at the same location let cypressFileDirectory = path.dirname(path.resolve(bsConfig.run_settings.cypressConfigFilePath)); let listOfFiles = fs.readdirSync(cypressFileDirectory); diff --git a/bin/helpers/constants.js b/bin/helpers/constants.js index 18618e8a..cc65ff48 100644 --- a/bin/helpers/constants.js +++ b/bin/helpers/constants.js @@ -117,7 +117,9 @@ const userMessages = { NO_CONNECTION_WHILE_UPDATING_UPLOAD_PROGRESS_BAR: "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" + "The requested port number is ignored. The default BrowserStack port will be used for this execution", + CYPRESS_INTERACTIVE_SESSION_CONFLICT_VALUES: + "Conflicting values (True & False) were found for the interactive_debugging capability. Please resolve this issue to proceed further." }; const validationMessages = { diff --git a/bin/helpers/utils.js b/bin/helpers/utils.js index c2ac9434..25256923 100644 --- a/bin/helpers/utils.js +++ b/bin/helpers/utils.js @@ -1000,6 +1000,24 @@ exports.setHeaded = (bsConfig, args) => { logger.debug(`headless mode set to ${bsConfig.run_settings.headless}`); }; +exports.isConflictingBooleanValues = (value1, value2) => { + return (value1.toString() === "true" && value2.toString() === "false") || (value1.toString() === "false" && value2.toString() === "true") +}; + +exports.isNonBooleanValue = (value) => { + return value.toString() !== "true" && value.toString() !== "false"; +}; + +exports.setInteractiveCapability = (bsConfig) => { + let interactiveDebuggingTemp = "true"; + let interactive_debugging = bsConfig.run_settings.interactive_debugging; + let interactiveDebugging = bsConfig.run_settings.interactiveDebugging; + if(this.isNotUndefined(interactive_debugging) && !this.isNonBooleanValue(interactive_debugging)) interactiveDebuggingTemp = interactive_debugging; + else if(this.isNotUndefined(interactiveDebugging) && !this.isNonBooleanValue(interactiveDebugging)) interactiveDebuggingTemp = interactiveDebugging; + logger.debug(`Setting interactiveDebugging flag to ${interactiveDebuggingTemp}`); + bsConfig.run_settings.interactiveDebugging = interactiveDebuggingTemp; +} + exports.setNoWrap = (_bsConfig, args) => { if (args.noWrap === true || this.searchForOption('--no-wrap')) { process.env.SYNC_NO_WRAP = true; diff --git a/test/unit/bin/helpers/capabilityHelper.js b/test/unit/bin/helpers/capabilityHelper.js index b8f7a8b7..68e47ae1 100644 --- a/test/unit/bin/helpers/capabilityHelper.js +++ b/test/unit/bin/helpers/capabilityHelper.js @@ -1229,6 +1229,95 @@ describe("capabilityHelper.js", () => { }); }); + describe("validate interactive caps debugging", () => { + let loggerWarningSpy; + beforeEach(() => { + loggerWarningSpy = sinon.stub(logger, 'warn').returns('You have passed an invalid value to the interactive_debugging capability. Proceeding with the default value (True).'); + }); + + afterEach(function() { + loggerWarningSpy.restore(); + }); + it("show the warning if interactive_debugging passed is a non boolean value", () => { + let bsConfig = { + auth: {}, + browsers: [ + { + browser: "chrome", + os: "Windows 10", + versions: ["78", "77"], + }, + ], + run_settings: { + cypress_proj_dir: "random path", + cypressConfigFilePath: "random path", + cypressProjectDir: "random path", + cypress_config_filename: "false", + interactive_debugging: "abc" + }, + connection_settings: {} + } + return capabilityHelper + .validate(bsConfig, {}) + .then(function (data) { + sinon.assert.calledWith(loggerWarningSpy, 'You have passed an invalid value to the interactive_debugging capability. Proceeding with the default value (True).'); + }); + }); + + it("show the warning if interactiveDebugging passed is a non boolean value", () => { + let bsConfig = { + auth: {}, + browsers: [ + { + browser: "chrome", + os: "Windows 10", + versions: ["78", "77"], + }, + ], + run_settings: { + cypress_proj_dir: "random path", + cypressConfigFilePath: "random path", + cypressProjectDir: "random path", + cypress_config_filename: "false", + interactiveDebugging: "abc" + }, + connection_settings: {} + } + return capabilityHelper + .validate(bsConfig, {}) + .then(function (data) { + sinon.assert.calledWith(loggerWarningSpy, 'You have passed an invalid value to the interactive_debugging capability. Proceeding with the default value (True).'); + }); + }); + + it("show the warning if both the interactive caps are non boolean", () => { + let bsConfig = { + auth: {}, + browsers: [ + { + browser: "chrome", + os: "Windows 10", + versions: ["78", "77"], + }, + ], + run_settings: { + cypress_proj_dir: "random path", + cypressConfigFilePath: "random path", + cypressProjectDir: "random path", + cypress_config_filename: "false", + interactiveDebugging: "def", + interactive_debugging: "abc" + }, + connection_settings: {} + } + return capabilityHelper + .validate(bsConfig, {}) + .then(function (data) { + sinon.assert.calledWith(loggerWarningSpy, 'You have passed an invalid value to the interactive_debugging capability. Proceeding with the default value (True).'); + }); + }); + }); + describe("validate home directory", () => { beforeEach(() => { bsConfig = { diff --git a/test/unit/bin/helpers/utils.js b/test/unit/bin/helpers/utils.js index 719a286a..f2751d76 100644 --- a/test/unit/bin/helpers/utils.js +++ b/test/unit/bin/helpers/utils.js @@ -3938,6 +3938,127 @@ describe('utils', () => { }); }); + describe('#isNonBooleanValue' , () => { + it('return true if value passed in empty string', () => { + expect(utils.isNonBooleanValue('')).to.be.eql(true); + }); + + it('return true if value passed is abc(non boolean)', () => { + expect(utils.isNonBooleanValue("abc")).to.be.eql(true); + }); + + it('return false if value passed is false(boolean)', () => { + expect(utils.isNonBooleanValue("false")).to.be.eql(false); + }); + + it('return false if value passed is true(boolean)', () => { + expect(utils.isNonBooleanValue(true)).to.be.eql(false); + }); + }); + + describe('#isConflictingBooleanValues' , () => { + it('return false if value passed is true and true', () => { + expect(utils.isConflictingBooleanValues(true, true)).to.be.eql(false); + }); + + it('return false if value passed is false and "false"', () => { + expect(utils.isConflictingBooleanValues(false, "false")).to.be.eql(false); + }); + + it('return true if value passed is "true" and "false"', () => { + expect(utils.isConflictingBooleanValues("true", "false")).to.be.eql(true); + }); + + it('return true if value passed is true and "false"', () => { + expect(utils.isConflictingBooleanValues(true, "false")).to.be.eql(true); + }); + + it('return false if value passed is false and "true"', () => { + expect(utils.isConflictingBooleanValues(false, "true")).to.be.eql(true); + }); + + it('return false if value passed is false and "false"', () => { + expect(utils.isConflictingBooleanValues(false, "false")).to.be.eql(false); + }); + }); + + describe('#setInteractiveCapability' , () => { + it('should set true if interactive caps is not passed', () => { + let bsConfig = { + run_settings: {} + } + let expectedResult = { + run_settings: { + interactiveDebugging: "true" + } + } + utils.setInteractiveCapability(bsConfig); + expect(bsConfig).to.be.eql(expectedResult); + }); + + it('should set true if interactiveDebugging caps passed is true', () => { + let bsConfig = { + run_settings: { + interactiveDebugging: true + } + } + let expectedResult = { + run_settings: { + interactiveDebugging: true + } + } + utils.setInteractiveCapability(bsConfig); + expect(bsConfig).to.be.eql(expectedResult); + }); + + it('should set true if interactive_debugging caps passed is true', () => { + let bsConfig = { + run_settings: { + interactive_debugging: true + } + } + let expectedResult = { + run_settings: { + interactive_debugging: true, + interactiveDebugging: true + } + } + utils.setInteractiveCapability(bsConfig); + expect(bsConfig).to.be.eql(expectedResult); + }); + + it('should set false if interactive_debugging caps passed is false', () => { + let bsConfig = { + run_settings: { + interactive_debugging: false + } + } + let expectedResult = { + run_settings: { + interactive_debugging: false, + interactiveDebugging: false + } + } + utils.setInteractiveCapability(bsConfig); + expect(bsConfig).to.be.eql(expectedResult); + }); + + it('should set false if interactiveDebugging caps passed is false', () => { + let bsConfig = { + run_settings: { + interactiveDebugging: false + } + } + let expectedResult = { + run_settings: { + interactiveDebugging: false + } + } + utils.setInteractiveCapability(bsConfig); + expect(bsConfig).to.be.eql(expectedResult); + }); + }); + describe('#setCypressNpmDependency', () => { it('should set cypress as latest for cypress 10 test suite if cypress_version missing', () => {