Skip to content

Commit 4903087

Browse files
committed
patch ats config
1 parent 8ca4324 commit 4903087

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

bin/commands/runs.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const {
3636
checkAccessibilityPlatform,
3737
supportFileCleanup
3838
} = require('../accessibility-automation/helper');
39-
const { isTurboScaleSession, getTurboScaleGridDetails } = require('../helpers/atsHelper');
39+
const { isTurboScaleSession, getTurboScaleGridDetails, patchCypressConfigFileContent, atsFileCleanup } = require('../helpers/atsHelper');
4040

4141
module.exports = function run(args, rawArgs) {
4242

@@ -163,6 +163,8 @@ module.exports = function run(args, rawArgs) {
163163
Constants.turboScaleObj.buildUrl = gridDetails.cypressUrl + '/build';
164164

165165
logger.debug(`Automate TurboScale Grid URL set to ${gridDetails.url}`);
166+
167+
patchCypressConfigFileContent(bsConfig);
166168
} else {
167169
process.exitCode = Constants.ERROR_EXIT_CODE;
168170
return;
@@ -272,6 +274,11 @@ module.exports = function run(args, rawArgs) {
272274
if (process.env.BROWSERSTACK_TEST_ACCESSIBILITY === 'true') {
273275
supportFileCleanup();
274276
}
277+
278+
if (turboScaleSession) {
279+
atsFileCleanup(bsConfig);
280+
}
281+
275282
// Create build
276283
//setup Local Testing
277284
markBlockStart('localSetup');

bin/helpers/atsHelper.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
const path = require('path');
2+
const fs = require('fs')
3+
14
const request = require('request'),
25
logger = require('./logger').winstonLogger,
36
utils = require('./utils'),
@@ -78,3 +81,38 @@ exports.getTurboScaleGridDetails = async (bsConfig, args, rawArgs) => {
7881
logger.error(`Failed to find TurboScale Grid: ${err}: ${err.stack}`);
7982
}
8083
};
84+
85+
exports.patchCypressConfigFileContent = (bsConfig) => {
86+
try {
87+
let cypressConfigFileData = fs.readFileSync(path.resolve(bsConfig.run_settings.cypress_config_file)).toString();
88+
const patchedConfigFileData = cypressConfigFileData + '\n\n' + `
89+
let originalFunction = module.exports.e2e.setupNodeEvents;
90+
91+
module.exports.e2e.setupNodeEvents = (on, config) => {
92+
const bstackOn = require("./cypressPatch.js")(on);
93+
if (originalFunction !== null && originalFunction !== undefined) {
94+
originalFunction(bstackOn, config);
95+
}
96+
}
97+
`
98+
99+
let confPath = bsConfig.run_settings.cypress_config_file;
100+
let patchedConfPathList = confPath.split(path.sep);
101+
patchedConfPathList[patchedConfPathList.length - 1] = 'patched_ats_config_file.js'
102+
const patchedConfPath = patchedConfPathList.join(path.sep);
103+
104+
bsConfig.run_settings.patched_cypress_config_file = patchedConfPath;
105+
106+
fs.writeFileSync(path.resolve(bsConfig.run_settings.patched_cypress_config_file), patchedConfigFileData);
107+
} catch(e) {
108+
logger.error(`Encountered an error when trying to patch ATS Cypress Config File ${e}`);
109+
return {};
110+
}
111+
}
112+
113+
exports.atsFileCleanup = (bsConfig) => {
114+
const filePath = path.resolve(bsConfig.run_settings.patched_cypress_config_file);
115+
if(fs.existsSync(filePath)){
116+
fs.unlinkSync(filePath);
117+
}
118+
}

0 commit comments

Comments
 (0)