diff --git a/bin/commands/runs.js b/bin/commands/runs.js index daea68b7..b2181303 100644 --- a/bin/commands/runs.js +++ b/bin/commands/runs.js @@ -72,7 +72,7 @@ module.exports = function run(args, rawArgs) { utils.setCypressConfigFilename(bsConfig, args); /* Set testObservability & browserstackAutomation flags */ - const [isTestObservabilitySession, isBrowserstackInfra] = setTestObservabilityFlags(bsConfig); + let [isTestObservabilitySession, isBrowserstackInfra] = setTestObservabilityFlags(bsConfig); const checkAccessibility = checkAccessibilityPlatform(bsConfig); let isAccessibilitySession = bsConfig.run_settings.accessibility || checkAccessibility; const turboScaleSession = isTurboScaleSession(bsConfig); @@ -91,6 +91,19 @@ module.exports = function run(args, rawArgs) { let buildReportData = (turboScaleSession || !isBrowserstackInfra) ? null : await getInitialDetails(bsConfig, args, rawArgs); + // APS-22894: the TestHub and Accessibility hooks injected into the support file call + // Cypress.env(), which Cypress 16 removed from the browser, so neither can run there yet. + // Decided here, before the support file is patched and the suite is zipped. + const cypressMajorVersion = utils.getCypressMajorVersion(bsConfig, buildReportData); + if (isBrowserstackInfra && (isTestObservabilitySession || isAccessibilitySession) + && cypressMajorVersion >= Constants.TESTHUB_A11Y_UNSUPPORTED_FROM_CYPRESS_MAJOR) { + logger.warn(Constants.userMessages.TESTHUB_A11Y_NOT_SUPPORTED_ON_CYPRESS_MAJOR.replace('', cypressMajorVersion)); + isTestObservabilitySession = false; + isAccessibilitySession = false; + bsConfig["testObservability"] = false; + process.env.BROWSERSTACK_TEST_OBSERVABILITY = 'false'; + } + // accept the build name from command line if provided utils.setBuildName(bsConfig, args); diff --git a/bin/helpers/constants.js b/bin/helpers/constants.js index c0bdd495..2642cfe6 100644 --- a/bin/helpers/constants.js +++ b/bin/helpers/constants.js @@ -19,6 +19,8 @@ const syncCLI = { }; const userMessages = { + TESTHUB_A11Y_NOT_SUPPORTED_ON_CYPRESS_MAJOR: + "TestHub (Test Observability) and Accessibility are not yet supported on Cypress . Disabling both for this build; your tests will still run. Read more about supported versions here: http://browserstack.com/docs/automate/cypress/supported-versions", ACCESSIBILITY_PLUGIN_NOT_LOADED: "BrowserStack Accessibility Automation plugin is not loaded in your cypress config file. Disabling accessibility for this build. Please follow https://www.browserstack.com/docs/accessibility/automated-tests/get-started/cypress to enable accessibility testing.", BUILD_FAILED: "Build creation failed.", @@ -469,6 +471,11 @@ const CYPRESS_CONFIG_FILE_MAPPING = { const CYPRESS_CONFIG_FILE_NAMES = Object.keys(CYPRESS_CONFIG_FILE_MAPPING); +// APS-22894: the TestHub and Accessibility support-file hooks read Cypress.env(), which +// Cypress 16 removed from the browser. Both are disabled from this major until the hooks +// move to Cypress.expose(). +const TESTHUB_A11Y_UNSUPPORTED_FROM_CYPRESS_MAJOR = 16; + const CYPRESS_V10_AND_ABOVE_CONFIG_FILE_EXTENSIONS = ['js', 'ts', 'cjs', 'mjs'] // Maximum size of VCS info which is allowed @@ -514,6 +521,7 @@ module.exports = Object.freeze({ CYPRESS_CONFIG_FILE_MAPPING, CYPRESS_CONFIG_FILE_NAMES, CYPRESS_V10_AND_ABOVE_CONFIG_FILE_EXTENSIONS, + TESTHUB_A11Y_UNSUPPORTED_FROM_CYPRESS_MAJOR, MAX_GIT_META_DATA_SIZE_IN_BYTES, GIT_META_DATA_TRUNCATED }); diff --git a/bin/helpers/utils.js b/bin/helpers/utils.js index 2cc7f133..5632c7d6 100644 --- a/bin/helpers/utils.js +++ b/bin/helpers/utils.js @@ -1452,6 +1452,20 @@ exports.setConfig = (bsConfig, args) => { } } +// Major of the Cypress version this run will get: the requested cypress_version when +// browserstack.json sets one ("16", "16.latest", "16.2.0"), else the default the server +// applies (default_cypress_version from get_initial_details). undefined when neither parses. +exports.getCypressMajorVersion = (bsConfig, buildReportData) => { + const requested = (bsConfig && bsConfig.run_settings && bsConfig.run_settings.cypress_version) + ? bsConfig.run_settings.cypress_version.toString() : undefined; + const fallback = (buildReportData && buildReportData.default_cypress_version) + ? buildReportData.default_cypress_version.toString() : undefined; + const version = requested || fallback; + if (this.isUndefined(version)) return undefined; + const match = version.match(/^(\d+)/); + return match ? parseInt(match[1], 10) : undefined; +} + exports.setVideoCliConfig = (bsConfig, videoConfig) => { // set cli config for video for cypress 13 and above to attain default value of true. if(this.isUndefined(videoConfig) || this.isUndefined(videoConfig.video) || this.isUndefined(videoConfig.videoUploadOnPasses) || this.isUndefined(bsConfig)) return; diff --git a/test/unit/bin/helpers/utils.js b/test/unit/bin/helpers/utils.js index 480cb5f4..4d6ee1df 100644 --- a/test/unit/bin/helpers/utils.js +++ b/test/unit/bin/helpers/utils.js @@ -5748,4 +5748,29 @@ describe('utils', () => { }); }); + describe('getCypressMajorVersion', () => { + it('reads the major from an exact requested version', () => { + expect(utils.getCypressMajorVersion({ run_settings: { cypress_version: '16.2.0' } }, {})).to.eql(16); + }); + it('reads the major from the .latest syntax', () => { + expect(utils.getCypressMajorVersion({ run_settings: { cypress_version: '16.latest' } }, {})).to.eql(16); + }); + it('reads the major from a bare major, including numeric values', () => { + expect(utils.getCypressMajorVersion({ run_settings: { cypress_version: 15 } }, {})).to.eql(15); + }); + it('falls back to the server default when no version is requested', () => { + expect(utils.getCypressMajorVersion({ run_settings: {} }, { default_cypress_version: '16.2.0' })).to.eql(16); + }); + it('prefers the requested version over the server default', () => { + expect(utils.getCypressMajorVersion({ run_settings: { cypress_version: '13.15.0' } }, { default_cypress_version: '16.2.0' })).to.eql(13); + }); + it('is undefined when neither a requested nor a default version is known', () => { + expect(utils.getCypressMajorVersion({ run_settings: {} }, {})).to.be.undefined; + expect(utils.getCypressMajorVersion({ run_settings: {} }, null)).to.be.undefined; + }); + it('is undefined when the version does not start with a number', () => { + expect(utils.getCypressMajorVersion({ run_settings: { cypress_version: 'latest' } }, {})).to.be.undefined; + }); + }); + });