Skip to content

Commit c0b1b74

Browse files
committed
test(ios-e2e): re-read an unsettled miss instead of scrolling past it
The live scroll search now re-probes the same window once when a miss carries `unsettledGesture`, and its failure lists every probe and scroll.
1 parent 2e81188 commit c0b1b74

2 files changed

Lines changed: 59 additions & 16 deletions

File tree

‎test/integration/ios-simulator-e2e-visibility-scroll.test.ts‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,45 @@ test('a stalled capture retries without scrolling or consuming an attempt', asyn
5252
assert.deepEqual(probeAttempts, [1, 1]);
5353
assert.deepEqual(scrollAttempts, []);
5454
});
55+
56+
/**
57+
* The CI failure shape: the element is on screen only at offset 1, and the first read after each
58+
* scroll lands on a surface still moving, so it misses with `unsettledGesture`.
59+
*/
60+
function listWithUnsettledFirstReads(visibleAt?: number) {
61+
let offset = 0;
62+
let moving = false;
63+
const probes: number[] = [];
64+
const scrolls: number[] = [];
65+
const probe = async (attempt: number) => {
66+
probes.push(attempt);
67+
const unsettled = moving;
68+
moving = false;
69+
if (!unsettled && offset === visibleAt) return result(0);
70+
return result(1, unsettled ? { unsettledGesture: { action: 'scroll', positionals: [] } } : {});
71+
};
72+
const scroll = async (attempt: number) => {
73+
scrolls.push(attempt);
74+
offset += 1;
75+
moving = true;
76+
};
77+
return { probes, scrolls, probe, scroll };
78+
}
79+
80+
test('an unsettled miss after the scroll that reached the element is re-read at the same offset', async () => {
81+
const list = listWithUnsettledFirstReads(1);
82+
83+
await searchForVisibleElement('id="target"', list.probe, list.scroll);
84+
85+
assert.deepEqual([list.probes, list.scrolls], [[1, 2, 2], [1]]);
86+
});
87+
88+
test('a real absence still fails after the forward scrolls, naming every step', async () => {
89+
const list = listWithUnsettledFirstReads();
90+
91+
await assert.rejects(
92+
searchForVisibleElement('id="target"', list.probe, list.scroll),
93+
/scroll after attempt 3: [\s\S]*probe 4:/,
94+
);
95+
assert.deepEqual(list.scrolls, [1, 2, 3]);
96+
});

‎test/integration/ios-simulator-e2e/live-assertions.ts‎

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@ export function snapshotNodes(result: { json?: any }): LiveSnapshotNode[] {
4141
}
4242

4343
const 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

4849
export 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(
7879
export 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

108109
function requireNode(

0 commit comments

Comments
 (0)