diff --git a/bin/commands/runs.js b/bin/commands/runs.js index 14e4e98e..74604378 100644 --- a/bin/commands/runs.js +++ b/bin/commands/runs.js @@ -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); @@ -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'); @@ -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 @@ -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 { diff --git a/bin/helpers/checkUploaded.js b/bin/helpers/checkUploaded.js index 5e580053..79385946 100644 --- a/bin/helpers/checkUploaded.js +++ b/bin/helpers/checkUploaded.js @@ -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); diff --git a/bin/helpers/utils.js b/bin/helpers/utils.js index 91dbcd59..c9247ae7 100644 --- a/bin/helpers/utils.js +++ b/bin/helpers/utils.js @@ -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')); diff --git a/test/unit/bin/helpers/utils.js b/test/unit/bin/helpers/utils.js index de4ae1f0..4ee15936 100644 --- a/test/unit/bin/helpers/utils.js +++ b/test/unit/bin/helpers/utils.js @@ -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; @@ -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); + }); + }); + + });