test: lock journey lifecycle and static fallback

This commit is contained in:
2026-09-02 05:36:59 +03:00
parent 130ff2d8bb
commit a86767cdc6
11 changed files with 478 additions and 5 deletions

View File

@@ -0,0 +1,57 @@
import { expect, test } from '../helpers/serve-dist';
import {
dispatchPersistedPageTransition,
installSceneInstrumentation,
readSceneInstrumentation,
} from '../helpers/scene-instrumentation';
test.beforeEach(async ({ page }) => installSceneInstrumentation(page));
test('synthetic persisted freeze and restore keeps at most one canvas, RAF loop, and audio context', async ({
page,
distUrl,
}) => {
await page.goto(distUrl, { waitUntil: 'domcontentloaded' });
await expect(page.locator('.journey-world')).toHaveAttribute('data-scene-state', 'running');
await page.getByRole('button', { name: 'START THE DRIVE' }).click();
await expect(page.getByRole('button', { name: 'Mute sound' })).toBeVisible();
for (let cycle = 0; cycle < 3; cycle += 1) {
await dispatchPersistedPageTransition(page, 'pagehide');
await expect.poll(async () => (await readSceneInstrumentation(page)).activeAnimationFrames).toBe(0);
await dispatchPersistedPageTransition(page, 'pageshow');
await expect(page.locator('.journey-world')).toHaveAttribute('data-scene-state', 'running');
await expect.poll(async () => (await readSceneInstrumentation(page)).activeAnimationFrames).toBeLessThanOrEqual(1);
}
const state = await readSceneInstrumentation(page);
expect(state.maximumCanvasCount).toBe(1);
expect(await page.locator('.journey-canvas').count()).toBe(1);
expect(state.audioContextsConstructed).toBe(1);
expect(state.liveAudioContexts).toBeLessThanOrEqual(1);
});
test('persisted lifecycle events preserve paused and Static states without duplicate resources', async ({
page,
distUrl,
}) => {
await page.goto(distUrl, { waitUntil: 'domcontentloaded' });
await expect(page.locator('.journey-world')).toHaveAttribute('data-scene-state', 'running');
await page.getByRole('button', { name: 'Pause motion' }).click();
await dispatchPersistedPageTransition(page, 'pagehide');
await dispatchPersistedPageTransition(page, 'pageshow');
await expect(page.locator('.journey-canvas')).toHaveCount(0);
await expect(page.getByRole('button', { name: 'Resume motion' })).toBeVisible();
await page.getByLabel('Quality control').selectOption('static');
await dispatchPersistedPageTransition(page, 'pagehide');
await dispatchPersistedPageTransition(page, 'pageshow');
await expect(page.locator('.journey-canvas')).toHaveCount(0);
await expect(page.getByRole('button', { name: 'Enable motion' })).toBeVisible();
const state = await readSceneInstrumentation(page);
expect(state.maximumCanvasCount).toBeLessThanOrEqual(1);
await expect.poll(async () => (await readSceneInstrumentation(page)).activeAnimationFrames).toBe(0);
expect(state.liveAudioContexts).toBe(0);
});