55 lines
3.1 KiB
JavaScript
55 lines
3.1 KiB
JavaScript
// @ts-check
|
|
// Section-specific feature code should not be fetched until its section is opened.
|
|
const { test, expect } = require('@playwright/test');
|
|
|
|
test('heavy feature modules load on demand', async ({ page }) => {
|
|
const requests = [];
|
|
page.on('request', request => {
|
|
if (request.url().includes('/static/js/')) requests.push(request.url());
|
|
});
|
|
|
|
await page.goto('/', { waitUntil: 'domcontentloaded' });
|
|
await page.waitForFunction(() => typeof window.navTo === 'function', null, { timeout: 15_000 });
|
|
await page.waitForSelector('#app-skeleton', { state: 'detached', timeout: 15_000 });
|
|
expect(requests.some(url => url.includes('/rehearser.js'))).toBeFalsy();
|
|
expect(requests.some(url => url.includes('/library-characters.js'))).toBeFalsy();
|
|
|
|
await page.evaluate(() => window.navTo('s-rehearser'));
|
|
await page.waitForFunction(() => window.rehState?.synthCache, null, { timeout: 15_000 });
|
|
expect(requests.some(url => url.includes('/rehearser.js'))).toBeTruthy();
|
|
|
|
const countBeforeRepeat = requests.filter(url => url.includes('/rehearser.js')).length;
|
|
await page.evaluate(() => window.navTo('s-rehearser'));
|
|
await page.waitForTimeout(100);
|
|
expect(requests.filter(url => url.includes('/rehearser.js')).length).toBe(countBeforeRepeat);
|
|
});
|
|
|
|
test('Audiobook lazy modules publish their namespace APIs after loading', async ({ page }) => {
|
|
await page.goto('/', { waitUntil: 'domcontentloaded' });
|
|
await page.waitForFunction(() => typeof window.navTo === 'function', null, { timeout: 15_000 });
|
|
await page.waitForSelector('#app-skeleton', { state: 'detached', timeout: 15_000 });
|
|
await page.evaluate(() => window.navTo('s-reader'));
|
|
await page.waitForFunction(() => typeof window.audiobookCastView === 'function', null, { timeout: 15_000 });
|
|
await expect.poll(() => page.evaluate(() => ({
|
|
castView: typeof window.TTVC?.audiobook?.cast?.castView,
|
|
stream: typeof window.TTVC?.audiobook?.attributeStream,
|
|
startCast: typeof window.TTVC?.audiobook?.startCast,
|
|
pipelineCast: typeof window.TTVC?.audiobook?.pipeline?.cast,
|
|
}))).toEqual({ castView: 'function', stream: 'function', startCast: 'function', pipelineCast: 'function' });
|
|
});
|
|
|
|
test('Rehearser playback module publishes transport APIs after loading', async ({ page }) => {
|
|
await page.goto('/', { waitUntil: 'domcontentloaded' });
|
|
await page.waitForFunction(() => typeof window.navTo === 'function', null, { timeout: 15_000 });
|
|
await page.waitForSelector('#app-skeleton', { state: 'detached', timeout: 15_000 });
|
|
await page.evaluate(() => window.navTo('s-rehearser'));
|
|
await page.waitForFunction(() => window.rehState?.synthCache, null, { timeout: 15_000 });
|
|
await expect.poll(() => page.evaluate(() => ({
|
|
start: typeof window.TTVC?.rehearser?.playback?.start,
|
|
stop: typeof window.TTVC?.rehearser?.playback?.stop,
|
|
synthAll: typeof window.TTVC?.rehearser?.playback?.synthAll,
|
|
loadRecord: typeof window.TTVC?.rehearser?.io?.loadRecord,
|
|
exportSession: typeof window.TTVC?.rehearser?.io?.exportSession,
|
|
}))).toEqual({ start: 'function', stop: 'function', synthAll: 'function', loadRecord: 'function', exportSession: 'function' });
|
|
});
|