tts-voice-creator-clone-and.../tests/constrained.spec.js

64 lines
3.3 KiB
JavaScript

// @ts-check
// Lightweight constrained-device regression: the browser's 4 GB profile must
// reduce shared batch concurrency before multiple audio/image operations run.
const { test, expect } = require('@playwright/test');
test('4 GB browser profile caps shared batch concurrency at two', async ({ page }) => {
await page.goto('/', { waitUntil: 'domcontentloaded' });
await page.waitForFunction(() => typeof window.runPool === 'function', null, { timeout: 15_000 });
const maxActive = await page.evaluate(async () => {
Object.defineProperty(navigator, 'deviceMemory', { configurable: true, value: 4 });
let active = 0;
let max = 0;
await window.runPool(Array.from({ length: 8 }, (_, i) => i), async () => {
active += 1;
max = Math.max(max, active);
await new Promise(resolve => setTimeout(resolve, 15));
active -= 1;
}, 4);
return max;
});
expect(maxActive).toBeLessThanOrEqual(2);
});
test('large character productions keep the rendered DOM paginated', async ({ page }) => {
const characters = Array.from({ length: 250 }, (_, index) => ({
id: 'large-' + index, book: 'Large Smoke Book', name: 'Character ' + index,
tags: '', voice: null, sheet: { gender: index % 2 ? 'F' : 'M' },
}));
await page.route('**/api/characters*', route => route.fulfill({ json: { characters } }));
await page.route('**/api/voices*', route => route.fulfill({ json: [] }));
await page.route('**/api/settings*', route => route.fulfill({ json: {} }));
await page.goto('/', { waitUntil: 'domcontentloaded' });
await page.waitForFunction(() => typeof window.libraryRenderCharacters === 'function', null, { timeout: 15_000 });
await page.waitForSelector('#lib-chars-list', { state: 'attached', timeout: 15_000 });
await page.waitForSelector('#app-skeleton', { state: 'detached', timeout: 15_000 });
await page.evaluate(() => window.navTo('s-library'));
await page.locator('.lib-tab[data-library-view="characters"]').click();
await expect.poll(() => page.locator('#lib-chars-list .lib-char-card').count()).toBeLessThanOrEqual(50);
await page.locator('#lib-chars-list .lib-chars-load-more').click();
await expect.poll(() => page.locator('#lib-chars-list .lib-char-card').count()).toBeLessThanOrEqual(100);
});
test('desktop navigation remains usable under Chrome CPU throttling', async ({ page }, testInfo) => {
test.skip(testInfo.project.name !== 'desktop', 'Chromium CDP throttling is a desktop measurement');
const cdp = await page.context().newCDPSession(page);
await cdp.send('Emulation.setCPUThrottlingRate', { rate: 4 });
try {
await page.goto('/', { waitUntil: 'domcontentloaded' });
await page.waitForSelector('#app-skeleton', { state: 'detached', timeout: 20_000 });
await page.evaluate(() => window.navTo('s-performance'));
await expect(page.locator('#background-jobs-card')).toBeVisible({ timeout: 15_000 });
const metrics = await page.evaluate(() => ({
domNodes: document.getElementsByTagName('*').length,
audioElements: document.querySelectorAll('audio').length,
jsHeapBytes: performance.memory?.usedJSHeapSize || null,
}));
expect(metrics.domNodes).toBeLessThan(20_000);
expect(metrics.audioElements).toBeLessThan(64);
} finally {
await cdp.send('Emulation.setCPUThrottlingRate', { rate: 1 }).catch(() => {});
await cdp.detach().catch(() => {});
}
});