Skip to content

Commit 19083f5

Browse files
authored
Changes in CLI messages to support browserstack cypress latest flag (#156)
* add code to show appropriate info message when latest syntax is used * add 'Constants' before calling a constant
1 parent 0121503 commit 19083f5

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

bin/commands/runs.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,13 @@ module.exports = function run(args) {
116116
}
117117

118118
if (bsConfig.run_settings.cypress_version && bsConfig.run_settings.cypress_version !== data.cypress_version) {
119-
let versionMessage = utils.versionChangedMessage(bsConfig.run_settings.cypress_version, data.cypress_version)
120-
logger.warn(versionMessage);
119+
if (bsConfig.run_settings.cypress_version.match(Constants.LATEST_VERSION_SYNTAX_REGEX)) {
120+
let versionMessage = utils.latestSyntaxToActualVersionMessage(bsConfig.run_settings.cypress_version, data.cypress_version);
121+
logger.info(versionMessage);
122+
} else {
123+
let versionMessage = utils.versionChangedMessage(bsConfig.run_settings.cypress_version, data.cypress_version);
124+
logger.warn(versionMessage);
125+
}
121126
}
122127

123128
if (!args.disableNpmWarning && bsConfig.run_settings.npm_dependencies && Object.keys(bsConfig.run_settings.npm_dependencies).length <= 0) {

bin/helpers/constants.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ const userMessages = {
4444
LOCAL_START_FAILED: "Local Testing setup failed.",
4545
LOCAL_STOP_FAILED: "Local Binary stop failed.",
4646
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",
47-
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."
47+
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.",
48+
LATEST_SYNTAX_TO_ACTUAL_VERSION_MESSAGE: "Your build will run using Cypress <actualVersion> as you had specified <latestSyntaxVersion>. Read more about supported versions here: http://browserstack.com/docs/automate/cypress/supported-versions"
4849
};
4950

5051
const validationMessages = {
@@ -170,6 +171,8 @@ const DEFAULT_CYPRESS_SPEC_PATH = "cypress/integration"
170171
const SPEC_TOTAL_CHAR_LIMIT = 32243;
171172
const METADATA_CHAR_BUFFER_PER_SPEC = 175;
172173

174+
const LATEST_VERSION_SYNTAX_REGEX = /\d*.latest(.\d*)?/gm
175+
173176
module.exports = Object.freeze({
174177
syncCLI,
175178
userMessages,
@@ -183,5 +186,6 @@ module.exports = Object.freeze({
183186
specFileTypes,
184187
DEFAULT_CYPRESS_SPEC_PATH,
185188
SPEC_TOTAL_CHAR_LIMIT,
186-
METADATA_CHAR_BUFFER_PER_SPEC
189+
METADATA_CHAR_BUFFER_PER_SPEC,
190+
LATEST_VERSION_SYNTAX_REGEX
187191
});

bin/helpers/utils.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,12 @@ exports.versionChangedMessage = (preferredVersion, actualVersion) => {
717717
return message
718718
}
719719

720+
exports.latestSyntaxToActualVersionMessage = (latestSyntaxVersion, actualVersion) => {
721+
let message = Constants.userMessages.LATEST_SYNTAX_TO_ACTUAL_VERSION_MESSAGE.replace("<latestSyntaxVersion>", latestSyntaxVersion);
722+
message = message.replace("<actualVersion>", actualVersion);
723+
return message
724+
}
725+
720726
exports.isJSONInvalid = (err, args) => {
721727
let invalid = true
722728

test/unit/bin/helpers/utils.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1890,6 +1890,14 @@ describe('utils', () => {
18901890
});
18911891
})
18921892

1893+
describe('#latestSyntaxToActualVersionMessage', () => {
1894+
it('should return proper info message with placeholders replaced', () => {
1895+
let latestSyntaxVersion = "7.latest", actualVersion = "7.6.0";
1896+
let message = constant.userMessages.LATEST_SYNTAX_TO_ACTUAL_VERSION_MESSAGE.replace("<latestSyntaxVersion>", latestSyntaxVersion).replace("<actualVersion>", actualVersion);
1897+
expect(utils.latestSyntaxToActualVersionMessage(latestSyntaxVersion, actualVersion)).to.eq(message)
1898+
});
1899+
})
1900+
18931901
describe('#isJSONInvalid', () => {
18941902
it('JSON is valid when error is parallel misconfiguration', () => {
18951903
let error = constant.validationMessages.INVALID_PARALLELS_CONFIGURATION;

0 commit comments

Comments
 (0)