Skip to content

Commit

Permalink
Merge pull request #467 from browserstack/cypress-dependency-fix
Browse files Browse the repository at this point in the history
🎨 adding cypress dependency if absent in npm_dependencies
  • Loading branch information
agrawalsaurabhs committed Mar 1, 2023
2 parents 0d592bc + 1909a19 commit 1a8b67a
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 0 deletions.
6 changes: 6 additions & 0 deletions bin/commands/runs.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const { getStackTraceUrl } = require('../helpers/sync/syncSpecsLogs');

module.exports = function run(args, rawArgs) {

markBlockStart('preBuild');
// set debug mode (--cli-debug)
utils.setDebugMode(args);

Expand Down Expand Up @@ -194,6 +195,8 @@ module.exports = function run(args, rawArgs) {
logger.debug("Started build creation");
markBlockStart('createBuild');
return build.createBuild(bsConfig, zip).then(function (data) {
markBlockEnd('preBuild');
markBlockStart('buildProcessing');
logger.debug("Completed build creation");
markBlockEnd('createBuild');
markBlockEnd('total');
Expand Down Expand Up @@ -225,6 +228,8 @@ module.exports = function run(args, rawArgs) {
if (args.sync) {
logger.debug("Started polling build status from BrowserStack");
syncRunner.pollBuildStatus(bsConfig, data, rawArgs, buildReportData).then(async (exitCode) => {
markBlockEnd('buildProcessing');
markBlockStart('postBuild');
logger.debug("Completed polling of build status");

// stop the Local instance
Expand All @@ -243,6 +248,7 @@ module.exports = function run(args, rawArgs) {
// Generate custom report!
reportGenerator(bsConfig, data.build_id, args, rawArgs, buildReportData, function(){
utils.sendUsageReport(bsConfig, args, `${message}\n${dashboardLink}`, Constants.messageTypes.SUCCESS, null, buildReportData, rawArgs);
markBlockEnd('postBuild');
utils.handleSyncExit(exitCode, data.dashboard_url);
});
} else {
Expand Down
1 change: 1 addition & 0 deletions bin/helpers/checkUploaded.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ const checkUploadedMd5 = (bsConfig, args, instrumentBlocks) => {
zipUrlPresent: false,
packageUrlPresent: false,
};
utils.setCypressNpmDependency(bsConfig);
if (args["force-upload"]) {
logger.debug("force-upload set to true. Uploading tests and npm packages.");
return resolve(obj);
Expand Down
17 changes: 17 additions & 0 deletions bin/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,23 @@ exports.setCypressTestSuiteType = (bsConfig) => {
logger.debug(`Setting cypress test suite type as ${bsConfig.run_settings.cypressTestSuiteType}`);
}

exports.setCypressNpmDependency = (bsConfig) => {
const runSettings = bsConfig.run_settings;
if (runSettings.npm_dependencies !== undefined &&
Object.keys(runSettings.npm_dependencies).length !== 0 &&
typeof runSettings.npm_dependencies === 'object') {
if (!("cypress" in runSettings.npm_dependencies) && runSettings.cypressTestSuiteType === Constants.CYPRESS_V10_AND_ABOVE_TYPE) {
logger.warn("Missing cypress not found in npm_dependencies");
if("cypress_version" in runSettings){
runSettings.npm_dependencies.cypress = `^${runSettings.cypress_version.toString().split(".")[0]}`;
} else if (runSettings.cypressTestSuiteType === Constants.CYPRESS_V10_AND_ABOVE_TYPE) {
runSettings.npm_dependencies.cypress = "latest";
}
logger.warn(`Adding cypress version ${runSettings.npm_dependencies.cypress} in npm_dependencies`);
}
}
}

exports.verifyGeolocationOption = () => {
let glOptionsSet = (this.searchForOption('-gl') || this.searchForOption('--gl'));
let geoHyphenLocationOptionsSet = (this.searchForOption('-geo-location') || this.searchForOption('--geo-location'));
Expand Down
79 changes: 79 additions & 0 deletions test/unit/bin/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const utils = require('../../../../bin/helpers/utils'),
syncLogger = require('../../../../bin/helpers/logger').syncCliLogger,
Contants = require('../../../../bin/helpers/constants');
const browserstack = require('browserstack-local');
const { CYPRESS_V10_AND_ABOVE_TYPE, CYPRESS_V9_AND_OLDER_TYPE } = require('../../../../bin/helpers/constants');
chai.use(chaiAsPromised);
logger.transports['console.info'].silent = true;

Expand Down Expand Up @@ -3529,4 +3530,82 @@ describe('utils', () => {
expect(utils.getMajorVersion('4.1')).to.be.eql('4');
});
});

describe('#setCypressNpmDependency', () => {

it('should set cypress as latest for cypress 10 test suite if cypress_version missing', () => {
let bsConfig = {
run_settings: {
cypressConfigFilePath: 'cypress.json',
npm_dependencies: {
"dummy": "verison"
},
cypressTestSuiteType: CYPRESS_V10_AND_ABOVE_TYPE
},
};
utils.setCypressNpmDependency(bsConfig);
chai.assert.equal(bsConfig.run_settings.npm_dependencies.cypress, "latest");
});

it('should set cypress as ^10 if cypress version added', () => {
let bsConfig = {
run_settings: {
cypress_version: "10.latest",
cypressConfigFilePath: 'cypress.json',
npm_dependencies: {
"dummy": "verison"
},
cypressTestSuiteType: CYPRESS_V10_AND_ABOVE_TYPE
},
};
utils.setCypressNpmDependency(bsConfig);
chai.assert.equal(bsConfig.run_settings.npm_dependencies.cypress, "^10");
});

it('should set cypress as ^10 if cypress version added', () => {
let bsConfig = {
run_settings: {
cypress_version: "10.latest",
cypressConfigFilePath: 'cypress.json',
npm_dependencies: {
"dummy": "verison"
},
cypressTestSuiteType: CYPRESS_V10_AND_ABOVE_TYPE
},
};
utils.setCypressNpmDependency(bsConfig);
chai.assert.equal(bsConfig.run_settings.npm_dependencies.cypress, "^10");
});

it('should set cypress as 10.0.0 if cypress version added', () => {
let bsConfig = {
run_settings: {
cypress_version: "10.0.0",
cypressConfigFilePath: 'cypress.json',
npm_dependencies: {
"dummy": "verison"
},
cypressTestSuiteType: CYPRESS_V10_AND_ABOVE_TYPE
},
};
utils.setCypressNpmDependency(bsConfig);
chai.assert.equal(bsConfig.run_settings.npm_dependencies.cypress, "^10");
});

it('should not set cypress for < 9 cypress version if cypress_version missing', () => {
let bsConfig = {
run_settings: {
cypressConfigFilePath: 'cypress.json',
npm_dependencies: {
"dummy": "verison"
},
cypressTestSuiteType: CYPRESS_V9_AND_OLDER_TYPE
},
};
utils.setCypressNpmDependency(bsConfig);
chai.assert.equal(bsConfig.run_settings.npm_dependencies.cypress, undefined);
});
});


});

0 comments on commit 1a8b67a

Please sign in to comment.