Skip to content

Commit 2c579c1

Browse files
committed
Merge branch 'master' of github.com:roshan04/browserstack-cypress-cli
2 parents 6a943f6 + ed58e18 commit 2c579c1

File tree

14 files changed

+598
-592
lines changed

14 files changed

+598
-592
lines changed

bin/commands/runs.js

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

100+
// set node version
101+
utils.setNodeVersion(bsConfig, args);
102+
100103
//set browsers
101104
await utils.setBrowsers(bsConfig, args);
102105

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/packageInstaller.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
fileHelpers = require('./fileHelpers'),
66
logger = require("./logger").winstonLogger,
77
Constants = require('./constants'),
8-
process = require('process'),
98
utils = require('./utils'),
9+
{ get_version } = require('./usageReporting'),
10+
process = require('process'),
1011
{ spawn } = require('child_process'),
1112
util = require('util');
1213

@@ -64,15 +65,30 @@ const packageInstall = (packageDir) => {
6465
logger.info(`Packages were installed locally successfully.`);
6566
resolve('Packages were installed successfully.');
6667
} else {
67-
logger.error(`Some error occurred while installing packages. Error code ${code}`);
68+
logger.error(`Some error occurred while installing packages. Error code ${code}. Please read npm_install_debug.log for more info.`);
6869
reject(`Packages were not installed successfully. Error code ${code}`);
6970
}
7071
};
7172
const nodeProcessErrorCallback = (error) => {
7273
logger.error(`Some error occurred while installing packages: %j`, error);
7374
reject(`Packages were not installed successfully. Error Description ${util.format('%j', error)}`);
7475
};
75-
nodeProcess = spawn(/^win/.test(process.platform) ? 'npm.cmd' : 'npm', ['install', '--loglevel', 'verbose', '>', '../npm_install_debug.log', '2>&1'], {cwd: packageDir, shell: true});
76+
77+
let nodeProcess;
78+
logger.debug(`Fetching npm version and its major version`);
79+
const npm_version = get_version('npm')
80+
const npm_major_version = utils.getMajorVersion(npm_version);
81+
logger.debug(`Fetched npm version: ${npm_version} and its major version: ${npm_major_version}`);
82+
83+
// add --legacy-peer-deps flag while installing dependencies for npm v7+
84+
// For more info please read "Peer Dependencies" section here -> https://github.blog/2021-02-02-npm-7-is-now-generally-available/
85+
if (parseInt(npm_major_version) >= 7) {
86+
logger.debug(`Running NPM install command: npm install --legacy-peer-deps --loglevel verbose > ../npm_install_debug.log`);
87+
nodeProcess = spawn(/^win/.test(process.platform) ? 'npm.cmd' : 'npm', ['install', '--legacy-peer-deps', '--loglevel', 'verbose', '>', '../npm_install_debug.log', '2>&1'], {cwd: packageDir, shell: true});
88+
} else {
89+
logger.debug(`Running NPM install command: 'npm install --loglevel verbose > ../npm_install_debug.log'`);
90+
nodeProcess = spawn(/^win/.test(process.platform) ? 'npm.cmd' : 'npm', ['install', '--loglevel', 'verbose', '>', '../npm_install_debug.log', '2>&1'], {cwd: packageDir, shell: true});
91+
}
7692
nodeProcess.on('close', nodeProcessCloseCallback);
7793
nodeProcess.on('error', nodeProcessErrorCallback);
7894
});

0 commit comments

Comments
 (0)