mirror of
https://github.com/gadgethd/ukmesh.git
synced 2026-12-06 03:14:09 +00:00
72 lines
3.5 KiB
TypeScript
72 lines
3.5 KiB
TypeScript
import { expect, test as base } from '@playwright/test';
|
|
import { fixtures, vectorRoutes } from './basemapFixtures.js';
|
|
|
|
const test = base.extend({
|
|
// Start a fresh renderer for each failure scenario. A shared Chromium process
|
|
// can stall when the next test opens a context after a software WebGL run.
|
|
context: [async ({ playwright, browserName, launchOptions, headless, contextOptions, baseURL, serviceWorkers }, use) => {
|
|
const browser = await playwright[browserName].launch({ ...launchOptions, headless });
|
|
try {
|
|
const context = await browser.newContext({ ...contextOptions, baseURL, serviceWorkers });
|
|
try {
|
|
await use(context);
|
|
} finally {
|
|
await context.close();
|
|
}
|
|
} finally {
|
|
await browser.close();
|
|
}
|
|
}, { timeout: 45_000 }],
|
|
});
|
|
|
|
test.beforeEach(async ({ page }) => fixtures(page));
|
|
|
|
test('production worker decodes tiles while old fixed worker and metadata URLs are stale', async ({ page }) => {
|
|
const workerRequests: string[] = [];
|
|
page.on('request', (request) => {
|
|
if (request.url().includes('maplibre-gl-worker')) workerRequests.push(request.url());
|
|
});
|
|
await page.route('**/assets/maplibre-gl-worker.mjs', (route) => route.fulfill({
|
|
contentType: 'application/javascript', body: 'throw new Error("stale cached worker")',
|
|
}));
|
|
await vectorRoutes(page, () => false);
|
|
await page.goto('/');
|
|
await page.locator('.maplibregl-map').waitFor({ timeout: 20_000 });
|
|
await expect(page.locator('.map-area')).toHaveAttribute('data-basemap-state', 'healthy', { timeout: 30_000 });
|
|
expect(workerRequests.some((url) => /maplibre-gl-worker-[\w-]+\.js$/.test(url))).toBe(true);
|
|
expect(workerRequests.some((url) => url.endsWith('/maplibre-gl-worker.mjs'))).toBe(false);
|
|
});
|
|
|
|
test('a style request that never completes still reaches the bundled outline', async ({ page }) => {
|
|
await page.route('https://tiles.openfreemap.org/**', () => {});
|
|
await page.route('https://tile.openstreetmap.org/**', (route) => route.abort());
|
|
const outline = page.waitForResponse('**/basemap/uk-land.geojson', { timeout: 40_000 });
|
|
await page.goto('/');
|
|
await page.locator('.maplibregl-map').waitFor({ timeout: 20_000 });
|
|
await expect(page.locator('.map-area')).toHaveAttribute('data-basemap-state', 'fallback', { timeout: 30_000 });
|
|
expect((await outline).ok()).toBe(true);
|
|
await expect(page.getByText('Using backup basemap')).toBeVisible();
|
|
});
|
|
|
|
test('failed tiles reach the backup map and a manual retry restores vector tiles', async ({ page }) => {
|
|
// The software renderer can queue raster work after the fallback UI is ready.
|
|
// Observe early responses too, and give each recovery phase its own deadline.
|
|
test.setTimeout(100_000);
|
|
let failTiles = true;
|
|
let receivedBackupTile = false;
|
|
page.on('response', response => {
|
|
if (new URL(response.url()).hostname === 'tile.openstreetmap.org' && response.ok()) {
|
|
receivedBackupTile = true;
|
|
}
|
|
});
|
|
await vectorRoutes(page, () => failTiles);
|
|
await page.goto('/');
|
|
await page.locator('.maplibregl-map').waitFor({ timeout: 20_000 });
|
|
await expect(page.locator('.map-area')).toHaveAttribute('data-basemap-state', 'fallback', { timeout: 30_000 });
|
|
await expect.poll(() => receivedBackupTile, { timeout: 40_000 }).toBe(true);
|
|
failTiles = false;
|
|
await page.getByRole('button', { name: 'Retry', exact: true }).click();
|
|
await expect(page.locator('.map-area')).toHaveAttribute('data-basemap-state', 'healthy', { timeout: 15_000 });
|
|
await expect(page.getByText('Using backup basemap')).toHaveCount(0);
|
|
});
|