diff --git a/bin/helpers/capabilityHelper.js b/bin/helpers/capabilityHelper.js index 97266e5e..b6068548 100644 --- a/bin/helpers/capabilityHelper.js +++ b/bin/helpers/capabilityHelper.js @@ -20,27 +20,13 @@ const isAboveAccessibilityCypressMajor = (cypressVersion) => { return major !== undefined && major > Constants.MAX_CYPRESS_MAJOR_FOR_ACCESSIBILITY; }; -const versionParts = (version) => String(version).split('.').map((n) => Number(n)); - -const isBefore = (version, other) => { - const a = versionParts(version), b = versionParts(other); - for (let i = 0; i < 3; i++) { - if ((a[i] || 0) !== (b[i] || 0)) return (a[i] || 0) < (b[i] || 0); - } - return false; -}; - -// True for an accessibility build whose Cypress has the extension service-worker bug. -// "16" and "16.latest" name no minor, so Rails picks it: they count while 16.2.0 is the only -// Cypress 16 Rails offers. Once Rails offers 16.2.1+, drop that branch. -const needsForceHttp1ForAccessibility = (cypressVersion) => { - const [firstAffected, firstFixed] = Constants.ACCESSIBILITY_FORCE_HTTP1_CYPRESS_RANGE; - const value = String(cypressVersion).trim().toLowerCase(); - const exact = value.match(/^(\d+)\.(\d+)\.(\d+)$/); - if (exact) return !isBefore(value, firstAffected) && isBefore(value, firstFixed); - const majorOnly = value.match(/^(\d+)(\.latest)?$/); - return !!majorOnly && Number(majorOnly[1]) === versionParts(firstAffected)[0]; -}; +// True for an accessibility build on Cypress 16. Keyed on the major, not the requested version: +// Rails runs the newest 16 it offers for any 16.x it doesn't list (e.g. 16.2.1, 16.3.0, "16.2"), +// and that is 16.2.0 today, which has the extension service-worker bug (fixed in 16.2.1). +// The version that actually runs is only known server-side, so this should move there +// (terminalDeploy, next to the Cypress 16 network-logs/Local forceHttp1 rule) and be removed here. +const needsForceHttp1ForAccessibility = (cypressVersion) => + cypressMajor(String(cypressVersion).trim()) === Constants.ACCESSIBILITY_FORCE_HTTP1_CYPRESS_MAJOR; // Adds forceHttp1=true to the run's Cypress config unless the user already set forceHttp1 // (either way), keeping every other key they passed. @@ -176,13 +162,13 @@ const caps = (bsConfig, zip) => { // send run_settings as is for other capabilities let runSettings = bsConfig.run_settings; - // Rails defaults to its newest Cypress, which accessibility does not support yet, so an - // accessibility build without a version asks for the newest major accessibility supports. + // An accessibility build without a version asks for DEFAULT_CYPRESS_MAJOR_FOR_ACCESSIBILITY, + // which keeps unpinned builds off the Cypress 16 forceHttp1 path (see constants.js). if (isAccessibilityOn(bsConfig) && Utils.isUndefined(runSettings.cypress_version)) { runSettings = Object.assign({}, runSettings, { cypress_version: String(Constants.DEFAULT_CYPRESS_MAJOR_FOR_ACCESSIBILITY) }); logger.info(Constants.userMessages.ACCESSIBILITY_CYPRESS_VERSION_PINNED); } - // Accessibility scans on the affected Cypress 16 versions only complete with forceHttp1. + // Accessibility scans on the Cypress 16 that Rails runs today (16.2.0) only complete with forceHttp1. if (isAccessibilityOn(bsConfig) && !Utils.isUndefined(runSettings.cypress_version) && needsForceHttp1ForAccessibility(runSettings.cypress_version)) { const config = withForceHttp1(runSettings.config); diff --git a/bin/helpers/constants.js b/bin/helpers/constants.js index bc4362e1..0882c07b 100644 --- a/bin/helpers/constants.js +++ b/bin/helpers/constants.js @@ -89,7 +89,7 @@ const userMessages = { ACCESSIBILITY_CYPRESS_VERSION_PINNED: "Accessibility builds without a cypress_version run on the latest Cypress 15.", ACCESSIBILITY_FORCE_HTTP1_SET: - "Accessibility on Cypress 16.1.0-16.2.0 needs Cypress's HTTP/1.1 proxy, so this build runs with forceHttp1=true.", + "Accessibility on Cypress 16 runs on Cypress 16.2.0, which needs Cypress's HTTP/1.1 proxy, so this build runs with forceHttp1=true.", CYPRESS_VERSION_CHANGED: "Your build will run using Cypress instead of Cypress . Read more about supported versions here: http://browserstack.com/docs/automate/cypress/supported-versions", LOCAL_START_FAILED: "Local Testing setup failed.", @@ -451,14 +451,16 @@ const SPEC_TIMEOUT_LIMIT = 120; // IN MINS // Newest Cypress major accessibility runs on (APS-22894). Raising this needs no Rails change. const MAX_CYPRESS_MAJOR_FOR_ACCESSIBILITY = 16; -// Major an accessibility build asks for when it names no cypress_version. Stays on 15 while -// Rails' own default does, so an unpinned build keeps today's Cypress. +// Major an accessibility build asks for when it names no cypress_version. This CLI's choice, not +// Rails': for a CLI that sends cypressExposeSupport, Rails defaults to its newest Cypress (16). +// Kept on 15 so unpinned accessibility builds stay off the Cypress 16 forceHttp1 path. const DEFAULT_CYPRESS_MAJOR_FOR_ACCESSIBILITY = 15; -// Cypress versions where the a11y extension's service worker never starts, so every scan times -// out unless forceHttp1 is on: [first affected, first fixed). Regression from cypress-io/cypress#34762 -// (16.1.0), reported as cypress-io/cypress#35127, fixed by #34958 in 16.2.1. +// Cypress major whose accessibility builds get forceHttp1. On 16.1.0-16.2.0 the a11y extension's +// service worker never starts, so every scan times out unless forceHttp1 is on. Regression from +// cypress-io/cypress#34762 (16.1.0), reported as cypress-io/cypress#35127, fixed by #34958 in 16.2.1. +// Whole major, because Rails runs 16.2.0 for every 16.x request while it is the only 16 it offers. // SDK-8048 preprod A/B on 16.2.0: scan step 25.6s without forceHttp1, 4.2s with it. -const ACCESSIBILITY_FORCE_HTTP1_CYPRESS_RANGE = ['16.1.0', '16.2.1']; +const ACCESSIBILITY_FORCE_HTTP1_CYPRESS_MAJOR = 16; const CYPRESS_CUSTOM_ERRORS_TO_PRINT_KEY = "custom_errors_to_print"; @@ -527,7 +529,7 @@ module.exports = Object.freeze({ SPEC_TIMEOUT_LIMIT, MAX_CYPRESS_MAJOR_FOR_ACCESSIBILITY, DEFAULT_CYPRESS_MAJOR_FOR_ACCESSIBILITY, - ACCESSIBILITY_FORCE_HTTP1_CYPRESS_RANGE, + ACCESSIBILITY_FORCE_HTTP1_CYPRESS_MAJOR, CYPRESS_CUSTOM_ERRORS_TO_PRINT_KEY, CYPRESS_V9_AND_OLDER_TYPE, CYPRESS_V10_AND_ABOVE_TYPE, diff --git a/test/unit/bin/accessibility-automation/plugin/index.js b/test/unit/bin/accessibility-automation/plugin/index.js index ff774b5c..4a6d6d3e 100644 --- a/test/unit/bin/accessibility-automation/plugin/index.js +++ b/test/unit/bin/accessibility-automation/plugin/index.js @@ -19,11 +19,16 @@ describe('accessibility plugin exposes browser values', () => { BROWSERSTACK_ACCESSIBILITY_DEBUG: 'true', }; + // The plugin itself sets these, so they are restored too. + const SET_BY_PLUGIN = ['BROWSERSTACK_LOGS', 'BROWSERSTACK_ACCESSIBILITY_PLUGIN_LOADED']; + const RESTORED = Object.keys(ENV).concat(SET_BY_PLUGIN); + beforeEach(() => { - Object.keys(ENV).forEach((k) => { saved[k] = process.env[k]; process.env[k] = ENV[k]; }); + RESTORED.forEach((k) => { saved[k] = process.env[k]; }); + Object.keys(ENV).forEach((k) => { process.env[k] = ENV[k]; }); }); afterEach(() => { - Object.keys(ENV).forEach((k) => { if (saved[k] === undefined) delete process.env[k]; else process.env[k] = saved[k]; }); + RESTORED.forEach((k) => { if (saved[k] === undefined) delete process.env[k]; else process.env[k] = saved[k]; }); }); const run = (config) => { diff --git a/test/unit/bin/helpers/capabilityHelper.js b/test/unit/bin/helpers/capabilityHelper.js index 5eb3cb22..54ac40a1 100644 --- a/test/unit/bin/helpers/capabilityHelper.js +++ b/test/unit/bin/helpers/capabilityHelper.js @@ -141,7 +141,8 @@ describe("capabilityHelper.js", () => { }); }); - ["16", "16.latest", "16.1.0", "16.1.1", "16.2.0"].forEach((version) => { + // Rails runs 16.2.0 for any 16.x it doesn't list, so every Cypress 16 request needs it. + ["16", "16.latest", "16.latest-1", "16.2", "16.0.0", "16.1.0", "16.1.1", "16.2.0", "16.2.1", "16.3.0"].forEach((version) => { it(`adds forceHttp1=true for accessibility on cypress_version ${version}`, () => { return sentRunSettings({ accessibility: true, cypress_version: version }).then(({ sent, bsConfig }) => { chai.assert.equal(sent.config, "forceHttp1=true"); @@ -169,9 +170,7 @@ describe("capabilityHelper.js", () => { ["accessibility on, no version (pinned to 15)", { accessibility: true }], ["accessibility off, Cypress 16", { accessibility: false, cypress_version: "16.2.0" }], ["accessibility on, cypress_version latest", { accessibility: true, cypress_version: "latest" }], - ["accessibility on, Cypress 16.2.1 (fixed)", { accessibility: true, cypress_version: "16.2.1" }], - ["accessibility on, Cypress 16.3.0 (fixed)", { accessibility: true, cypress_version: "16.3.0" }], - ["accessibility on, Cypress 16.0.0 (before the regression)", { accessibility: true, cypress_version: "16.0.0" }], + ["accessibility on, Cypress 17", { accessibility: true, cypress_version: "17.0.0" }], ].forEach(([name, runSettings]) => { it(`does not add forceHttp1 for ${name}`, () => { return sentRunSettings(runSettings).then(({ sent }) => {