@@ -12,6 +12,44 @@ const commandsToOverride = [
1212
1313const commandsToWrap = [ 'visit' , 'click' , 'type' , 'request' , 'dblclick' , 'rightclick' , 'clear' , 'check' , 'uncheck' , 'select' , 'trigger' , 'selectFile' , 'scrollIntoView' , 'scroll' , 'scrollTo' , 'blur' , 'focus' , 'go' , 'reload' , 'submit' , 'viewport' , 'origin' ] ;
1414
15+ const performModifiedScan = ( originalFn , Subject , stateType , ...args ) => {
16+ let customChaining = cy . wrap ( null ) . processAccessibilityReport ( ) ;
17+ const changeSub = ( args , stateType , newSubject ) => {
18+ if ( stateType !== 'parent' ) {
19+ return [ newSubject , ...args . slice ( 1 ) ] ;
20+ }
21+ return args ;
22+ }
23+ const runCustomizedCommand = ( ) => {
24+ if ( ! Subject ) {
25+ let orgS1 , orgS2 , cypressCommandSubject = null ;
26+ if ( ( orgS2 = ( orgS1 = cy ) . subject ) !== null && orgS2 !== void 0 ) {
27+ cypressCommandSubject = orgS2 . call ( orgS1 ) ;
28+ }
29+ customChaining . then ( ( ) => cypressCommandSubject ) . then ( ( ) => { originalFn ( ...args ) } ) ;
30+ } else {
31+ let orgSC1 , orgSC2 , timeO1 , cypressCommandChain = null , setTimeout = null ;
32+ if ( ( timeO1 = args . find ( arg => arg !== null && arg !== void 0 ? arg . timeout : null ) ) !== null && timeO1 !== void 0 ) {
33+ setTimeout = timeO1 . timeout ;
34+ }
35+ if ( ( orgSC1 = ( orgSC2 = cy ) . subjectChain ) !== null && orgSC1 !== void 0 ) {
36+ cypressCommandChain = orgSC1 . call ( orgSC2 ) ;
37+ }
38+ customChaining . performScanSubjectQuery ( cypressCommandChain , setTimeout ) . then ( { timeout : 30000 } , ( newSubject ) => originalFn ( ...changeSub ( args , stateType , newSubject ) ) ) ;
39+ }
40+ }
41+ runCustomizedCommand ( ) ;
42+ }
43+
44+ Cypress . Commands . add ( 'processAccessibilityReport' , ( ) => {
45+ try {
46+ cy . window ( ) . then ( ( win ) => {
47+ return cy . wrap ( processAccessibilityReport ( win ) , { timeout : 45000 } ) ;
48+ } ) ;
49+ } catch ( error ) {
50+ console . log ( `Error in performing scan with error: ${ error . message } ` ) ;
51+ }
52+ } )
1553
1654const setScanConfig = ( win , payload ) => {
1755 return new Promise ( ( resolve , reject ) => {
@@ -76,7 +114,7 @@ const sendScanData = (win, payload) => {
76114 } ) ;
77115} ;
78116
79- async function processAccessibilityReport ( url , windowNew ) {
117+ const processAccessibilityReport = async ( windowNew ) => {
80118 try {
81119 let wcagCriteriaValue = Cypress . env ( "WCAG_CRITERIA" ) || "wcag21a" ;
82120 let bestPracticeValue = Cypress . env ( "BEST_PRACTICE" ) === "true" ;
@@ -89,7 +127,7 @@ async function processAccessibilityReport(url,windowNew) {
89127 needsReview : needsReviewValue
90128 } ;
91129
92- console . log ( 'log' , "SET SCAN: Payload to send: for url: " , payloadToSend , url ) ;
130+ console . log ( 'log' , "SET SCAN: Payload to send: for url: " , payloadToSend ) ;
93131 try {
94132 let setResult = await setScanConfig ( windowNew , payloadToSend ) ;
95133 console . log ( 'SET SCAN: response:' , setResult ) ;
@@ -211,22 +249,18 @@ const overRideCommands = JSON.parse(Cypress.env("ACCESSIBILITY_OVERIDE_COMMANDS"
211249
212250if ( overRideCommands ) {
213251 commandsToOverride . forEach ( ( command ) => {
214- Cypress . Commands . overwrite ( command , ( originalFn , url , options ) => {
252+ Cypress . Commands . overwrite ( command , ( originalFn , ... args ) => {
215253 let isAccessibilityLoaded = Cypress . env ( "ACCESSIBILITY" ) || false ;
216- if ( ! isAccessibilityLoaded ) {
217- console . log ( 'log' , "Accessibility not enabled." ) ;
218- return originalFn ( url , options ) ;
254+ const state = cy . state ( 'current' ) , Subject = 'getSubjectFromChain' in cy ;
255+ const stateName = state === null || state === void 0 ? void 0 : state . get ( 'name' ) ;
256+ let stateType = null ;
257+ if ( ! isAccessibilityLoaded || ( stateName && stateName !== command ) ) {
258+ return originalFn ( ...args ) ;
219259 }
220- Cypress . log ( {
221- name : command , // Display the passed command name
222- displayName : `${ command } ` , // Change how it looks in the Cypress log
223- message : url ,
224- } ) ;
225- return cy . window ( ) . then ( ( currentWindowNew ) => {
226- return originalFn ( url , options ) . then ( ( ) => {
227- return processAccessibilityReport ( url , currentWindowNew ) ;
228- } ) ;
229- } ) ;
260+ if ( state !== null && state !== void 0 ) {
261+ stateType = state . get ( 'type' ) ;
262+ }
263+ performModifiedScan ( originalFn , Subject , stateType , ...args ) ;
230264
231265 } ) ;
232266 } ) ;
@@ -260,13 +294,16 @@ if (overRideCommands) {
260294 return ;
261295 }
262296 cy . window ( ) . then ( ( win ) => {
263- processAccessibilityReport ( win ) ;
297+ oldprocessAccessibilityReport ( win ) ;
264298 } )
265299
266300
267301 } )
268302}
269303
270-
304+ Cypress . Commands . addQuery ( 'performScanSubjectQuery' , function ( chaining , setTimeout ) {
305+ this . set ( 'timeout' , setTimeout ) ;
306+ return ( ) => cy . getSubjectFromChain ( chaining ) ;
307+ } ) ;
271308
272309
0 commit comments