From eab6dc7444ce68408c31bc2ae23babc256effff7 Mon Sep 17 00:00:00 2001 From: Pranav Jain Date: Tue, 27 Jul 2021 15:55:28 +0530 Subject: [PATCH 1/2] add code to show appropriate info message when latest syntax is used --- bin/commands/runs.js | 9 +++++++-- bin/helpers/constants.js | 8 ++++++-- bin/helpers/utils.js | 6 ++++++ test/unit/bin/helpers/utils.js | 8 ++++++++ 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/bin/commands/runs.js b/bin/commands/runs.js index c1d64e66..3138855d 100644 --- a/bin/commands/runs.js +++ b/bin/commands/runs.js @@ -110,8 +110,13 @@ module.exports = function run(args) { } if (bsConfig.run_settings.cypress_version && bsConfig.run_settings.cypress_version !== data.cypress_version) { - let versionMessage = utils.versionChangedMessage(bsConfig.run_settings.cypress_version, data.cypress_version) - logger.warn(versionMessage); + if (bsConfig.run_settings.cypress_version.match(LATEST_VERSION_SYNTAX_REGEX)) { + let versionMessage = utils.latestSyntaxToActualVersionMessage(bsConfig.run_settings.cypress_version, data.cypress_version); + logger.info(versionMessage); + } else { + let versionMessage = utils.versionChangedMessage(bsConfig.run_settings.cypress_version, data.cypress_version); + logger.warn(versionMessage); + } } if (!args.disableNpmWarning && bsConfig.run_settings.npm_dependencies && Object.keys(bsConfig.run_settings.npm_dependencies).length <= 0) { diff --git a/bin/helpers/constants.js b/bin/helpers/constants.js index f4219805..68def9c1 100644 --- a/bin/helpers/constants.js +++ b/bin/helpers/constants.js @@ -42,7 +42,8 @@ const userMessages = { LOCAL_START_FAILED: "Local Testing setup failed.", LOCAL_STOP_FAILED: "Local Binary stop failed.", INVALID_LOCAL_MODE_WARNING: "Invalid value specified for local_mode. local_mode: (\"always-on\" | \"on-demand\"). For more info, check out https://www.browserstack.com/docs/automate/cypress/cli-reference", - SPEC_LIMIT_WARNING: "You might not see all your results on the dashboard because of high spec count, please consider reducing the number of spec files in this folder." + SPEC_LIMIT_WARNING: "You might not see all your results on the dashboard because of high spec count, please consider reducing the number of spec files in this folder.", + LATEST_SYNTAX_TO_ACTUAL_VERSION_MESSAGE: "Your build will run using Cypress as you had specified . Read more about supported versions here: http://browserstack.com/docs/automate/cypress/supported-versions" }; const validationMessages = { @@ -152,6 +153,8 @@ const DEFAULT_CYPRESS_SPEC_PATH = "cypress/integration" const SPEC_TOTAL_CHAR_LIMIT = 32243; const METADATA_CHAR_BUFFER_PER_SPEC = 175; +const LATEST_VERSION_SYNTAX_REGEX = /\d*.latest(.\d*)?/gm + module.exports = Object.freeze({ syncCLI, userMessages, @@ -163,5 +166,6 @@ module.exports = Object.freeze({ specFileTypes, DEFAULT_CYPRESS_SPEC_PATH, SPEC_TOTAL_CHAR_LIMIT, - METADATA_CHAR_BUFFER_PER_SPEC + METADATA_CHAR_BUFFER_PER_SPEC, + LATEST_VERSION_SYNTAX_REGEX }); diff --git a/bin/helpers/utils.js b/bin/helpers/utils.js index 38ca2475..6a85ec25 100644 --- a/bin/helpers/utils.js +++ b/bin/helpers/utils.js @@ -652,6 +652,12 @@ exports.versionChangedMessage = (preferredVersion, actualVersion) => { return message } +exports.latestSyntaxToActualVersionMessage = (latestSyntaxVersion, actualVersion) => { + let message = Constants.userMessages.LATEST_SYNTAX_TO_ACTUAL_VERSION_MESSAGE.replace("", latestSyntaxVersion); + message = message.replace("", actualVersion); + return message +} + exports.isJSONInvalid = (err, args) => { let invalid = true diff --git a/test/unit/bin/helpers/utils.js b/test/unit/bin/helpers/utils.js index ac105617..9d5c859a 100644 --- a/test/unit/bin/helpers/utils.js +++ b/test/unit/bin/helpers/utils.js @@ -1772,6 +1772,14 @@ describe('utils', () => { }); }) + describe('#latestSyntaxToActualVersionMessage', () => { + it('should return proper info message with placeholders replaced', () => { + let latestSyntaxVersion = "7.latest", actualVersion = "7.6.0"; + let message = constant.userMessages.LATEST_SYNTAX_TO_ACTUAL_VERSION_MESSAGE.replace("", latestSyntaxVersion).replace("", actualVersion); + expect(utils.latestSyntaxToActualVersionMessage(latestSyntaxVersion, actualVersion)).to.eq(message) + }); + }) + describe('#isJSONInvalid', () => { it('JSON is valid when error is parallel misconfiguration', () => { let error = constant.validationMessages.INVALID_PARALLELS_CONFIGURATION; From d7231c641d5388bff158064dfaa7c817a8f0ddca Mon Sep 17 00:00:00 2001 From: Pranav Jain Date: Tue, 27 Jul 2021 19:42:57 +0530 Subject: [PATCH 2/2] add 'Constants' before calling a constant --- bin/commands/runs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/commands/runs.js b/bin/commands/runs.js index 3138855d..54243166 100644 --- a/bin/commands/runs.js +++ b/bin/commands/runs.js @@ -110,7 +110,7 @@ module.exports = function run(args) { } if (bsConfig.run_settings.cypress_version && bsConfig.run_settings.cypress_version !== data.cypress_version) { - if (bsConfig.run_settings.cypress_version.match(LATEST_VERSION_SYNTAX_REGEX)) { + if (bsConfig.run_settings.cypress_version.match(Constants.LATEST_VERSION_SYNTAX_REGEX)) { let versionMessage = utils.latestSyntaxToActualVersionMessage(bsConfig.run_settings.cypress_version, data.cypress_version); logger.info(versionMessage); } else {