@@ -37,49 +37,36 @@ function extractHealedSelectors(logText: string): SelectorMapping[] {
37
37
38
38
// Pattern to match preceding selector requests
39
39
const requestPattern =
40
- / P O S T \/ s e s s i o n \/ [ ^ / ] + \/ e l e m e n t .* ?" u s i n g " : " c s s s e l e c t o r " , " v a l u e " : " ( .* ?) " / g ;
40
+ / P O S T \/ s e s s i o n \/ [ ^ / ] + \/ e l e m e n t .* ?" u s i n g " : " c s s s e l e c t o r " , " v a l u e " : " ( .* ?) " / ;
41
41
42
42
// Find all successful healed selectors with their line numbers and context
43
- const healedSelectors : Array < {
44
- selector : string ;
45
- lineNumber : number ;
46
- context : { before : string ; after : string } ;
47
- } > = [ ] ;
43
+ const healedMappings : SelectorMapping [ ] = [ ] ;
48
44
49
- logLines . forEach ( ( line , index ) => {
50
- const match = line . match ( selfhealPattern ) ;
45
+ for ( let i = 0 ; i < logLines . length ; i ++ ) {
46
+ const match = logLines [ i ] . match ( selfhealPattern ) ;
51
47
if ( match ) {
52
- const beforeLine = index > 0 ? logLines [ index - 1 ] : "" ;
53
- const afterLine = index < logLines . length - 1 ? logLines [ index + 1 ] : "" ;
48
+ const beforeLine = i > 0 ? logLines [ i - 1 ] : "" ;
49
+ const afterLine = i < logLines . length - 1 ? logLines [ i + 1 ] : "" ;
50
+
51
+ // Look backwards to find the most recent original selector request
52
+ let originalSelector = "UNKNOWN" ;
53
+ for ( let j = i - 1 ; j >= 0 ; j -- ) {
54
+ const requestMatch = logLines [ j ] . match ( requestPattern ) ;
55
+ if ( requestMatch ) {
56
+ originalSelector = requestMatch [ 1 ] ;
57
+ break ;
58
+ }
59
+ }
54
60
55
- healedSelectors . push ( {
56
- selector : match [ 1 ] ,
57
- lineNumber : index ,
61
+ healedMappings . push ( {
62
+ originalSelector ,
63
+ healedSelector : match [ 1 ] ,
58
64
context : {
59
65
before : beforeLine ,
60
66
after : afterLine ,
61
67
} ,
62
68
} ) ;
63
69
}
64
- } ) ;
65
-
66
- // Find all selector requests
67
- const selectorRequests : string [ ] = [ ] ;
68
- let requestMatch ;
69
- while ( ( requestMatch = requestPattern . exec ( logText ) ) !== null ) {
70
- selectorRequests . push ( requestMatch [ 1 ] ) ;
71
- }
72
-
73
- // Pair each healed selector with its corresponding original selector
74
- const healedMappings : SelectorMapping [ ] = [ ] ;
75
- const minLength = Math . min ( selectorRequests . length , healedSelectors . length ) ;
76
-
77
- for ( let i = 0 ; i < minLength ; i ++ ) {
78
- healedMappings . push ( {
79
- originalSelector : selectorRequests [ i ] ,
80
- healedSelector : healedSelectors [ i ] . selector ,
81
- context : healedSelectors [ i ] . context ,
82
- } ) ;
83
70
}
84
71
85
72
return healedMappings ;
0 commit comments