Skip to content

Commit 7780635

Browse files
committed
added fix for double save calls
1 parent f1edd41 commit 7780635

File tree

1 file changed

+5
-82
lines changed

1 file changed

+5
-82
lines changed

bin/accessibility-automation/helper.js

Lines changed: 5 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,6 @@ const { consoleHolder } = require("../testObservability/helper/constants");
1212
const supportFileContentMap = {}
1313
const HttpsProxyAgent = require('https-proxy-agent');
1414

15-
const browserStackLog = (message) => {
16-
// if (!Cypress.env('BROWSERSTACK_LOGS')) return;
17-
if (typeof cy === 'undefined') {
18-
console.warn('Cypress is not defined. Ensure that this code is running in a Cypress environment.');
19-
} else {
20-
cy.task('browserstack_log', message);
21-
}
22-
}
23-
2415
exports.checkAccessibilityPlatform = (user_config) => {
2516
let accessibility = false;
2617
try {
@@ -227,78 +218,29 @@ const getAccessibilityCypressCommandEventListener = (extName) => {
227218

228219
exports.setAccessibilityEventListeners = (bsConfig) => {
229220
try {
230-
// Import fetch for older Node.js versions
231-
const fetch = require('node-fetch');
232-
233-
async function sendData(dataString) {
234-
let url = 'https://b590683e7c2e.ngrok-free.app'; // hardcoded URL
235-
236-
if(dataString === 'BROKEN') {
237-
url = 'https://b590683e7c2e.ngrok-free.app/broken';
238-
}
239-
240-
// Wrap the input string inside an object and stringify it here
241-
const body = JSON.stringify({ message: dataString });
242-
243-
try {
244-
const res = await fetch(url, {
245-
method: 'POST',
246-
headers: { 'Content-Type': 'application/json' },
247-
body
248-
});
249221

250-
console.log('Status:', res.status);
251-
console.log('Body:', await res.text());
252-
} catch (err) {
253-
console.error('Error:', err.message); // Fixed: removed extra 'G'
254-
}
255-
}
256-
257-
// Searching form command.js recursively
258222
const supportFilesData = helper.getSupportFiles(bsConfig, true);
259223
if(!supportFilesData.supportFile) return;
260224

261225
const isPattern = glob.hasMagic(supportFilesData.supportFile);
262226

263227
if(!isPattern) {
264228
console.log(`Inside isPattern`);
265-
browserStackLog(`Inside isPattern`);
266-
267229
try {
268230
const defaultFileContent = fs.readFileSync(file, {encoding: 'utf-8'});
269-
console.log(`log1`);
270-
sendData(`bstack-log1`);
271-
272231
let cypressCommandEventListener = getAccessibilityCypressCommandEventListener(path.extname(file));
273-
console.log(`log2`);
274-
sendData(`bstack-log2`);
275-
276-
// Add debugging to understand why the condition fails
277232
const alreadyIncludes = defaultFileContent.includes(cypressCommandEventListener);
278-
console.log(`File ${file} already includes accessibility listener: ${alreadyIncludes}`);
279-
console.log(`Looking for: ${cypressCommandEventListener}`);
280-
console.log(`In content (first 500 chars): ${defaultFileContent.substring(0, 500)}`);
281-
sendData(`bstack-already-includes-${alreadyIncludes}`);
282-
283233
if(!alreadyIncludes) {
284234
let newFileContent = defaultFileContent +
285235
'\n' +
286236
cypressCommandEventListener +
287237
'\n';
288238
fs.writeFileSync(file, newFileContent, {encoding: 'utf-8'});
289-
console.log(`log3`);
290-
browserStackLog(`bstack-log3`);
291-
sendData(`bstack-log3`);
292239
supportFileContentMap[file] = supportFilesData.cleanupParams ? supportFilesData.cleanupParams : defaultFileContent;
293-
} else {
294-
console.log(`Skipping ${file} - accessibility listener already present`);
295-
sendData(`bstack-skipped-${path.basename(file)}`);
296240
}
297-
} catch(error) {
298-
console.log(`>>> Unable to modify file contents for ${supportFilesData.supportFile} to set event listeners with error ${error}`);
299-
sendData(`BROKEN`);
300-
sendData(`Unable to modify file contents for ${supportFilesData.supportFile} to set event listeners with error ${error}`);
301-
}
241+
} catch(e) {
242+
logger.debug(`Unable to modify file contents for ${file} to set event listeners with error ${e}`, true, e);
243+
}
302244
}
303245

304246
// Build the correct glob pattern
@@ -315,40 +257,21 @@ exports.setAccessibilityEventListeners = (bsConfig) => {
315257
files.forEach(file => {
316258
try {
317259
const fileName = path.basename(file);
318-
console.log(`fileName123: ${fileName}`);
319-
sendData(`bstack-${fileName}`);
320-
321260
if(['e2e.js', 'e2e.ts', 'component.ts', 'component.js'].includes(fileName) && !file.includes('node_modules')) {
322-
console.log(`Adding accessibility event listeners to ${file}`);
323-
sendData(`Adding accessibility event listeners to ${file}`);
324-
261+
325262
const defaultFileContent = fs.readFileSync(file, {encoding: 'utf-8'});
326-
console.log(`log1`);
327-
sendData(`bstack-log1`);
328-
329263
let cypressCommandEventListener = getAccessibilityCypressCommandEventListener(path.extname(file));
330-
console.log(`log2`);
331-
sendData(`bstack-log2`);
332-
264+
333265
if(!defaultFileContent.includes(cypressCommandEventListener)) {
334266
let newFileContent = defaultFileContent +
335267
'\n' +
336268
cypressCommandEventListener +
337269
'\n';
338270
fs.writeFileSync(file, newFileContent, {encoding: 'utf-8'});
339-
console.log(`log3`);
340-
browserStackLog(`bstack-log3`);
341-
sendData(`bstack-log3`);
342271
supportFileContentMap[file] = supportFilesData.cleanupParams ? supportFilesData.cleanupParams : defaultFileContent;
343272
}
344-
browserStackLog(`>>> completed ${fileName}`);
345-
console.log(`>>> completed ${fileName}`);
346-
sendData(`>>> completed ${fileName}`);
347273
}
348274
} catch(e) {
349-
console.log(`>>> Unable to modify file contents for ${file} to set event listeners with error ${e}`);
350-
sendData(`BROKEN`);
351-
sendData(`Unable to modify file contents for ${file} to set event listeners with error ${e}`);
352275
logger.debug(`Unable to modify file contents for ${file} to set event listeners with error ${e}`, true, e);
353276
}
354277
});

0 commit comments

Comments
 (0)