Skip to content

Commit 2a8d643

Browse files
authored
Merge pull request #350 from HRanjan-11/CBT-19919
Release 3 march
2 parents a82c4ae + afa3968 commit 2a8d643

File tree

4 files changed

+89
-124
lines changed

4 files changed

+89
-124
lines changed

accessibility/plugin/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ const Accessibility = (on, config) => {
1616
fs.writeFileSync(filePath, '[]');
1717
}
1818
return filePath;
19+
},
20+
readFileIfExists(filePath) {
21+
const fullPath = path.resolve(filePath);
22+
if (fs.existsSync(fullPath)) {
23+
const fileContent = fs.readFileSync(fullPath, 'utf8');
24+
return { exists: true, content:fileContent };
25+
} else {
26+
return { exists: false, content: null }; // Return null if the file doesn't exist
27+
}
1928
}
2029
})
2130

accessibility/scanner/index.js

Lines changed: 77 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,74 @@ const getScanData = (win, payload) =>
6565

6666
})
6767

68+
function processAccessibilityReport(win){
69+
let wcagCriteriaValue = Cypress.env("WCAG_CRITERIA") || "wcag21a";
70+
let bestPracticeValue = Cypress.env("BEST_PRACTICE") || false;
71+
let needsReviewValue = Cypress.env("NEEDS_REVIEW") || true;
72+
bestPracticeValue = bestPracticeValue == "true" ? true : false;
73+
needsReviewValue = needsReviewValue == "true" ? true : false;
74+
const payloadToSend = {
75+
message: 'SET_CONFIG',
76+
wcagCriteria: wcagCriteriaValue,
77+
bestPractice: bestPracticeValue,
78+
needsReview: needsReviewValue
79+
}
80+
81+
console.log('log', "payload to send " + payloadToSend);
82+
let testId = Cypress.env("TEST_ID") || ""
83+
84+
const filePath = Cypress.env("ACCESSIBILITY_REPORT_PATH") || 'cypress/results/accessibilityReport_' + testId + '.json';
85+
86+
cy.wrap(setScanConfig(win, payloadToSend), {timeout: 30000}).then((res) => {
87+
console.log('logging config reponse', res);
88+
89+
const payload = {
90+
message: 'GET_LATEST_SCAN_DATA',
91+
}
92+
93+
cy.wrap(getScanData(win, payload), {timeout: 45000}).then((res) => {
94+
LambdatestLog('log', "scanning data ");
95+
96+
97+
cy.task('initializeFile', filePath).then((filePath) => {
98+
cy.task('readFileIfExists', filePath,{ log: true, timeout: 45000 }).then((result) => {
99+
let resultsArray = [{}];
100+
console.log('logging report', res);
101+
// If the file is not empty, parse the existing content
102+
if (result.exists && result.content) {
103+
try {
104+
resultsArray = JSON.parse(result.content);
105+
} catch (e) {
106+
console.log("parsing error for content " , result.content)
107+
console.log('Error parsing JSON file:', e);
108+
return;
109+
}
110+
} else if(!result.exists) {
111+
console.log('accessibility file does not exist');
112+
}
113+
if (res) {
114+
console.log('scanned data recieved is', res.message);
115+
}
116+
117+
if (res && res.message == "GET_LATEST_SCAN_DATA") {
118+
try {
119+
// Append the new result
120+
resultsArray.push(res);
121+
console.log('resultsarray logging', resultsArray);
122+
} catch (e) {
123+
console.log('Error pushing issues to array:', e);
124+
}
125+
}
126+
127+
// Write the updated content back to the file
128+
cy.writeFile(filePath, resultsArray, { log: true, timeout: 45000 });
129+
});
130+
});
131+
});
132+
133+
});
134+
}
135+
68136
Cypress.on('command:start', async (command) => {
69137
if(!command || !command.attributes) return;
70138
if(command.attributes.name == 'window' || command.attributes.name == 'then' || command.attributes.name == 'wrap' || command.attributes.name == 'wait') {
@@ -80,63 +148,9 @@ Cypress.on('command:start', async (command) => {
80148

81149

82150
console.log('log', "debugging scan form command " + command.attributes.name);
83-
cy.window().then((win) => {
84-
let wcagCriteriaValue = Cypress.env("WCAG_CRITERIA") || "wcag21a";
85-
let bestPracticeValue = Cypress.env("BEST_PRACTICE") || false;
86-
let needsReviewValue = Cypress.env("NEEDS_REVIEW") || true;
87-
bestPracticeValue = bestPracticeValue == "true" ? true : false;
88-
needsReviewValue = needsReviewValue == "true" ? true : false;
89-
const payloadToSend = {
90-
message: 'SET_CONFIG',
91-
wcagCriteria: wcagCriteriaValue,
92-
bestPractice: bestPracticeValue,
93-
needsReview: needsReviewValue
94-
}
95-
96-
console.log('log', "payload to send " + payloadToSend);
97-
let testId = Cypress.env("TEST_ID") || ""
98-
99-
const filePath = Cypress.env("ACCESSIBILITY_REPORT_PATH") || 'cypress/results/accessibilityReport_' + testId + '.json';
100-
101-
cy.wrap(setScanConfig(win, payloadToSend), {timeout: 30000}).then((res) => {
102-
console.log('logging config reponse', res);
103-
104-
const payload = {
105-
message: 'GET_LATEST_SCAN_DATA',
106-
}
107-
108-
cy.wrap(getScanData(win, payload), {timeout: 45000}).then((res) => {
109-
LambdatestLog('log', "scanning data ");
110-
111-
112-
cy.task('initializeFile', filePath).then((filePath) => {
113-
cy.readFile(filePath, { log: true, timeout: 45000 }).then((fileContent) => {
114-
let resultsArray = [{}];
115-
console.log('logging report', res);
116-
// If the file is not empty, parse the existing content
117-
if (fileContent) {
118-
try {
119-
resultsArray = JSON.parse(JSON.stringify(fileContent));
120-
} catch (e) {
121-
console.log("parsing error for content " , fileContent)
122-
console.log('Error parsing JSON file:', e);
123-
return;
124-
}
125-
}
126-
console.log('scanned data recieved is', res.message);
127-
if (res.message == "GET_LATEST_SCAN_DATA") {
128-
// Append the new result
129-
resultsArray.push(res);
130-
console.log('resultsarray logging', resultsArray);
131-
}
132-
133-
// Write the updated content back to the file
134-
cy.writeFile(filePath, resultsArray, { log: true, timeout: 45000 });
135-
});
136-
});
137-
});
138151

139-
});
152+
cy.window().then((win) => {
153+
processAccessibilityReport(win);
140154
})
141155
})
142156

@@ -149,72 +163,14 @@ return;
149163

150164
afterEach(() => {
151165
console.log("after each hook")
166+
let isAccessibilityLoaded = Cypress.env("ACCESSIBILITY") || false;
167+
if (!isAccessibilityLoaded){
168+
console.log('log', "accessibility not enabled " + isAccessibilityLoaded);
169+
return;
170+
}
152171
cy.window().then((win) => {
153-
let wcagCriteriaValue = Cypress.env("WCAG_CRITERIA") || "wcag21a";
154-
let bestPracticeValue = Cypress.env("BEST_PRACTICE") || false;
155-
let needsReviewValue = Cypress.env("NEEDS_REVIEW") || false;
156-
157-
bestPracticeValue = bestPracticeValue == "true" ? true : false;
158-
needsReviewValue = needsReviewValue == "true" ? true : false;
159-
160-
let isAccessibilityLoaded = Cypress.env("ACCESSIBILITY") || false;
161-
if (!isAccessibilityLoaded){
162-
console.log('log', "accessibility not enabled " + isAccessibilityLoaded);
163-
return;
164-
}
165-
166-
const payloadToSend = {
167-
message: 'SET_CONFIG',
168-
wcagCriteria: wcagCriteriaValue,
169-
bestPractice: bestPracticeValue,
170-
needsReview: needsReviewValue
171-
}
172-
173-
console.log('log', "payload to send " + payloadToSend);
174-
let testId = Cypress.env("TEST_ID") || ""
175-
176-
const filePath = Cypress.env("ACCESSIBILITY_REPORT_PATH") || 'cypress/results/accessibilityReport_' + testId + '.json';
177-
178-
cy.wrap(setScanConfig(win, payloadToSend), {timeout: 30000}).then((res) => {
179-
console.log('logging config reponse', res);
180-
181-
const payload = {
182-
message: 'GET_LATEST_SCAN_DATA',
183-
}
184-
185-
cy.wrap(getScanData(win, payload), {timeout: 45000}).then((res) => {
186-
LambdatestLog('log', "scanning data ");
187-
188-
189-
cy.task('initializeFile', filePath).then((filePath) => {
190-
cy.readFile(filePath, { log: true, timeout: 45000 }).then((fileContent) => {
191-
let resultsArray = [{}];
192-
console.log('logging report', res);
193-
// If the file is not empty, parse the existing content
194-
if (fileContent) {
195-
try {
196-
resultsArray = JSON.parse(JSON.stringify(fileContent));
197-
} catch (e) {
198-
console.log("parsing error for content " , fileContent)
199-
console.log('Error parsing JSON file:', e);
200-
return;
201-
}
202-
}
203-
console.log('scanned data recieved is', res.message);
204-
if (res.message == "GET_LATEST_SCAN_DATA") {
205-
// Append the new result
206-
resultsArray.push(res);
207-
console.log('resultsarray logging', resultsArray);
208-
}
209-
210-
// Write the updated content back to the file
211-
cy.writeFile(filePath, resultsArray, { log: true, timeout: 45000 });
212-
});
213-
});
214-
});
215-
216-
});
217-
})
172+
processAccessibilityReport(win);
173+
})
218174

219175

220176
})

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "lambdatest-cypress-cli",
3-
"version": "3.0.33",
3+
"version": "3.0.34",
44
"description": "The lambdatest-cypress-cli is LambdaTest's command-line interface (CLI) aimed to help you run your Cypress tests on LambdaTest platform.",
55
"homepage": "https://github.com/LambdaTest/lambdatest-cypress-cli",
66
"author": "LambdaTest <[email protected]>",

0 commit comments

Comments
 (0)