@@ -13,33 +13,27 @@ const commandsToOverride = [
13
13
const commandsToWrap = [ 'visit' , 'click' , 'type' , 'request' , 'dblclick' , 'rightclick' , 'clear' , 'check' , 'uncheck' , 'select' , 'trigger' , 'selectFile' , 'scrollIntoView' , 'scroll' , 'scrollTo' , 'blur' , 'focus' , 'go' , 'reload' , 'submit' , 'viewport' , 'origin' ] ;
14
14
15
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
- }
16
+ const customChaining = cy . wrap ( null ) . processAccessibilityReport ( ) ;
17
+
18
+ const updateArgs = ( args , stateType , newSubject ) =>
19
+ stateType !== 'parent' ? [ newSubject , ...args . slice ( 1 ) ] : args ;
20
+
23
21
const runCustomizedCommand = ( ) => {
24
22
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 ) ) ;
30
25
} 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 ) ) ) ;
39
31
}
40
- }
32
+ } ;
33
+
41
34
runCustomizedCommand ( ) ;
42
- }
35
+ } ;
36
+
43
37
44
38
Cypress . Commands . add ( 'processAccessibilityReport' , ( ) => {
45
39
try {
@@ -308,9 +302,11 @@ afterEach(() => {
308
302
309
303
} )
310
304
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
+ }
316
312
0 commit comments