Skip to content

Cypress dependency fix #492

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions bin/commands/runs.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,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 @@ -185,6 +186,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 @@ -216,6 +219,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 @@ -234,6 +239,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
21 changes: 21 additions & 0 deletions bin/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,27 @@ 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)) {
logger.warn("Missing cypress not found in npm_dependencies");
if("cypress_version" in runSettings){
if(runSettings.cypress_version.toString().match(Constants.LATEST_VERSION_SYNTAX_REGEX)){
runSettings.npm_dependencies.cypress = `^${runSettings.cypress_version.toString().split(".")[0]}`
} else {
runSettings.npm_dependencies.cypress = runSettings.cypress_version;
}
} 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 @@ -3522,4 +3523,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.0.0");
});

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);
});
});


});