Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion bin/commands/runs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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('<cypressMajor>', 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);

Expand Down
8 changes: 8 additions & 0 deletions bin/helpers/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <cypressMajor>. 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.",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
});
14 changes: 14 additions & 0 deletions bin/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
25 changes: 25 additions & 0 deletions test/unit/bin/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <major>.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;
});
});

});
Loading