Skip to content

Commit faff373

Browse files
SDK-8048: run accessibility on Cypress 16 with forceHttp1
Cypress 16.2.0's default network mode never starts the a11y extension's service worker (cypress-io/cypress#35127, fixed in 16.2.1), so every scan waits out the 25s timeout and the build still passes. forceHttp1 avoids it: on the same preprod Ventura pool, the scan step took 25.6s without it and 4.2s with it (15.21.1: 5.0s). - Accessibility builds on Cypress 16 get forceHttp1=true added to run_settings.config. Other config keys are kept, and a forceHttp1 the user already set (true or false) is left alone. - MAX_CYPRESS_MAJOR_FOR_ACCESSIBILITY 15 -> 16, so 16 is allowed and 17+ is still refused. - Builds with no cypress_version still ask for 15 (DEFAULT_CYPRESS_MAJOR_FOR_ACCESSIBILITY), matching Rails' default. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent a40ac2c commit faff373

3 files changed

Lines changed: 84 additions & 12 deletions

File tree

‎bin/helpers/capabilityHelper.js‎

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,22 @@ const logger = require("./logger").winstonLogger,
1010
const isAccessibilityOn = (bsConfig) =>
1111
process.env.BROWSERSTACK_TEST_ACCESSIBILITY === 'true' || String(bsConfig.run_settings.accessibility) === 'true';
1212

13-
const isAboveAccessibilityCypressMajor = (cypressVersion) => {
13+
const cypressMajor = (cypressVersion) => {
1414
const major = String(cypressVersion).match(/^(\d+)/);
15-
return !!major && Number(major[1]) > Constants.MAX_CYPRESS_MAJOR_FOR_ACCESSIBILITY;
15+
return major ? Number(major[1]) : undefined;
16+
};
17+
18+
const isAboveAccessibilityCypressMajor = (cypressVersion) => {
19+
const major = cypressMajor(cypressVersion);
20+
return major !== undefined && major > Constants.MAX_CYPRESS_MAJOR_FOR_ACCESSIBILITY;
21+
};
22+
23+
// Adds forceHttp1=true to the run's Cypress config unless the user already set forceHttp1
24+
// (either way), keeping every other key they passed.
25+
const withForceHttp1 = (config) => {
26+
const current = Utils.isUndefined(config) ? '' : String(config).trim();
27+
if (/(^|,)\s*forceHttp1\s*=/.test(current)) return config;
28+
return current ? `${current},forceHttp1=true` : 'forceHttp1=true';
1629
};
1730

1831
const caps = (bsConfig, zip) => {
@@ -144,9 +157,19 @@ const caps = (bsConfig, zip) => {
144157
// Rails defaults to its newest Cypress, which accessibility does not support yet, so an
145158
// accessibility build without a version asks for the newest major accessibility supports.
146159
if (isAccessibilityOn(bsConfig) && Utils.isUndefined(runSettings.cypress_version)) {
147-
runSettings = Object.assign({}, runSettings, { cypress_version: String(Constants.MAX_CYPRESS_MAJOR_FOR_ACCESSIBILITY) });
160+
runSettings = Object.assign({}, runSettings, { cypress_version: String(Constants.DEFAULT_CYPRESS_MAJOR_FOR_ACCESSIBILITY) });
148161
logger.info(Constants.userMessages.ACCESSIBILITY_CYPRESS_VERSION_PINNED);
149162
}
163+
// Accessibility scans on Cypress 16 only complete with forceHttp1 (see the constant).
164+
const requestedMajor = cypressMajor(runSettings.cypress_version);
165+
if (isAccessibilityOn(bsConfig) && requestedMajor !== undefined
166+
&& requestedMajor >= Constants.MIN_CYPRESS_MAJOR_NEEDING_FORCE_HTTP1_FOR_ACCESSIBILITY) {
167+
const config = withForceHttp1(runSettings.config);
168+
if (config !== runSettings.config) {
169+
runSettings = Object.assign({}, runSettings, { config });
170+
logger.info(Constants.userMessages.ACCESSIBILITY_FORCE_HTTP1_SET);
171+
}
172+
}
150173
obj.run_settings = JSON.stringify(runSettings);
151174
}
152175

‎bin/helpers/constants.js‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ const userMessages = {
8787
RETRY_LIMIT_EXCEEDED: `Max retries exceeded trying to connect to the host (retries: ${config.retries})`,
8888
CHECK_DASHBOARD_AT: "Please check the build status at: ",
8989
ACCESSIBILITY_CYPRESS_VERSION_PINNED:
90-
"Accessibility Testing supports Cypress up to version 15, so this build runs on the latest Cypress 15.",
90+
"Accessibility builds without a cypress_version run on the latest Cypress 15.",
91+
ACCESSIBILITY_FORCE_HTTP1_SET:
92+
"Accessibility on Cypress 16 needs Cypress's HTTP/1.1 proxy, so this build runs with forceHttp1=true.",
9193
CYPRESS_VERSION_CHANGED:
9294
"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",
9395
LOCAL_START_FAILED: "Local Testing setup failed.",
@@ -201,7 +203,7 @@ const validationMessages = {
201203
NODE_VERSION_PARSING_ERROR:
202204
"We weren't able to successfully parse the specified nodeVersion. We will be using the default nodeVersion to run your tests.",
203205
ACCESSIBILITY_CYPRESS_VERSION_UNSUPPORTED:
204-
"Accessibility Testing supports Cypress up to version 15. Set cypress_version to 15 in browserstack.json, or turn off accessibility to run Cypress 16 or later.",
206+
"Accessibility Testing supports Cypress up to version 16. Set cypress_version to 16 or lower in browserstack.json, or turn off accessibility to run a later Cypress.",
205207
AUTO_IMPORT_CONFLICT_ERROR:
206208
"Cannot use both 'auto_import_dev_dependencies' and manual npm dependency configuration. Please either set 'auto_import_dev_dependencies' to false or remove manual 'npm_dependencies', 'win_npm_dependencies', and 'mac_npm_dependencies' configurations.",
207209
AUTO_IMPORT_INVALID_TYPE:
@@ -447,8 +449,15 @@ const REDACTED_AUTH = `auth: { "username": ${REDACTED}, "access_key": ${REDACTED
447449

448450
const SPEC_TIMEOUT_LIMIT = 120; // IN MINS
449451

450-
// Accessibility does not support Cypress 16 yet (APS-22894). Raising this needs no Rails change.
451-
const MAX_CYPRESS_MAJOR_FOR_ACCESSIBILITY = 15;
452+
// Newest Cypress major accessibility runs on (APS-22894). Raising this needs no Rails change.
453+
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.
456+
const DEFAULT_CYPRESS_MAJOR_FOR_ACCESSIBILITY = 15;
457+
// From this major the a11y extension's service worker never starts in Cypress's default network
458+
// mode (cypress-io/cypress#35127, fixed in 16.2.1), so scans time out unless forceHttp1 is on.
459+
// SDK-8048 preprod A/B on 16.2.0: scan step 25.6s without it, 4.2s with it.
460+
const MIN_CYPRESS_MAJOR_NEEDING_FORCE_HTTP1_FOR_ACCESSIBILITY = 16;
452461

453462
const CYPRESS_CUSTOM_ERRORS_TO_PRINT_KEY = "custom_errors_to_print";
454463

@@ -516,6 +525,8 @@ module.exports = Object.freeze({
516525
BUILD_FAILED_EXIT_CODE,
517526
SPEC_TIMEOUT_LIMIT,
518527
MAX_CYPRESS_MAJOR_FOR_ACCESSIBILITY,
528+
DEFAULT_CYPRESS_MAJOR_FOR_ACCESSIBILITY,
529+
MIN_CYPRESS_MAJOR_NEEDING_FORCE_HTTP1_FOR_ACCESSIBILITY,
519530
CYPRESS_CUSTOM_ERRORS_TO_PRINT_KEY,
520531
CYPRESS_V9_AND_OLDER_TYPE,
521532
CYPRESS_V10_AND_ABOVE_TYPE,

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

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,42 @@ describe("capabilityHelper.js", () => {
140140
chai.assert.isUndefined(sent.cypress_version);
141141
});
142142
});
143+
144+
["16", "16.2.0", "16.latest"].forEach((version) => {
145+
it(`adds forceHttp1=true for accessibility on cypress_version ${version}`, () => {
146+
return sentRunSettings({ accessibility: true, cypress_version: version }).then(({ sent, bsConfig }) => {
147+
chai.assert.equal(sent.config, "forceHttp1=true");
148+
chai.assert.isUndefined(bsConfig.run_settings.config);
149+
});
150+
});
151+
});
152+
153+
it("keeps the user's other config keys when adding forceHttp1", () => {
154+
return sentRunSettings({ accessibility: true, cypress_version: "16.2.0", config: "video=false,baseUrl=https://x.test" }).then(({ sent }) => {
155+
chai.assert.equal(sent.config, "video=false,baseUrl=https://x.test,forceHttp1=true");
156+
});
157+
});
158+
159+
["forceHttp1=false", "video=true, forceHttp1 = false"].forEach((config) => {
160+
it(`does not override a forceHttp1 the user set (${config})`, () => {
161+
return sentRunSettings({ accessibility: true, cypress_version: "16", config }).then(({ sent }) => {
162+
chai.assert.equal(sent.config, config);
163+
});
164+
});
165+
});
166+
167+
[
168+
["accessibility on, Cypress 15", { accessibility: true, cypress_version: "15.21.1" }],
169+
["accessibility on, no version (pinned to 15)", { accessibility: true }],
170+
["accessibility off, Cypress 16", { accessibility: false, cypress_version: "16.2.0" }],
171+
["accessibility on, cypress_version latest", { accessibility: true, cypress_version: "latest" }],
172+
].forEach(([name, runSettings]) => {
173+
it(`does not add forceHttp1 for ${name}`, () => {
174+
return sentRunSettings(runSettings).then(({ sent }) => {
175+
chai.assert.isUndefined(sent.config);
176+
});
177+
});
178+
});
143179
});
144180

145181
it("handle empty test_suite", () => {
@@ -808,26 +844,28 @@ describe("capabilityHelper.js", () => {
808844
else process.env.BROWSERSTACK_TEST_ACCESSIBILITY = savedA11yEnv;
809845
});
810846

811-
["16", "16.2.0", "16.latest", 17].forEach((version) => {
847+
["17", "17.0.0", "17.latest", 18].forEach((version) => {
812848
it(`rejects cypress_version ${version} with accessibility on`, () => {
813849
return validateError(a11yConfig({ accessibility: true, cypress_version: version })).then((error) => {
814850
chai.assert.equal(error, Constants.validationMessages.ACCESSIBILITY_CYPRESS_VERSION_UNSUPPORTED);
815851
});
816852
});
817853
});
818854

819-
it("rejects cypress_version 16 when accessibility is on through BROWSERSTACK_TEST_ACCESSIBILITY", () => {
855+
it("rejects cypress_version 17 when accessibility is on through BROWSERSTACK_TEST_ACCESSIBILITY", () => {
820856
process.env.BROWSERSTACK_TEST_ACCESSIBILITY = 'true';
821-
return validateError(a11yConfig({ cypress_version: "16" })).then((error) => {
857+
return validateError(a11yConfig({ cypress_version: "17" })).then((error) => {
822858
chai.assert.equal(error, Constants.validationMessages.ACCESSIBILITY_CYPRESS_VERSION_UNSUPPORTED);
823859
});
824860
});
825861

826862
[
827863
["cypress_version 15 with accessibility on", { accessibility: true, cypress_version: "15" }],
864+
["cypress_version 16 with accessibility on", { accessibility: true, cypress_version: "16" }],
865+
["cypress_version 16.2.0 with accessibility on", { accessibility: true, cypress_version: "16.2.0" }],
828866
["no cypress_version with accessibility on", { accessibility: "true" }],
829-
["cypress_version 16 with accessibility off", { accessibility: false, cypress_version: "16" }],
830-
["cypress_version 16 without accessibility", { cypress_version: "16" }],
867+
["cypress_version 17 with accessibility off", { accessibility: false, cypress_version: "17" }],
868+
["cypress_version 17 without accessibility", { cypress_version: "17" }],
831869
].forEach(([name, runSettings]) => {
832870
it(`does not reject ${name} for accessibility`, () => {
833871
return validateError(a11yConfig(runSettings)).then((error) => {

0 commit comments

Comments
 (0)