Skip to content

Commit aac35d7

Browse files
committed
🐛 fix for addinf cypress dependency
1 parent 4e5283f commit aac35d7

File tree

3 files changed

+101
-14
lines changed

3 files changed

+101
-14
lines changed

bin/helpers/checkUploaded.js

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -86,20 +86,7 @@ const checkUploadedMd5 = (bsConfig, args, instrumentBlocks) => {
8686
zipUrlPresent: false,
8787
packageUrlPresent: false,
8888
};
89-
const runSettings = bsConfig.run_settings;
90-
if (runSettings.npm_dependencies !== undefined &&
91-
Object.keys(runSettings.npm_dependencies).length !== 0 &&
92-
typeof runSettings.npm_dependencies === 'object') {
93-
if (!("cypress" in runSettings.npm_dependencies)) {
94-
logger.warn("Missing cypress not found in npm_dependencies");
95-
if ("cypress_version" in runSettings && !runSettings.cypress_version.toString().match(Constants.LATEST_VERSION_SYNTAX_REGEX)) {
96-
runSettings.npm_dependencies.cypress = runSettings.cypress_version;
97-
} else {
98-
runSettings.npm_dependencies.cypress = "latest";
99-
}
100-
logger.warn(`Adding cypress version ${runSettings.npm_dependencies.cypress} in npm_dependencies`);
101-
}
102-
}
89+
utils.setCypressNpmDependency(bsConfig);
10390
if (args["force-upload"]) {
10491
logger.debug("force-upload set to true. Uploading tests and npm packages.");
10592
return resolve(obj);

bin/helpers/utils.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,27 @@ exports.setCypressTestSuiteType = (bsConfig) => {
328328
logger.debug(`Setting cypress test suite type as ${bsConfig.run_settings.cypressTestSuiteType}`);
329329
}
330330

331+
exports.setCypressNpmDependency = (bsConfig) => {
332+
const runSettings = bsConfig.run_settings;
333+
if (runSettings.npm_dependencies !== undefined &&
334+
Object.keys(runSettings.npm_dependencies).length !== 0 &&
335+
typeof runSettings.npm_dependencies === 'object') {
336+
if (!("cypress" in runSettings.npm_dependencies)) {
337+
logger.warn("Missing cypress not found in npm_dependencies");
338+
if("cypress_version" in runSettings){
339+
if(runSettings.cypress_version.toString().match(Constants.LATEST_VERSION_SYNTAX_REGEX)){
340+
runSettings.npm_dependencies.cypress = `^${runSettings.cypress_version.toString().split(".")[0]}`
341+
} else {
342+
runSettings.npm_dependencies.cypress = runSettings.cypress_version;
343+
}
344+
} else if (runSettings.cypressTestSuiteType === Constants.CYPRESS_V10_AND_ABOVE_TYPE) {
345+
runSettings.npm_dependencies.cypress = "latest";
346+
}
347+
logger.warn(`Adding cypress version ${runSettings.npm_dependencies.cypress} in npm_dependencies`);
348+
}
349+
}
350+
}
351+
331352
exports.verifyGeolocationOption = () => {
332353
let glOptionsSet = (this.searchForOption('-gl') || this.searchForOption('--gl'));
333354
let geoHyphenLocationOptionsSet = (this.searchForOption('-geo-location') || this.searchForOption('--geo-location'));

test/unit/bin/helpers/utils.js

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const utils = require('../../../../bin/helpers/utils'),
2323
syncLogger = require('../../../../bin/helpers/logger').syncCliLogger,
2424
Contants = require('../../../../bin/helpers/constants');
2525
const browserstack = require('browserstack-local');
26+
const { CYPRESS_V10_AND_ABOVE_TYPE, CYPRESS_V9_AND_OLDER_TYPE } = require('../../../../bin/helpers/constants');
2627
chai.use(chaiAsPromised);
2728
logger.transports['console.info'].silent = true;
2829

@@ -3522,4 +3523,82 @@ describe('utils', () => {
35223523
expect(utils.getMajorVersion('4.1')).to.be.eql('4');
35233524
});
35243525
});
3526+
3527+
describe('#setCypressNpmDependency', () => {
3528+
3529+
it('should set cypress as latest for cypress 10 test suite if cypress_version missing', () => {
3530+
let bsConfig = {
3531+
run_settings: {
3532+
cypressConfigFilePath: 'cypress.json',
3533+
npm_dependencies: {
3534+
"dummy": "verison"
3535+
},
3536+
cypressTestSuiteType: CYPRESS_V10_AND_ABOVE_TYPE
3537+
},
3538+
};
3539+
utils.setCypressNpmDependency(bsConfig);
3540+
chai.assert.equal(bsConfig.run_settings.npm_dependencies.cypress, "latest");
3541+
});
3542+
3543+
it('should set cypress as ^10 if cypress version added', () => {
3544+
let bsConfig = {
3545+
run_settings: {
3546+
cypress_version: "10.latest",
3547+
cypressConfigFilePath: 'cypress.json',
3548+
npm_dependencies: {
3549+
"dummy": "verison"
3550+
},
3551+
cypressTestSuiteType: CYPRESS_V10_AND_ABOVE_TYPE
3552+
},
3553+
};
3554+
utils.setCypressNpmDependency(bsConfig);
3555+
chai.assert.equal(bsConfig.run_settings.npm_dependencies.cypress, "^10");
3556+
});
3557+
3558+
it('should set cypress as ^10 if cypress version added', () => {
3559+
let bsConfig = {
3560+
run_settings: {
3561+
cypress_version: "10.latest",
3562+
cypressConfigFilePath: 'cypress.json',
3563+
npm_dependencies: {
3564+
"dummy": "verison"
3565+
},
3566+
cypressTestSuiteType: CYPRESS_V10_AND_ABOVE_TYPE
3567+
},
3568+
};
3569+
utils.setCypressNpmDependency(bsConfig);
3570+
chai.assert.equal(bsConfig.run_settings.npm_dependencies.cypress, "^10");
3571+
});
3572+
3573+
it('should set cypress as 10.0.0 if cypress version added', () => {
3574+
let bsConfig = {
3575+
run_settings: {
3576+
cypress_version: "10.0.0",
3577+
cypressConfigFilePath: 'cypress.json',
3578+
npm_dependencies: {
3579+
"dummy": "verison"
3580+
},
3581+
cypressTestSuiteType: CYPRESS_V10_AND_ABOVE_TYPE
3582+
},
3583+
};
3584+
utils.setCypressNpmDependency(bsConfig);
3585+
chai.assert.equal(bsConfig.run_settings.npm_dependencies.cypress, "10.0.0");
3586+
});
3587+
3588+
it('should not set cypress for < 9 cypress version if cypress_version missing', () => {
3589+
let bsConfig = {
3590+
run_settings: {
3591+
cypressConfigFilePath: 'cypress.json',
3592+
npm_dependencies: {
3593+
"dummy": "verison"
3594+
},
3595+
cypressTestSuiteType: CYPRESS_V9_AND_OLDER_TYPE
3596+
},
3597+
};
3598+
utils.setCypressNpmDependency(bsConfig);
3599+
chai.assert.equal(bsConfig.run_settings.npm_dependencies.cypress, undefined);
3600+
});
3601+
});
3602+
3603+
35253604
});

0 commit comments

Comments
 (0)