/* eslint-env jest */ import { waitFor } from 'next-test-utils' import path from 'path' import { nextTestSetup } from 'e2e-utils' describe('updating while client routing', () => { const { next } = nextTestSetup({ files: path.join(__dirname, 'fixture'), }) it.each([true, false])( 'should handle boolean async prop in next/head client-side: %s', async (bool) => { const browser = await next.browser('/head') const value = await browser.eval( `document.querySelector('script[src="/test-async-${JSON.stringify( bool )}.js"]').async` ) expect(value).toBe(bool) } ) it('should only execute async and defer scripts once', async () => { const browser = await next.browser('/head') await browser.waitForElementByCss('h1') await waitFor(2000) expect(Number(await browser.eval('window.__test_async_executions'))).toBe(1) expect(Number(await browser.eval('window.__test_defer_executions'))).toBe(1) await browser.elementByCss('#reverseScriptOrder').click() await waitFor(2000) expect(Number(await browser.eval('window.__test_async_executions'))).toBe(1) expect(Number(await browser.eval('window.__test_defer_executions'))).toBe(1) await browser.elementByCss('#toggleScript').click() await waitFor(2000) expect(Number(await browser.eval('window.__test_async_executions'))).toBe(1) expect(Number(await browser.eval('window.__test_defer_executions'))).toBe(1) }) it('should warn when stylesheets or scripts are in head', async () => { const browser = await next.browser('/head') await browser.waitForElementByCss('h1') await waitFor(1000) const browserLogs = await browser.log() let foundStyles = false let foundScripts = false const logs = [] browserLogs.forEach(({ message }) => { if (message.includes('Do not add stylesheets using next/head')) { foundStyles = true logs.push(message) } if (message.includes('Do not add