@@ -13,33 +13,27 @@ const commandsToOverride = [
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
1515const 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- }
16+ const customChaining = cy . wrap ( null ) . processAccessibilityReport ( ) ;
17+
18+ const updateArgs = ( args , stateType , newSubject ) =>
19+ stateType !== 'parent' ? [ newSubject , ...args . slice ( 1 ) ] : args ;
20+
2321 const runCustomizedCommand = ( ) => {
2422 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 ) } ) ;
23+ const cypressCommandSubject = cy . subject ?. ( ) ;
24+ customChaining . then ( ( ) => cypressCommandSubject ) . then ( ( ) => originalFn ( ...args ) ) ;
3025 } 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 ) ) ) ;
26+ const timeoutArg = args . find ( arg => arg ?. timeout ) ?. timeout ;
27+ const cypressCommandChain = cy . subjectChain ?. ( ) ;
28+
29+ customChaining . performScanSubjectQuery ( cypressCommandChain , timeoutArg )
30+ . then ( { timeout : 30000 } , ( newSubject ) => originalFn ( ...updateArgs ( args , stateType , newSubject ) ) ) ;
3931 }
40- }
32+ } ;
33+
4134 runCustomizedCommand ( ) ;
42- }
35+ } ;
36+
4337
4438Cypress . Commands . add ( 'processAccessibilityReport' , ( ) => {
4539 try {
@@ -308,9 +302,11 @@ afterEach(() => {
308302
309303} )
310304
311- Cypress . Commands . addQuery ( 'performScanSubjectQuery' , function ( chaining , setTimeout ) {
312- this . set ( 'timeout' , setTimeout ) ;
313- return ( ) => cy . getSubjectFromChain ( chaining ) ;
314- } ) ;
315-
305+ if ( ! Cypress . Commands . hasOwnProperty ( '_lambdaTestSDKQueryAdded' ) ) {
306+ Cypress . Commands . addQuery ( 'performScanSubjectQuery' , function ( chaining , setTimeout ) {
307+ this . set ( 'timeout' , setTimeout ) ;
308+ return ( ) => cy . getSubjectFromChain ( chaining ) ;
309+ } ) ;
310+ Cypress . Commands . _lambdaTestSDKQueryAdded = true ;
311+ }
316312
0 commit comments