|
| 1 | +const path = require('path'); |
| 2 | +const fs = require('fs') |
| 3 | + |
1 | 4 | const request = require('request'),
|
2 | 5 | logger = require('./logger').winstonLogger,
|
3 | 6 | utils = require('./utils'),
|
@@ -78,3 +81,38 @@ exports.getTurboScaleGridDetails = async (bsConfig, args, rawArgs) => {
|
78 | 81 | logger.error(`Failed to find TurboScale Grid: ${err}: ${err.stack}`);
|
79 | 82 | }
|
80 | 83 | };
|
| 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