Skip to content

Commit 6d0032e

Browse files
committed
add code changes to parse and validate node version
1 parent 754690e commit 6d0032e

File tree

6 files changed

+47
-2
lines changed

6 files changed

+47
-2
lines changed

bin/commands/runs.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ module.exports = function run(args, rawArgs) {
9494
// set record feature caps
9595
utils.setRecordCaps(bsConfig, args);
9696

97+
// set node version
98+
utils.setNodeVersion(bsConfig, args);
99+
97100
//set browsers
98101
await utils.setBrowsers(bsConfig, args);
99102

bin/helpers/capabilityHelper.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,9 @@ const validate = (bsConfig, args) => {
254254
}
255255
}
256256

257+
if (!Utils.isUndefined(bsConfig.run_settings.nodeVersion) && typeof(bsConfig.run_settings.nodeVersion) === 'string' && !bsConfig.run_settings.nodeVersion.match(/^(\d+\.)?(\d+\.)?(\*|\d+)$/))
258+
logger.warn(Constants.validationMessages.NODE_VERSION_PARSING_ERROR);
259+
257260
resolve(cypressJson);
258261
});
259262
}

bin/helpers/constants.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ const validationMessages = {
104104
SPEC_TIMEOUT_LIMIT_ERROR: "The maximum allowed value of 'spec_timeout' is 120. Read more on https://browserstack.com/docs/automate/cypress/spec-timeout ",
105105
SPEC_TIMEOUT_NOT_PASSED_ERROR: "'spec_timeout' key not specified. Going ahead with 30 mins as the default spec timeout. Read more about how to specify the option in https://browserstack.com/docs/automate/cypress/spec-timeout ",
106106
PROJECT_ID_MISSING: "You have specified '--record' flag but you've not provided the 'projectId' in cypress.json or in browserstack.json. Your record functionality on cypress.io dashboard might not work as it needs both the key and the projectId",
107-
RECORD_KEY_MISSING: "You have specified '--record' flag but you've not provided the '--record-key' and we could not find any value in 'CYPRESS_RECORD_KEY' environment variable. Your record functionality on cypress.io dashboard might not work as it needs the key and projectId"
107+
RECORD_KEY_MISSING: "You have specified '--record' flag but you've not provided the '--record-key' and we could not find any value in 'CYPRESS_RECORD_KEY' environment variable. Your record functionality on cypress.io dashboard might not work as it needs the key and projectId",
108+
NODE_VERSION_PARSING_ERROR: "We weren't able to successfully parse the specified nodeVersion. We will be using the default nodeVersion to run your tests."
108109
};
109110

110111
const cliMessages = {
@@ -151,7 +152,8 @@ const cliMessages = {
151152
SPEC_TIMEOUT: "Specify a value for a hard timeout for each spec execution in the 1-120 mins range. Read https://browserstack.com/docs/automate/cypress/spec-timeout for more details.",
152153
RECORD: "Pass the --record flag to record your Cypress runs on Cypress.io dashboard. Note: You also need to specify '--record-key' and '--projectId' arguments either in CLI or in browserstack.json.",
153154
RECORD_KEY: "You can specify the 'key' that is needed to record your runs on Cypress.io dashboard using the '--record-key' argument. Alternatively, you can also pass it on browserstack.json",
154-
PROJECT_ID: "You can pass the 'projectId' of your Cypress.io project where you want to record your runs if specifying the '--record' key. You can also specify this in your cypress.json or in your browserstack.json."
155+
PROJECT_ID: "You can pass the 'projectId' of your Cypress.io project where you want to record your runs if specifying the '--record' key. You can also specify this in your cypress.json or in your browserstack.json.",
156+
NODE_VERSION: "Pass the node version that you want BrowserStack to use to run your Cypress tests on."
155157
},
156158
COMMON: {
157159
DISABLE_USAGE_REPORTING: "Disable usage reporting",

bin/helpers/usageReporting.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,4 +291,5 @@ function send(args) {
291291
module.exports = {
292292
send,
293293
cli_version_and_path,
294+
get_version
294295
};

bin/helpers/utils.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,36 @@ exports.setRecordCaps = (bsConfig, args) => {
371371
bsConfig.run_settings["projectId"] = this.setProjectId(bsConfig, args);
372372
}
373373

374+
exports.verifyNodeVersionOption = () => {
375+
let nvOptionsSet = (this.searchForOption('-nv') || this.searchForOption('--nv'));
376+
let nodeVersionHyphenLocationOptionsSet = (this.searchForOption('-node-version') || this.searchForOption('--node-version'));
377+
let nodeVersionOptionsSet = (this.searchForOption('-nodeVersion') || this.searchForOption('--nodeVersion'));
378+
return (nvOptionsSet || nodeVersionHyphenLocationOptionsSet || nodeVersionOptionsSet);
379+
}
380+
381+
exports.setNodeVersion = (bsConfig, args) => {
382+
let userProvidedNodeVersion = this.verifyNodeVersionOption();
383+
bsConfig.run_settings.userProvidedNodeVersion = (userProvidedNodeVersion || (!this.isUndefined(bsConfig.run_settings.nodeVersion)) || (!this.isUndefined(bsConfig.run_settings.nodeversion)));
384+
385+
if (bsConfig.run_settings.userProvidedNodeVersion) {
386+
if(!this.isUndefined(args.nodeVersion)) {
387+
bsConfig.run_settings.nodeVersion = args.nodeVersion;
388+
} else if (!this.isUndefined(bsConfig.run_settings.nodeversion)) {
389+
bsConfig.run_settings.nodeVersion = bsConfig.run_settings.nodeversion;
390+
}
391+
}
392+
393+
if (this.isUndefined(bsConfig.run_settings.nodeVersion)) {
394+
bsConfig.run_settings.nodeVersion = usageReporting.get_version('node') || '';
395+
}
396+
397+
if (bsConfig.run_settings.nodeVersion && typeof(bsConfig.run_settings.nodeVersion) === 'string' && bsConfig.run_settings.nodeVersion.charAt(0).toLowerCase() === 'v') {
398+
bsConfig.run_settings.nodeVersion = bsConfig.run_settings.nodeVersion.substr(1);
399+
}
400+
401+
logger.debug(`Setting nodeVersion = ${bsConfig.run_settings.nodeVersion}`);
402+
}
403+
374404
// specs can be passed from bstack configuration file
375405
// specs can be passed via command line args as a string
376406
// command line args takes precedence over config

bin/runner.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,12 @@ var argv = yargs
265265
default: undefined,
266266
describe: Constants.cliMessages.RUN.PROJECT_ID,
267267
type: "string"
268+
},
269+
'nv': {
270+
alias: ['node-version', 'nodeVersion'],
271+
default: undefined,
272+
describe: Constants.cliMessages.RUN.NODE_VERSION,
273+
type: "string"
268274
}
269275
})
270276
.help('help')

0 commit comments

Comments
 (0)