Add the public-document Worldspace, Rust Client/Host bridge, and WIP-backed tree and document rendering while preserving static fallback and navigation. Pin the Rust source and build tools, verify resource and trap boundaries, and cover dev and preview loading including same-origin generated module URLs.
47 lines
2.3 KiB
TypeScript
47 lines
2.3 KiB
TypeScript
import { expect, test } from '@playwright/test';
|
|
import { load } from 'cheerio';
|
|
|
|
// Shared by dev and preview: a successful build alone cannot catch Vite's
|
|
// dynamic-import rewriting of generated modules served from public/.
|
|
test.use({ javaScriptEnabled: true, reducedMotion: 'reduce' });
|
|
|
|
test('generated WASM loads as a static asset and hydrates real WIP data', async ({ page }, testInfo) => {
|
|
const base = testInfo.project.use.baseURL!;
|
|
const errors: string[] = [];
|
|
const assets: { url: string; status: number }[] = [];
|
|
page.on('pageerror', (error) => errors.push(error.message));
|
|
page.on('response', (response) => {
|
|
if (response.status() >= 500) errors.push(`${response.status()} ${response.url()}`);
|
|
if (new URL(response.url()).pathname.includes('/wip-wasm/')) {
|
|
assets.push({ url: response.url(), status: response.status() });
|
|
}
|
|
});
|
|
await page.route(base, async (route) => {
|
|
const response = await route.fetch();
|
|
const $ = load(await response.text());
|
|
$('[data-selected-content]').prepend('<p data-ssr-only>Not a WIP result</p>');
|
|
await route.fulfill({ response, body: $.html() });
|
|
});
|
|
await page.goto(base);
|
|
const stage = page.locator('[data-landing-stage]');
|
|
await expect(stage).toHaveAttribute('data-wip-state', 'ready');
|
|
await expect(page.locator('[data-ssr-only]')).toHaveCount(0);
|
|
await expect(page.locator('[data-selected-content]')).toHaveAttribute('data-wip-path', '/');
|
|
for (const counter of ['observes', 'interfaces', 'calls']) {
|
|
expect(Number(await stage.getAttribute(`data-wip-${counter}`))).toBeGreaterThan(0);
|
|
}
|
|
const calls = Number(await stage.getAttribute('data-wip-calls'));
|
|
await page.locator('.demo-node[data-path="/book"]').click();
|
|
await expect(page).toHaveURL(new URL('book/', base).href);
|
|
await expect(stage).toHaveAttribute('data-wip-state', 'ready');
|
|
await expect(page.locator('[data-selected-content]')).toHaveAttribute('data-wip-path', '/book');
|
|
expect(Number(await stage.getAttribute('data-wip-calls'))).toBe(calls + 1);
|
|
expect(assets.map(({ url }) => url).sort()).toEqual([
|
|
new URL('wip-wasm/wip_browser.js', base).href,
|
|
new URL('wip-wasm/wip_browser_bg.wasm', base).href,
|
|
].sort());
|
|
expect(assets.every(({ status }) => status === 200)).toBe(true);
|
|
await expect(page.locator('vite-error-overlay')).toHaveCount(0);
|
|
expect(errors).toEqual([]);
|
|
});
|