|
|
import { Server } from 'http' |
|
|
import { |
|
|
findPort, |
|
|
nextBuild, |
|
|
startStaticServer, |
|
|
stopApp, |
|
|
} from 'next-test-utils' |
|
|
import webdriver from 'next-webdriver' |
|
|
import { join } from 'path' |
|
|
|
|
|
const itHeaded = process.env.HEADLESS ? it.skip : it |
|
|
|
|
|
describe('bfcache-routing', () => { |
|
|
let port: number |
|
|
let app: Server |
|
|
|
|
|
beforeAll(async () => { |
|
|
const appDir = __dirname |
|
|
const exportDir = join(appDir, 'out') |
|
|
|
|
|
await nextBuild(appDir, undefined, { cwd: appDir }) |
|
|
port = await findPort() |
|
|
app = await startStaticServer(exportDir, undefined, port) |
|
|
}) |
|
|
|
|
|
afterAll(() => { |
|
|
stopApp(app) |
|
|
}) |
|
|
|
|
|
itHeaded( |
|
|
'should not suspend indefinitely when page is restored from bfcache after an mpa navigation', |
|
|
async () => { |
|
|
|
|
|
|
|
|
|
|
|
const browser = await webdriver(port, '/index.html', { headless: false }) |
|
|
|
|
|
|
|
|
const bfOptions = { waitUntil: 'commit' as const } |
|
|
|
|
|
await browser.elementByCss('a[href="https://example.vercel.sh"]').click() |
|
|
await browser.waitForCondition( |
|
|
'window.location.origin === "https://example.vercel.sh"' |
|
|
) |
|
|
|
|
|
await browser.back(bfOptions) |
|
|
|
|
|
await browser.waitForCondition( |
|
|
'window.location.origin.includes("localhost")' |
|
|
) |
|
|
|
|
|
let html = await browser.eval<string>( |
|
|
'document.documentElement.innerHTML' |
|
|
) |
|
|
|
|
|
expect(html).toContain('BFCache Test') |
|
|
|
|
|
await browser.eval(`document.querySelector('button').click()`) |
|
|
|
|
|
|
|
|
html = await browser.eval<string>('document.documentElement.innerHTML') |
|
|
expect(html).toContain('BFCache Test') |
|
|
|
|
|
await browser.forward(bfOptions) |
|
|
await browser.back(bfOptions) |
|
|
|
|
|
await browser.waitForCondition( |
|
|
'window.location.origin.includes("localhost")' |
|
|
) |
|
|
|
|
|
|
|
|
html = await browser.eval<string>('document.documentElement.innerHTML') |
|
|
expect(html).toContain('BFCache Test') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await browser.eval( |
|
|
`document.querySelector('a[href="https://example.vercel.sh"]').click()` |
|
|
) |
|
|
await browser.waitForCondition( |
|
|
'window.location.origin === "https://example.vercel.sh"' |
|
|
) |
|
|
} |
|
|
) |
|
|
}) |
|
|
|