@@ -41,9 +41,10 @@ export function snapshotNodes(result: { json?: any }): LiveSnapshotNode[] {
4141}
4242
4343const SCROLL_SEARCH_ATTEMPTS = 4 ;
44- // A stalled capture says nothing about where the element is, so it must not consume the scroll
45- // budget outright; a couple of retries absorb a slow runner without masking a real absence.
46- const SCROLL_SEARCH_STALL_RETRIES = 2 ;
44+ // A stalled capture, or one taken while the last scroll was still moving, says nothing about where
45+ // the element is, so re-reading it must not consume a scroll. A couple of re-reads per scroll absorb
46+ // a slow runner without masking a real absence.
47+ const SCROLL_SEARCH_REREADS = 2 ;
4748
4849export async function assertElementTextAfterScrolling (
4950 context : LiveContext ,
@@ -64,7 +65,7 @@ export async function assertElementTextAfterScrolling(
6465 'scroll' ,
6566 'down' ,
6667 '0.75' ,
67- ] ) . then ( ( ) => undefined ) ,
68+ ] ) . then ( ( result ) => result . json ?. data ) ,
6869 ) ;
6970 await assertElementText ( context , selector , expected ) ;
7071}
@@ -78,31 +79,31 @@ export async function assertElementTextAfterScrolling(
7879export async function searchForVisibleElement (
7980 selector : string ,
8081 probeVisibility : ( attempt : number ) => Promise < CliJsonResult > ,
81- scrollAfterAttempt : ( attempt : number ) => Promise < void > ,
82+ scrollAfterAttempt : ( attempt : number ) => Promise < unknown > ,
8283) : Promise < void > {
83- let stallRetriesLeft = SCROLL_SEARCH_STALL_RETRIES ;
84- let lastFailure : CliJsonResult | undefined ;
84+ let rereadsLeft = SCROLL_SEARCH_REREADS ;
85+ const history : string [ ] = [ ] ;
8586
8687 for ( let attempt = 1 ; attempt <= SCROLL_SEARCH_ATTEMPTS ; ) {
8788 const probe = await probeVisibility ( attempt ) ;
89+ history . push ( `probe ${ attempt } : ${ JSON . stringify ( probe . json ?? { status : probe . status } ) } ` ) ;
8890 if ( probe . status === 0 ) return ;
89- lastFailure = probe ;
9091
91- // The snapshot never came back, so the surface was never read. Scrolling here would move the
92- // surface for a reason unrelated to visibility and spend an attempt on no evidence.
93- if ( probe . json ?. error ?. details ?. captureStalled === true && stallRetriesLeft > 0 ) {
94- stallRetriesLeft -= 1 ;
92+ const details = probe . json ?. error ?. details ;
93+ const readNothing = details ?. captureStalled === true || details ?. unsettledGesture !== undefined ;
94+ if ( readNothing && rereadsLeft > 0 ) {
95+ rereadsLeft -= 1 ;
9596 continue ;
9697 }
9798
9899 attempt += 1 ;
99100 if ( attempt <= SCROLL_SEARCH_ATTEMPTS ) {
100- await scrollAfterAttempt ( attempt - 1 ) ;
101+ const scrolled = await scrollAfterAttempt ( attempt - 1 ) ;
102+ history . push ( `scroll after attempt ${ attempt - 1 } : ${ JSON . stringify ( scrolled ?? null ) } ` ) ;
103+ rereadsLeft = SCROLL_SEARCH_REREADS ;
101104 }
102105 }
103- assert . fail (
104- `${ selector } did not become visible after scrolling\nlast visibility probe: ${ JSON . stringify ( lastFailure ?. json ?? null ) } ` ,
105- ) ;
106+ assert . fail ( `${ selector } did not become visible after scrolling\n${ history . join ( '\n' ) } ` ) ;
106107}
107108
108109function requireNode (
0 commit comments