Skip to content

Commit f94103c

Browse files
authored
Merge pull request #492 from browserstack/cypress-dependency-fix
Cypress dependency fix
2 parents f14755b + aac35d7 commit f94103c

File tree

4 files changed

+107
-0
lines changed

4 files changed

+107
-0
lines changed

bin/commands/runs.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const { getStackTraceUrl } = require('../helpers/sync/syncSpecsLogs');
2424

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

27+
markBlockStart('preBuild');
2728
// set debug mode (--cli-debug)
2829
utils.setDebugMode(args);
2930

@@ -185,6 +186,8 @@ module.exports = function run(args, rawArgs) {
185186
logger.debug("Started build creation");
186187
markBlockStart('createBuild');
187188
return build.createBuild(bsConfig, zip).then(function (data) {
189+
markBlockEnd('preBuild');
190+
markBlockStart('buildProcessing');
188191
logger.debug("Completed build creation");
189192
markBlockEnd('createBuild');
190193
markBlockEnd('total');
@@ -216,6 +219,8 @@ module.exports = function run(args, rawArgs) {
216219
if (args.sync) {
217220
logger.debug("Started polling build status from BrowserStack");
218221
syncRunner.pollBuildStatus(bsConfig, data, rawArgs, buildReportData).then(async (exitCode) => {
222+
markBlockEnd('buildProcessing');
223+
markBlockStart('postBuild');
219224
logger.debug("Completed polling of build status");
220225

221226
// stop the Local instance
@@ -234,6 +239,7 @@ module.exports = function run(args, rawArgs) {
234239
// Generate custom report!
235240
reportGenerator(bsConfig, data.build_id, args, rawArgs, buildReportData, function(){
236241
utils.sendUsageReport(bsConfig, args, `${message}\n${dashboardLink}`, Constants.messageTypes.SUCCESS, null, buildReportData, rawArgs);
242+
markBlockEnd('postBuild');
237243
utils.handleSyncExit(exitCode, data.dashboard_url);
238244
});
239245
} else {

bin/helpers/checkUploaded.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ const checkUploadedMd5 = (bsConfig, args, instrumentBlocks) => {
8686
zipUrlPresent: false,
8787
packageUrlPresent: false,
8888
};
89+
utils.setCypressNpmDependency(bsConfig);
8990
if (args["force-upload"]) {
9091
logger.debug("force-upload set to true. Uploading tests and npm packages.");
9192
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)