Skip to content

Commit e64dcc1

Browse files
Merge pull request #1223 from browserstack/SDK-8048-review-fixes
SDK-8048: address #1206 review — forceHttp1 on every Cypress 16 a11y build
2 parents ee19496 + 7ca0e7b commit e64dcc1

4 files changed

Lines changed: 30 additions & 38 deletions

File tree

‎bin/helpers/capabilityHelper.js‎

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,13 @@ const isAboveAccessibilityCypressMajor = (cypressVersion) => {
2020
return major !== undefined && major > Constants.MAX_CYPRESS_MAJOR_FOR_ACCESSIBILITY;
2121
};
2222

23-
const versionParts = (version) => String(version).split('.').map((n) => Number(n));
24-
25-
const isBefore = (version, other) => {
26-
const a = versionParts(version), b = versionParts(other);
27-
for (let i = 0; i < 3; i++) {
28-
if ((a[i] || 0) !== (b[i] || 0)) return (a[i] || 0) < (b[i] || 0);
29-
}
30-
return false;
31-
};
32-
33-
// True for an accessibility build whose Cypress has the extension service-worker bug.
34-
// "16" and "16.latest" name no minor, so Rails picks it: they count while 16.2.0 is the only
35-
// Cypress 16 Rails offers. Once Rails offers 16.2.1+, drop that branch.
36-
const needsForceHttp1ForAccessibility = (cypressVersion) => {
37-
const [firstAffected, firstFixed] = Constants.ACCESSIBILITY_FORCE_HTTP1_CYPRESS_RANGE;
38-
const value = String(cypressVersion).trim().toLowerCase();
39-
const exact = value.match(/^(\d+)\.(\d+)\.(\d+)$/);
40-
if (exact) return !isBefore(value, firstAffected) && isBefore(value, firstFixed);
41-
const majorOnly = value.match(/^(\d+)(\.latest)?$/);
42-
return !!majorOnly && Number(majorOnly[1]) === versionParts(firstAffected)[0];
43-
};
23+
// True for an accessibility build on Cypress 16. Keyed on the major, not the requested version:
24+
// 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"),
25+
// and that is 16.2.0 today, which has the extension service-worker bug (fixed in 16.2.1).
26+
// The version that actually runs is only known server-side, so this should move there
27+
// (terminalDeploy, next to the Cypress 16 network-logs/Local forceHttp1 rule) and be removed here.
28+
const needsForceHttp1ForAccessibility = (cypressVersion) =>
29+
cypressMajor(String(cypressVersion).trim()) === Constants.ACCESSIBILITY_FORCE_HTTP1_CYPRESS_MAJOR;
4430

