Skip to content

Commit 2c323d0

Browse files
Kim DuganKim Dugan
authored andcommitted
remove findLastIndex
1 parent ba048e5 commit 2c323d0

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

packages/rrweb/test/record/cross-origin-iframes.test.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -273,14 +273,24 @@ describe('cross origin iframes', function (this: ISuite) {
273273
);
274274

275275
// Verify the last attachment event came after the last full snapshot
276-
const lastFullSnapshotIndex = eventsAfterSnapshot.findLastIndex(
277-
(e) => e.type === EventType.FullSnapshot,
278-
);
279-
const lastAttachmentIndex = eventsAfterSnapshot.findLastIndex(
280-
(e) =>
276+
let lastFullSnapshotIndex = -1;
277+
let lastAttachmentIndex = -1;
278+
for (let i = eventsAfterSnapshot.length - 1; i >= 0; i--) {
279+
const e = eventsAfterSnapshot[i];
280+
if (lastFullSnapshotIndex === -1 && e.type === EventType.FullSnapshot) {
281+
lastFullSnapshotIndex = i;
282+
}
283+
if (
284+
lastAttachmentIndex === -1 &&
281285
e.type === EventType.IncrementalSnapshot &&
282-
(e.data as mutationData).isAttachIframe,
283-
);
286+
(e.data as mutationData).isAttachIframe
287+
) {
288+
lastAttachmentIndex = i;
289+
}
290+
if (lastFullSnapshotIndex !== -1 && lastAttachmentIndex !== -1) {
291+
break;
292+
}
293+
}
284294
expect(lastAttachmentIndex).toBeGreaterThan(lastFullSnapshotIndex);
285295
});
286296

0 commit comments

Comments
 (0)