Skip to content

Commit 3c99d04

Browse files
committed
test: Add cache-busting to ensure fresh WASM loads between tests
Each Playwright test now navigates to a unique URL with a timestamp query parameter to bust browser/WASM caching. This ensures: 1. Each test gets a fresh page load 2. WASM module is reloaded (not cached from previous test) 3. Event handlers are freshly attached 4. Component state starts clean Without cache busting, tests were using cached WASM from the first test, causing event handlers to persist and state to carry over between tests. Changes: - Added getTestUrl() helper that appends ?t=<timestamp> - Replaced all page.goto('http://localhost:8080') with page.goto(getTestUrl()) - Added beforeEach hook to clear cookies between tests This ensures tests are isolated and the app reloads properly between test cases, which is critical for testing state changes like the auto-rotate toggle.
1 parent 5944879 commit 3c99d04

1 file changed

Lines changed: 19 additions & 14 deletions

File tree

examples/webgpu-cube/tests/webgpu-cube.spec.ts

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import { test, expect } from '@playwright/test';
22

3+
// Helper function to get URL with cache buster
4+
function getTestUrl(): string {
5+
return `http://localhost:8080?t=${Date.now()}`;
6+
}
7+
38
test.describe('WebGPU Rotating Cube', () => {
4-
test.beforeEach(async ({ page }) => {
5-
// Only navigate if not the initialization logs test
6-
// (that test needs to set up listeners before navigation)
9+
test.beforeEach(async ({ page, context }) => {
10+
// Clear cookies between tests
11+
await context.clearCookies();
712
});
813

914
test('should show initialization logs', async ({ page }) => {
@@ -13,8 +18,8 @@ test.describe('WebGPU Rotating Cube', () => {
1318
consoleMessages.push(`[${msg.type()}] ${msg.text()}`);
1419
});
1520

16-
// NOW navigate to the page
17-
await page.goto('http://localhost:8080');
21+
// NOW navigate to the page with cache buster
22+
await page.goto(getTestUrl());
1823

1924
// Wait for canvas to be rendered (indicates WebGPU initialization)
2025
await page.waitForSelector('canvas', { timeout: 5000 });
@@ -48,7 +53,7 @@ test.describe('WebGPU Rotating Cube', () => {
4853

4954
test('should load without errors', async ({ page }) => {
5055
// Navigate to the page
51-
await page.goto('http://localhost:8080');
56+
await page.goto(getTestUrl());
5257

5358
// Wait for the page to load
5459
await page.waitForLoadState('networkidle');
@@ -75,7 +80,7 @@ test.describe('WebGPU Rotating Cube', () => {
7580

7681
test('should display WebGPU support message', async ({ page }) => {
7782
// Navigate to the page
78-
await page.goto('http://localhost:8080');
83+
await page.goto(getTestUrl());
7984

8085
// Check that WebGPU initialization messages appear in console
8186
const initMessages: string[] = [];
@@ -103,7 +108,7 @@ test.describe('WebGPU Rotating Cube', () => {
103108

104109
test('should render canvas element', async ({ page }) => {
105110
// Navigate to the page
106-
await page.goto('http://localhost:8080');
111+
await page.goto(getTestUrl());
107112

108113
// Wait for canvas to be created
109114
await page.waitForSelector('canvas', { timeout: 5000 });
@@ -120,7 +125,7 @@ test.describe('WebGPU Rotating Cube', () => {
120125

121126
test('should display control buttons', async ({ page }) => {
122127
// Navigate to the page
123-
await page.goto('http://localhost:8080');
128+
await page.goto(getTestUrl());
124129

125130
// Wait for canvas to be rendered
126131
await page.waitForSelector('canvas', { timeout: 5000 });
@@ -149,7 +154,7 @@ test.describe('WebGPU Rotating Cube', () => {
149154

150155
test('should respond to button clicks', async ({ page }) => {
151156
// Navigate to the page
152-
await page.goto('http://localhost:8080');
157+
await page.goto(getTestUrl());
153158

154159
// Wait for canvas to be rendered
155160
await page.waitForSelector('canvas', { timeout: 5000 });
@@ -185,7 +190,7 @@ test.describe('WebGPU Rotating Cube', () => {
185190

186191
test('should show speed control when auto-rotate is enabled', async ({ page }) => {
187192
// Navigate to the page
188-
await page.goto('http://localhost:8080');
193+
await page.goto(getTestUrl());
189194

190195
// Wait for canvas to be rendered
191196
await page.waitForSelector('canvas', { timeout: 5000 });
@@ -216,7 +221,7 @@ test.describe('WebGPU Rotating Cube', () => {
216221

217222
test('should handle keyboard controls', async ({ page }) => {
218223
// Navigate to the page
219-
await page.goto('http://localhost:8080');
224+
await page.goto(getTestUrl());
220225

221226
// Wait for canvas to be rendered
222227
await page.waitForSelector('canvas', { timeout: 5000 });
@@ -251,7 +256,7 @@ test.describe('WebGPU Rotating Cube', () => {
251256

252257
test('should render scene and capture screenshot', async ({ page }) => {
253258
// Navigate to the page
254-
await page.goto('http://localhost:8080');
259+
await page.goto(getTestUrl());
255260

256261
// Wait for canvas to be rendered
257262
await page.waitForSelector('canvas', { timeout: 5000 });
@@ -275,7 +280,7 @@ test.describe('WebGPU Rotating Cube', () => {
275280

276281
test('should not show error messages', async ({ page }) => {
277282
// Navigate to the page
278-
await page.goto('http://localhost:8080');
283+
await page.goto(getTestUrl());
279284

280285
// Wait for page to load
281286
await page.waitForTimeout(1000);

0 commit comments

Comments
 (0)