4531
// Adds forceHttp1=true to the run's Cypress config unless the user already set forceHttp1
4632
// (either way), keeping every other key they passed.
@@ -176,13 +162,13 @@ const caps = (bsConfig, zip) => {
176162

177163
// send run_settings as is for other capabilities
178164
let runSettings = bsConfig.run_settings;
179-
// Rails defaults to its newest Cypress, which accessibility does not support yet, so an
180-
// accessibility build without a version asks for the newest major accessibility supports.
165+
// An accessibility build without a version asks for DEFAULT_CYPRESS_MAJOR_FOR_ACCESSIBILITY,
166+
// which keeps unpinned builds off the Cypress 16 forceHttp1 path (see constants.js).
181167
if (isAccessibilityOn(bsConfig) && Utils.isUndefined(runSettings.cypress_version)) {
182168
runSettings = Object.assign({}, runSettings, { cypress_version: String(Constants.DEFAULT_CYPRESS_MAJOR_FOR_ACCESSIBILITY) });
183169
logger.info(Constants.userMessages.ACCESSIBILITY_CYPRESS_VERSION_PINNED);
184170
}
185-
// Accessibility scans on the affected Cypress 16 versions only complete with forceHttp1.
171+
// Accessibility scans on the Cypress 16 that Rails runs today (16.2.0) only complete with forceHttp1.
186172
if (isAccessibilityOn(bsConfig) && !Utils.isUndefined(runSettings.cypress_version)
187173
&& needsForceHttp1ForAccessibility(runSettings.cypress_version)) {
188174
const config = withForceHttp1(runSettings.config);

‎bin/helpers/constants.js‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ const userMessages = {
8989
ACCESSIBILITY_CYPRESS_VERSION_PINNED:
9090
"Accessibility builds without a cypress_version run on the latest Cypress 15.",
9191
ACCESSIBILITY_FORCE_HTTP1_SET:
92-
"Accessibility on Cypress 16.1.0-16.2.0 needs Cypress's HTTP/1.1 proxy, so this build runs with forceHttp1=true.",
92+
"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.",
9393
CYPRESS_VERSION_CHANGED:
9494
"Your build will run using Cypress <actualVersion> instead of Cypress <preferredVersion>.<frameworkUpgradeMessage> Read more about supported versions here: http://browserstack.com/docs/automate/cypress/supported-versions",
9595
LOCAL_START_FAILED: "Local Testing setup failed.",
@@ -451,14 +451,16 @@ const SPEC_TIMEOUT_LIMIT = 120; // IN MINS
451451

452452
// Newest Cypress major accessibility runs on (APS-22894). Raising this needs no Rails change.
453453
const MAX_CYPRESS_MAJOR_FOR_ACCESSIBILITY = 16;
454-
// Major an accessibility build asks for when it names no cypress_version. Stays on 15 while
455-
// Rails' own default does, so an unpinned build keeps today's Cypress.
454+
// Major an accessibility build asks for when it names no cypress_version. This CLI's choice, not
455+
// Rails': for a CLI that sends cypressExposeSupport, Rails defaults to its newest Cypress (16).
456+
// Kept on 15 so unpinned accessibility builds stay off the Cypress 16 forceHttp1 path.
456457
const DEFAULT_CYPRESS_MAJOR_FOR_ACCESSIBILITY = 15;
457-
// Cypress versions where the a11y extension's service worker never starts, so every scan times
458-
// out unless forceHttp1 is on: [first affected, first fixed). Regression from cypress-io/cypress#34762
459-
// (16.1.0), reported as cypress-io/cypress#35127, fixed by #34958 in 16.2.1.
458+
// Cypress major whose accessibility builds get forceHttp1. On 16.1.0-16.2.0 the a11y extension's
459+
// service worker never starts, so every scan times out unless forceHttp1 is on. Regression from
460+
// cypress-io/cypress#34762 (16.1.0), reported as cypress-io/cypress#35127, fixed by #34958 in 16.2.1.
461+
// Whole major, because Rails runs 16.2.0 for every 16.x request while it is the only 16 it offers.
460462
// SDK-8048 preprod A/B on 16.2.0: scan step 25.6s without forceHttp1, 4.2s with it.
461-
const ACCESSIBILITY_FORCE_HTTP1_CYPRESS_RANGE = ['16.1.0', '16.2.1'];
463+
const ACCESSIBILITY_FORCE_HTTP1_CYPRESS_MAJOR = 16;
462464

463465
const CYPRESS_CUSTOM_ERRORS_TO_PRINT_KEY = "custom_errors_to_print";
464466

@@ -527,7 +529,7 @@ module.exports = Object.freeze({
527529
SPEC_TIMEOUT_LIMIT,
528530
MAX_CYPRESS_MAJOR_FOR_ACCESSIBILITY,
529531
DEFAULT_CYPRESS_MAJOR_FOR_ACCESSIBILITY,
530-
ACCESSIBILITY_FORCE_HTTP1_CYPRESS_RANGE,
532+
ACCESSIBILITY_FORCE_HTTP1_CYPRESS_MAJOR,
531533
CYPRESS_CUSTOM_ERRORS_TO_PRINT_KEY,
532534
CYPRESS_V9_AND_OLDER_TYPE,
533535
CYPRESS_V10_AND_ABOVE_TYPE,

‎test/unit/bin/accessibility-automation/plugin/index.js‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,16 @@ describe('accessibility plugin exposes browser values', () => {
1919
BROWSERSTACK_ACCESSIBILITY_DEBUG: 'true',
2020
};
2121

22+
// The plugin itself sets these, so they are restored too.
23+
const SET_BY_PLUGIN = ['BROWSERSTACK_LOGS', 'BROWSERSTACK_ACCESSIBILITY_PLUGIN_LOADED'];
24+
const RESTORED = Object.keys(ENV).concat(SET_BY_PLUGIN);
25+
2226
beforeEach(() => {
23-
Object.keys(ENV).forEach((k) => { saved[k] = process.env[k]; process.env[k] = ENV[k]; });
27+
RESTORED.forEach((k) => { saved[k] = process.env[k]; });
28+
Object.keys(ENV).forEach((k) => { process.env[k] = ENV[k]; });
2429
});
2530
afterEach(() => {
26-
Object.keys(ENV).forEach((k) => { if (saved[k] === undefined) delete process.env[k]; else process.env[k] = saved[k]; });
31+
RESTORED.forEach((k) => { if (saved[k] === undefined) delete process.env[k]; else process.env[k] = saved[k]; });
2732
});
2833

2934
const run = (config) => {

‎test/unit/bin/helpers/capabilityHelper.js‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ describe("capabilityHelper.js", () => {
141141
});
142142
});
143143

144-
["16", "16.latest", "16.1.0", "16.1.1", "16.2.0"].forEach((version) => {
144+
// Rails runs 16.2.0 for any 16.x it doesn't list, so every Cypress 16 request needs it.
145+
["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) => {
145146
it(`adds forceHttp1=true for accessibility on cypress_version ${version}`, () => {
146147
return sentRunSettings({ accessibility: true, cypress_version: version }).then(({ sent, bsConfig }) => {
147148
chai.assert.equal(sent.config, "forceHttp1=true");
@@ -169,9 +170,7 @@ describe("capabilityHelper.js", () => {
169170
["accessibility on, no version (pinned to 15)", { accessibility: true }],
170171
["accessibility off, Cypress 16", { accessibility: false, cypress_version: "16.2.0" }],
171172
["accessibility on, cypress_version latest", { accessibility: true, cypress_version: "latest" }],
172-
["accessibility on, Cypress 16.2.1 (fixed)", { accessibility: true, cypress_version: "16.2.1" }],
173-
["accessibility on, Cypress 16.3.0 (fixed)", { accessibility: true, cypress_version: "16.3.0" }],
174-
["accessibility on, Cypress 16.0.0 (before the regression)", { accessibility: true, cypress_version: "16.0.0" }],
173+
["accessibility on, Cypress 17", { accessibility: true, cypress_version: "17.0.0" }],
175174
].forEach(([name, runSettings]) => {
176175
it(`does not add forceHttp1 for ${name}`, () => {
177176
return sentRunSettings(runSettings).then(({ sent }) => {

0 commit comments

Comments
 (0)