Skip to content

Commit 2c429d4

Browse files
committed
Support running on ATS grid
1 parent 0f8cf33 commit 2c429d4

File tree

9 files changed

+111
-4
lines changed

9 files changed

+111
-4
lines changed

bin/commands/runs.js

+20
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const {
3636
checkAccessibilityPlatform,
3737
supportFileCleanup
3838
} = require('../accessibility-automation/helper');
39+
const { isTurboScaleSession, getTurboScaleGridDetails } = require('../helpers/atsHelper');
3940

4041
module.exports = function run(args, rawArgs) {
4142

@@ -66,6 +67,8 @@ module.exports = function run(args, rawArgs) {
6667
const [isTestObservabilitySession, isBrowserstackInfra] = setTestObservabilityFlags(bsConfig);
6768
const checkAccessibility = checkAccessibilityPlatform(bsConfig);
6869
const isAccessibilitySession = bsConfig.run_settings.accessibility || checkAccessibility;
70+
const turboScaleSession = isTurboScaleSession(bsConfig);
71+
Constants.turboScaleObj.enabled = turboScaleSession;
6972

7073
utils.setUsageReportingFlag(bsConfig, args.disableUsageReporting);
7174

@@ -144,6 +147,23 @@ module.exports = function run(args, rawArgs) {
144147
if (isAccessibilitySession && isBrowserstackInfra) {
145148
await createAccessibilityTestRun(bsConfig);
146149
}
150+
151+
if (turboScaleSession) {
152+
const gridDetails = await getTurboScaleGridDetails(bsConfig);
153+
Constants.turboScaleObj.gridDetails = gridDetails;
154+
155+
if (gridDetails.isTrialGrid) {
156+
bsConfig.connection_settings.local = true;
157+
bsConfig.connection_settings.local_inferred = true;
158+
bsConfig.connection_settings.local_mode = 'on-demand';
159+
}
160+
161+
Constants.turboScaleObj.gridUrl = gridDetails.cypressUrl;
162+
Constants.turboScaleObj.uploadUrl = gridDetails.cypressUrl + '/upload';
163+
Constants.turboScaleObj.buildUrl = gridDetails.cypressUrl + '/build';
164+
165+
logger.debug(`Automate TurboScale Grid URL set to ${gridDetails.url}`);
166+
}
147167
}
148168

149169
const { packagesInstalled } = !isBrowserstackInfra ? false : await packageInstaller.packageSetupAndInstaller(bsConfig, config.packageDirName, {markBlockStart, markBlockEnd});

bin/helpers/atsHelper.js

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// TODO: confirm if we need to add command line args. if yes then decide priority
2+
3+
const logger = require("./logger").winstonLogger;
4+
5+
exports.isTurboScaleSession = (bsConfig) => {
6+
// env var will override config
7+
if (process.env.BROWSERSTACK_TURBOSCALE && process.env.BROWSERSTACK_TURBOSCALE === 'true') {
8+
return true;
9+
}
10+
11+
if (bsConfig.run_settings && bsConfig.run_settings.turboScale) {
12+
return true;
13+
}
14+
15+
return false;
16+
};
17+
18+
exports.getTurboScaleOptions = (bsConfig) => {
19+
if (bsConfig.run_settings && bsConfig.run_settings.turboScaleOptions) {
20+
return bsConfig.run_settings.turboScaleOptions;
21+
}
22+
23+
return {};
24+
};
25+
26+
exports.getTurboScaleGridName = (bsConfig) => {
27+
// env var will override config
28+
if (process.env.BROWSERSTACK_TURBOSCALE_GRID_NAME) {
29+
return process.env.BROWSERSTACK_TURBOSCALE_GRID_NAME;
30+
}
31+
32+
if (bsConfig.run_settings && bsConfig.run_settings.turboScaleOptions && bsConfig.run_settings.turboScaleOptions.gridName) {
33+
return bsConfig.run_settings.turboScaleOptions.gridName;
34+
}
35+
36+
return 'NO_GRID_NAME_PASSED';
37+
};
38+
39+
exports.getTurboScaleGridDetails = async (bsConfig) => {
40+
try {
41+
const gridName = this.getTurboScaleGridName(bsConfig);
42+
// TODO: update request making logic
43+
const response = await this.nodeRequest('GET', `${turboScaleConstants.API_ENDPOINT}/grids/${gridName}`, {}, bsConfig);
44+
45+
return JSON.parse(response.data);
46+
} catch (err) {
47+
logger.error(`Failed to find TurboScale Grid: ${err}: ${err.stack}`);
48+
}
49+
};
50+
51+
52+
53+
ATSGridName = getTurboScaleGridName(bsConfig);

bin/helpers/build.js

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ const createBuild = (bsConfig, zip) => {
2323
body: data
2424
}
2525

26+
if (Constants.turboScaleObj.enabled) {
27+
options.url = Constants.turboScaleObj.buildUrl;
28+
}
29+
2630
request.post(options, function (err, resp, body) {
2731
if (err) {
2832
logger.error(utils.formatRequest(err, resp, body));

bin/helpers/checkUploaded.js

+4
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ const checkUploadedMd5 = (bsConfig, args, instrumentBlocks) => {
121121
body: JSON.stringify(data)
122122
};
123123

124+
if (Constants.turboScaleObj.enabled) {
125+
options.url = config.turboScaleMd5Sum;
126+
}
127+
124128
instrumentBlocks.markBlockStart("checkAlreadyUploaded.railsCheck");
125129
request.post(options, function (err, resp, body) {
126130
if (err) {

bin/helpers/config.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ config.packageFileName = "bstackPackages.tar.gz";
2424
config.packageDirName = "tmpBstackPackages";
2525
config.retries = 5;
2626
config.networkErrorExitCode = 2;
27-
config.compiledConfigJsDirName = 'tmpBstackCompiledJs'
28-
config.configJsonFileName = 'tmpCypressConfig.json'
27+
config.compiledConfigJsDirName = 'tmpBstackCompiledJs';
28+
config.configJsonFileName = 'tmpCypressConfig.json';
29+
30+
// turboScale
31+
config.turboScaleMd5Sum = `${config.turboScaleUrl}/md5sumcheck`;
32+
config.turboScaleBuildsUrl = `${config.turboScaleUrl}/builds`;
2933

3034
module.exports = config;

bin/helpers/config.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
"rails_host": "https://api.browserstack.com",
44
"dashboardUrl": "https://automate.browserstack.com/dashboard/v2/builds/",
55
"usageReportingUrl": "https://eds.browserstack.com:443/send_event_cy_internal",
6-
"localTestingListUrl": "https://www.browserstack.com/local/v1/list"
6+
"localTestingListUrl": "https://www.browserstack.com/local/v1/list",
7+
"turboScaleUrl": "https://grid.browserstack.com/packages/cypress"
78
}

bin/helpers/constants.js

+3
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,8 @@ const CYPRESS_CONFIG_FILE_NAMES = Object.keys(CYPRESS_CONFIG_FILE_MAPPING);
437437

438438
const CYPRESS_V10_AND_ABOVE_CONFIG_FILE_EXTENSIONS = ['js', 'ts', 'cjs', 'mjs']
439439

440+
const turboScaleObj = {};
441+
440442
module.exports = Object.freeze({
441443
syncCLI,
442444
userMessages,
@@ -449,6 +451,7 @@ module.exports = Object.freeze({
449451
hashingOptions,
450452
packageInstallerOptions,
451453
specFileTypes,
454+
turboScaleObj,
452455
DEFAULT_CYPRESS_SPEC_PATH,
453456
DEFAULT_CYPRESS_10_SPEC_PATH,
454457
SPEC_TOTAL_CHAR_LIMIT,

bin/helpers/sync/syncSpecsLogs.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ let lineSeparator = Constants.syncCLI.DEFAULT_LINE_SEP;
2525
if (!isNaN(terminalWidth)) lineSeparator = "\n" + "-".repeat(terminalWidth);
2626

2727
let getOptions = (auth, build_id) => {
28-
return {
28+
const options = {
2929
url: `${config.buildUrlV2}${build_id}`,
3030
auth: {
3131
user: auth.username,
@@ -37,6 +37,12 @@ let getOptions = (auth, build_id) => {
3737
"User-Agent": utils.getUserAgent()
3838
}
3939
};
40+
41+
if (Constants.turboScaleObj.enabled) {
42+
options.url = `${config.turboScaleBuildsUrl}/${build_id}`;
43+
}
44+
45+
return options;
4046
}
4147

4248
let getTableConfig = (termWidth) => {

bin/helpers/utils.js

+12
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,11 @@ exports.generateUploadParams = (bsConfig, filePath, md5data, fileDetails) => {
718718
"User-Agent": exports.getUserAgent(),
719719
}
720720
}
721+
722+
if (Constants.turboScaleObj.enabled) {
723+
options.url = Constants.turboScaleObj.uploadUrl;
724+
}
725+
721726
return options
722727
}
723728

@@ -965,6 +970,13 @@ exports.setLocalArgs = (bsConfig, args) => {
965970
local_args['proxyPort'] = bsConfig["connection_settings"]["proxyPort"];
966971
if (bsConfig["connection_settings"]["useCaCertificate"])
967972
local_args['useCaCertificate'] = bsConfig["connection_settings"]["useCaCertificate"];
973+
974+
if (Constants.turboScaleObj.enabled) {
975+
local_args['forceLocal'] = true;
976+
local_args['localIdentifier'] = 'ats-repeater';
977+
local_args['custom-repeater'] = Constants.turboScaleObj.gridDetails.customRepeaters.join(',');
978+
}
979+
968980
local_args['daemon'] = true;
969981
local_args['enable-logging-for-api'] = true
970982
local_args['source'] = `cypress:${usageReporting.cli_version_and_path(bsConfig).version}`;

0 commit comments

Comments
 (0)