Skip to content

Commit ee19496

Browse files
Merge pull request #1222 from browserstack/SDK-8048-a11y-cypress16-forcehttp1
SDK-8048: run accessibility on Cypress 16.1.0-16.2.0 with forceHttp1 (stacked on #1206)
2 parents a40ac2c + 0cafced commit ee19496

3 files changed

Lines changed: 109 additions & 12 deletions

File tree

‎bin/helpers/capabilityHelper.js‎

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,44 @@ 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+
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+
};
44+
45+
// Adds forceHttp1=true to the run's Cypress config unless the user already set forceHttp1
46+
// (either way), keeping every other key they passed.
47+
const withForceHttp1 = (config) => {
48+
const current = Utils.isUndefined(config) ? '' : String(config).trim();
49+
if (/(^|,)\s*forceHttp1\s*=/.test(current)) return config;
50+
return current ? `${current},forceHttp1=true` : 'forceHttp1=true';
1651
};
1752

1853
const caps = (bsConfig, zip) => {
@@ -144,9 +179,18 @@ const caps = (bsConfig, zip) => {
144179
// Rails defaults to its newest Cypress, which accessibility does not support yet, so an
145180
// accessibility build without a version asks for the newest major accessibility supports.
146181
if (isAccessibilityOn(bsConfig) && Utils.isUndefined(runSettings.cypress_version)) {
147-
runSettings = Object.assign({}, runSettings, { cypress_version: String(Constants.MAX_CYPRESS_MAJOR_FOR_ACCESSIBILITY) });
182+
runSettings = Object.assign({}, runSettings, { cypress_version: String(Constants.DEFAULT_CYPRESS_MAJOR_FOR_ACCESSIBILITY) });
148183
logger.info(Constants.userMessages.ACCESSIBILITY_CYPRESS_VERSION_PINNED);
149184
}
185+
// Accessibility scans on the affected Cypress 16 versions only complete with forceHttp1.
186+
if (isAccessibilityOn(bsConfig) && !Utils.isUndefined(runSettings.cypress_version)
187+
&& needsForceHttp1ForAccessibility(runSettings.cypress_version)) {
188+
const config = withForceHttp1(runSettings.config);
189+
if (config !== runSettings.config) {
190+
runSettings = Object.assign({}, runSettings, { config });
191+
logger.info(Constants.userMessages.ACCESSIBILITY_FORCE_HTTP1_SET);
192+
}
193+
}
150194
obj.run_settings = JSON.stringify(runSettings);
151195
}
152196

‎bin/helpers/constants.js‎

Lines changed: 16 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.1.0-16.2.0 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,16 @@ 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+
// 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.
460+
// 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'];
452462

453463
const CYPRESS_CUSTOM_ERRORS_TO_PRINT_KEY = "custom_errors_to_print";
454464

@@ -516,6 +526,8 @@ module.exports = Object.freeze({
516526
BUILD_FAILED_EXIT_CODE,
517527
SPEC_TIMEOUT_LIMIT,
518528
MAX_CYPRESS_MAJOR_FOR_ACCESSIBILITY,
529+
DEFAULT_CYPRESS_MAJOR_FOR_ACCESSIBILITY,
530+
ACCESSIBILITY_FORCE_HTTP1_CYPRESS_RANGE,
519531
CYPRESS_CUSTOM_ERRORS_TO_PRINT_KEY,
520532
CYPRESS_V9_AND_OLDER_TYPE,
521533
CYPRESS_V10_AND_ABOVE_TYPE,

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

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,45 @@ describe("capabilityHelper.js", () => {
140140
chai.assert.isUndefined(sent.cypress_version);
141141
});
142142
});
143+
144+
["16", "16.latest", "16.1.0", "16.1.1", "16.2.0"].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+
["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" }],
175+
].forEach(([name, runSettings]) => {
176+
it(`does not add forceHttp1 for ${name}`, () => {
177+
return sentRunSettings(runSettings).then(({ sent }) => {
178+
chai.assert.isUndefined(sent.config);
179+
});
180+
});
181+
});
143182
});
144183

145184
it("handle empty test_suite", () => {
@@ -808,26 +847,28 @@ describe("capabilityHelper.js", () => {
808847
else process.env.BROWSERSTACK_TEST_ACCESSIBILITY = savedA11yEnv;
809848
});
810849

811-
["16", "16.2.0", "16.latest", 17].forEach((version) => {
850+
["17", "17.0.0", "17.latest", 18].forEach((version) => {
812851
it(`rejects cypress_version ${version} with accessibility on`, () => {
813852
return validateError(a11yConfig({ accessibility: true, cypress_version: version })).then((error) => {
814853
chai.assert.equal(error, Constants.validationMessages.ACCESSIBILITY_CYPRESS_VERSION_UNSUPPORTED);
815854
});
816855
});
817856
});
818857

819-
it("rejects cypress_version 16 when accessibility is on through BROWSERSTACK_TEST_ACCESSIBILITY", () => {
858+
it("rejects cypress_version 17 when accessibility is on through BROWSERSTACK_TEST_ACCESSIBILITY", () => {
820859
process.env.BROWSERSTACK_TEST_ACCESSIBILITY = 'true';
821-
return validateError(a11yConfig({ cypress_version: "16" })).then((error) => {
860+
return validateError(a11yConfig({ cypress_version: "17" })).then((error) => {
822861
chai.assert.equal(error, Constants.validationMessages.ACCESSIBILITY_CYPRESS_VERSION_UNSUPPORTED);
823862
});
824863
});
825864

826865
[
827866
["cypress_version 15 with accessibility on", { accessibility: true, cypress_version: "15" }],
867+
["cypress_version 16 with accessibility on", { accessibility: true, cypress_version: "16" }],
868+
["cypress_version 16.2.0 with accessibility on", { accessibility: true, cypress_version: "16.2.0" }],
828869
["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" }],
870+
["cypress_version 17 with accessibility off", { accessibility: false, cypress_version: "17" }],
871+
["cypress_version 17 without accessibility", { cypress_version: "17" }],
831872
].forEach(([name, runSettings]) => {
832873
it(`does not reject ${name} for accessibility`, () => {
833874
return validateError(a11yConfig(runSettings)).then((error) => {

0 commit comments

Comments
 (0)