Skip to content

Commit 1a8b67a

Browse files
Merge pull request #467 from browserstack/cypress-dependency-fix
🎨 adding cypress dependency if absent in npm_dependencies
2 parents 0d592bc + 1909a19 commit 1a8b67a

File tree

4 files changed

+103
-0
lines changed

4 files changed

+103
-0
lines changed

bin/commands/runs.js

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

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

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

@@ -194,6 +195,8 @@ module.exports = function run(args, rawArgs) {
194195
logger.debug("Started build creation");
195196
markBlockStart('createBuild');
196197
return build.createBuild(bsConfig, zip).then(function (data) {
198+
markBlockEnd('preBuild');
199+
markBlockStart('buildProcessing');
197200
logger.debug("Completed build creation");
198201
markBlockEnd('createBuild');
199202
markBlockEnd('total');
@@ -225,6 +228,8 @@ module.exports = function run(args, rawArgs) {
225228
if (args.sync) {
226229
logger.debug("Started polling build status from BrowserStack");
227230
syncRunner.pollBuildStatus(bsConfig, data, rawArgs, buildReportData).then(async (exitCode) => {
231+
markBlockEnd('buildProcessing');
232+
markBlockStart('postBuild');
228233
logger.debug("Completed polling of build status");
229234

230235
// stop the Local instance
@@ -243,6 +248,7 @@ module.exports = function run(args, rawArgs) {
243248
// Generate custom report!
244249
reportGenerator(bsConfig, data.build_id, args, rawArgs, buildReportData, function(){
245250
utils.sendUsageReport(bsConfig, args, `${message}\n${dashboardLink}`, Constants.messageTypes.SUCCESS, null, buildReportData, rawArgs);
251+
markBlockEnd('postBuild');
246252
utils.handleSyncExit(exitCode, data.dashboard_url);
247253
});
248254
} 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: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,23 @@ exports.setCypressTestSuiteType = (bsConfig) => {
331331
logger.debug(`Setting cypress test suite type as ${bsConfig.run_settings.cypressTestSuiteType}`);
332332
}
333333

334+
exports.setCypressNpmDependency = (bsConfig) => {
335+
const runSettings = bsConfig.run_settings;
336+
if (runSettings.npm_dependencies !== undefined &&
337+
Object.keys(runSettings.npm_dependencies).length !== 0 &&
338+
typeof runSettings.npm_dependencies === 'object') {
339+
if (!("cypress" in runSettings.npm_dependencies) && runSettings.cypressTestSuiteType === Constants.CYPRESS_V10_AND_ABOVE_TYPE) {
340+
logger.warn("Missing cypress not found in npm_dependencies");
341+
if("cypress_version" in runSettings){
342+
runSettings.npm_dependencies.cypress = `^${runSettings.cypress_version.toString().split(".")[0]}`;
343+
} else if (runSettings.cypressTestSuiteType === Constants.CYPRESS_V10_AND_ABOVE_TYPE) {
344+
runSettings.npm_dependencies.cypress = "latest";
345+
}
346+
logger.warn(`Adding cypress version ${runSettings.npm_dependencies.cypress} in npm_dependencies`);
347+
}
348+
}
349+
}
350+
334351
exports.verifyGeolocationOption = () => {
335352
let glOptionsSet = (this.searchForOption('-gl') || this.searchForOption('--gl'));
336353
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

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

0 commit comments

Comments
 (0)