Improve terrain performance tests by resetting long task state and adjusting wait logic

This commit is contained in:
2026-04-29 23:36:15 +02:00
parent 31e5428186
commit 5bd734bf00

View File

@@ -81,6 +81,15 @@ async function readLongTaskCount(page: Page) {
}); });
} }
async function resetLongTasks(page: Page) {
await page.evaluate(() => {
const targetWindow = window as Window & {
__terrainPerfLongTasks?: { duration: number }[];
};
targetWindow.__terrainPerfLongTasks = [];
});
}
function createTerrainScene(size: number, collisionEnabled: boolean) { function createTerrainScene(size: number, collisionEnabled: boolean) {
const document = createEmptySceneDocument({ const document = createEmptySceneDocument({
name: `Terrain ${size} perf` name: `Terrain ${size} perf`
@@ -119,18 +128,11 @@ test("terrain runner and editor zoom perf probe", async ({ page }) => {
await installLongTaskObserver(page); await installLongTaskObserver(page);
for (const size of [100, 320, 640]) { for (const size of [100, 320, 640]) {
await resetLongTasks(page);
await replaceSceneDocument(page, createTerrainScene(size, true)); await replaceSceneDocument(page, createTerrainScene(size, true));
await page.getByTestId("enter-run-mode").click(); await page.getByTestId("enter-run-mode").click();
await page.getByTestId("runner-shell").waitFor({ state: "visible" }); await page.getByTestId("runner-shell").waitFor({ state: "visible" });
await page.waitForFunction(() => { await page.waitForTimeout(2_000);
const overlay = document.querySelector(
"[data-testid='runner-loading-overlay']"
);
return overlay?.className.includes(
"runner-canvas__loading-overlay--hidden"
);
});
const frames = await sampleAnimationFrames(page, 180); const frames = await sampleAnimationFrames(page, 180);
const longTaskCount = await readLongTaskCount(page); const longTaskCount = await readLongTaskCount(page);