// @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); });