Skip to content

Commit d57241b

Browse files
authored
Skip timeStampedPointRange for Playwright recordings (#10633)
* Skip `timeStampedPointRange` for Playwright recordings * skip it for v2 too * fmt * fix thing * fix a thing, maybe * fixed types * comment * seek to the begin point of the playwright recording * tweak the test
1 parent 20f2208 commit d57241b

6 files changed

Lines changed: 39 additions & 31 deletions

File tree

packages/e2e-tests/tests/repaint-02.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ test("repaint-02: repaints on hover", async ({
1111
}) => {
1212
await startTest(page, recordingId, testScope);
1313

14-
const initialScreenShot = await getGraphicsDataUrl(page);
14+
const endingScreenShot = await getGraphicsDataUrl(page);
1515

1616
const testLink = getTestRows(page).first();
1717
await testLink.click();
1818

19-
// Wait for the test to open and focus
19+
// Wait for the test to open
2020
await waitFor(async () => {
21-
await expect(await getGraphicsDataUrl(page)).not.toBe(initialScreenShot);
21+
await expect(await getGraphicsDataUrl(page)).not.toBe(endingScreenShot);
2222
});
2323

2424
// By default, the screenshot shown should correspond to the start of the test

packages/e2e-tests/tests/repaint-03.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@ test("repaint-03: repaints on seek", async ({ pageWithMeta: { page, recordingId,
1111
await startTest(page, recordingId, testScope);
1212

1313
const endingScreenShot = await getGraphicsDataUrl(page);
14-
const initialFocusBeginTime = await getFocusBeginTime(page);
1514

1615
const testLink = getTestRows(page).first();
1716
await testLink.click();
1817

19-
// Wait for the test to open and focus
18+
// Wait for the test to open
2019
await waitFor(async () => {
21-
await expect(await getFocusBeginTime(page)).not.toBe(initialFocusBeginTime);
20+
await expect(await getGraphicsDataUrl(page)).not.toBe(endingScreenShot);
2221
});
2322

2423
// By default, the screenshot shown should correspond to the start of the test

packages/shared/test-suites/RecordingTestMetadata.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -921,22 +921,17 @@ export async function processPlaywrightTestRecording(
921921
id,
922922
result,
923923
source,
924-
timeStampedPointRange: getPlaywrightTestTimeStampedPointRange(events),
924+
timeStampedPointRange: null,
925925
};
926926
} else if (isTestRecordingV3(testRecording)) {
927-
if (!testRecording.timeStampedPointRange) {
928-
testRecording.timeStampedPointRange = getPlaywrightTestTimeStampedPointRange(
929-
testRecording.events
930-
);
931-
}
932927
return testRecording;
933928
} else {
934929
// This function does not support the legacy TestItem format
935930
throw Error(`Unsupported legacy TestItem value`);
936931
}
937932
}
938933

939-
function getPlaywrightTestTimeStampedPointRange(
934+
export function getPlaywrightTestTimeStampedPointRange(
940935
events: RecordingTestMetadataV3.TestRecording["events"]
941936
) {
942937
const allEventsSections = Object.values(events);

src/ui/components/TestSuite/views/TestRecording/Panel.tsx

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,26 @@ export default function Panel() {
4949
});
5050

5151
// We only want to cache the test event details when the focus window has been updated
52-
// to match the range of the test recording. Experimentation shows there can be some renders
52+
// to match the range of the test recording in the case of Cypress tests. Experimentation shows there can be some renders
5353
// where the focus range and test range are mismatched, so try to avoid caching in those cases.
54+
//
55+
// Entering the panel in the case of Playwright recording doesn't change the focus range.
56+
// Playwright recordings are usually much shorter given each page is recorded separately
57+
// and it's OK to prefetch all of the test event details for them right away.
5458
const enableCache =
55-
focusWindow &&
56-
testRecording.timeStampedPointRange?.begin &&
57-
isExecutionPointsWithinRange(
58-
focusWindow.begin.point,
59-
testRecording.timeStampedPointRange.begin.point,
60-
testRecording.timeStampedPointRange.end.point
61-
) &&
62-
isExecutionPointsWithinRange(
63-
focusWindow.end.point,
64-
testRecording.timeStampedPointRange.begin.point,
65-
testRecording.timeStampedPointRange.end.point
66-
);
59+
testRecording.testRunnerName === "playwright" ||
60+
(focusWindow &&
61+
testRecording.timeStampedPointRange &&
62+
isExecutionPointsWithinRange(
63+
focusWindow.begin.point,
64+
testRecording.timeStampedPointRange.begin.point,
65+
testRecording.timeStampedPointRange.end.point
66+
) &&
67+
isExecutionPointsWithinRange(
68+
focusWindow.end.point,
69+
testRecording.timeStampedPointRange.begin.point,
70+
testRecording.timeStampedPointRange.end.point
71+
));
6772

6873
useImperativeIntervalCacheValues(
6974
testEventDetailsIntervalCache,

src/ui/components/TestSuite/views/TestRecording/useTestEventContextMenu.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ function PlayToHereMenuItem({ testEvent }: { testEvent: TestEvent }) {
111111

112112
const beginTimeStampedPoint = testRecording.timeStampedPointRange?.begin ?? null;
113113
const endPoint = getTestEventExecutionPoint(testEvent);
114-
if (beginTimeStampedPoint == null || endPoint == null) {
114+
if (endPoint == null) {
115115
return null;
116116
}
117117

@@ -120,7 +120,7 @@ function PlayToHereMenuItem({ testEvent }: { testEvent: TestEvent }) {
120120

121121
dispatch(
122122
startPlayback({
123-
beginTime: beginTimeStampedPoint.time,
123+
beginTime: beginTimeStampedPoint?.time ?? 0,
124124
endTime: getTestEventTime(testEvent),
125125
})
126126
);

src/ui/components/TestSuite/views/TestSuiteContext.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ import {
1111
import { FocusContext } from "replay-next/src/contexts/FocusContext";
1212
import { SessionContext } from "replay-next/src/contexts/SessionContext";
1313
import { TimelineContext } from "replay-next/src/contexts/TimelineContext";
14-
import { TestEvent, TestRecording } from "shared/test-suites/RecordingTestMetadata";
14+
import {
15+
TestEvent,
16+
TestRecording,
17+
getPlaywrightTestTimeStampedPointRange,
18+
} from "shared/test-suites/RecordingTestMetadata";
1519

1620
type TestSuiteContextType = {
1721
setTestRecording: (value: TestRecording | null) => Promise<void>;
@@ -57,8 +61,13 @@ export function TestSuiteContextRoot({ children }: PropsWithChildren) {
5761
sync: true,
5862
}
5963
);
60-
61-
seekToTime(timeStampedPointRange.begin.time, timeStampedPointRange.begin.point, false);
64+
}
65+
let beginPoint = timeStampedPointRange?.begin;
66+
if (testRecording.testRunnerName === "playwright") {
67+
beginPoint = getPlaywrightTestTimeStampedPointRange(testRecording.events)?.begin;
68+
}
69+
if (beginPoint) {
70+
seekToTime(beginPoint.time, beginPoint.point, false);
6271
}
6372
} else {
6473
await updateForTimelineImprecise([0, duration], {

0 commit comments

Comments
 (0)