@@ -13,25 +13,51 @@ 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- const customChaining = cy . wrap ( null ) . processAccessibilityReport ( ) ;
16+ // Initialize custom chaining
17+ const customChaining = cy . wrap ( null ) . performScan ( ) ;
1718
18- const updateArgs = ( args , stateType , newSubject ) =>
19- stateType !== 'parent' ? [ newSubject , ...args . slice ( 1 ) ] : args ;
19+ // Function to modify arguments based on stateType
20+ const updateArgs = ( args , stateType , newSubject ) => {
21+ return stateType !== 'parent' ? [ newSubject , ...args . slice ( 1 ) ] : args ;
22+ } ;
2023
21- const runCustomizedCommand = ( ) => {
22- if ( ! Subject ) {
23- const cypressCommandSubject = cy . subject ? cy . subject ( ) : cy . wrap ( null ) ;
24- customChaining . then ( ( ) => cypressCommandSubject ) . then ( ( ) => originalFn ( ...args ) ) ;
25- } else {
26- const timeoutArg = args . find ( arg => arg ?. timeout ) ?. timeout ;
27- const cypressCommandChain = cy . subjectChain ?. ( ) ;
24+ // Extract timeout from args if present
25+ const getTimeout = ( args ) => {
26+ const timeoutArg = args . find ( arg => arg && arg . timeout !== undefined ) ;
27+ return timeoutArg ?. timeout ;
28+ } ;
2829
29- customChaining . performScanSubjectQuery ( cypressCommandChain , timeoutArg )
30- . then ( { timeout : 30000 } , ( newSubject ) => originalFn ( ...updateArgs ( args , stateType , newSubject ) ) ) ;
31- }
30+ // Get the current Cypress subject
31+ const getCurrentSubject = ( ) => {
32+ return cy . subject ?. ( ) || null ;
33+ } ;
34+
35+ // Get the current Cypress subject chain
36+ const getSubjectChain = ( ) => {
37+ return cy . subjectChain ?. ( ) || null ;
3238 } ;
3339
34- runCustomizedCommand ( ) ;
40+ // Execute the command pipeline
41+ if ( ! Subject ) {
42+ // Handle case without Subject
43+ const cypressCommandSubject = getCurrentSubject ( ) ;
44+
45+ customChaining
46+ . then ( ( ) => cypressCommandSubject )
47+ . then ( ( ) => {
48+ originalFn ( ...args ) ;
49+ } ) ;
50+ } else {
51+ // Handle case with Subject
52+ const cypressCommandChain = getSubjectChain ( ) ;
53+ const timeout = getTimeout ( args ) ;
54+
55+ customChaining
56+ . performScanSubjectQuery ( cypressCommandChain , timeout )
57+ . then ( { timeout : 30000 } , ( newSubject ) => {
58+ originalFn ( ...updateArgs ( args , stateType , newSubject ) ) ;
59+ } ) ;
60+ }
3561} ;
3662
3763
0 commit comments