a1d830eec8
Ensures we delete the prefetch header when the path is static as it can't be honored and the full tree must be sent instead. ## Bug - [x] Related issues linked using `fixes #number` - [x] Integration tests added - [ ] Errors have a helpful link attached, see `contributing.md` x-ref: [slack thread](https://vercel.slack.com/archives/C035J346QQL/p1665610012952039?thread_ts=1665582783.184029&cid=C035J346QQL)
67 lines
2.1 KiB
TypeScript
67 lines
2.1 KiB
TypeScript
import { createNext, FileRef } from 'e2e-utils'
|
|
import { NextInstance } from 'test/lib/next-modes/base'
|
|
import { waitFor } from 'next-test-utils'
|
|
import path from 'path'
|
|
import webdriver from 'next-webdriver'
|
|
|
|
describe('app dir prefetching', () => {
|
|
// TODO: re-enable for dev after https://vercel.slack.com/archives/C035J346QQL/p1663822388387959 is resolved (Sep 22nd 2022)
|
|
if ((global as any).isNextDeploy || (global as any).isNextDev) {
|
|
it('should skip next deploy for now', () => {})
|
|
return
|
|
}
|
|
|
|
if (process.env.NEXT_TEST_REACT_VERSION === '^17') {
|
|
it('should skip for react v17', () => {})
|
|
return
|
|
}
|
|
let next: NextInstance
|
|
|
|
beforeAll(async () => {
|
|
next = await createNext({
|
|
files: new FileRef(path.join(__dirname, 'app-prefetch')),
|
|
dependencies: {
|
|
react: 'experimental',
|
|
'react-dom': 'experimental',
|
|
},
|
|
skipStart: true,
|
|
})
|
|
await next.start()
|
|
})
|
|
afterAll(() => next.destroy())
|
|
|
|
it('should show layout eagerly when prefetched with loading one level down', async () => {
|
|
const browser = await webdriver(next.url, '/')
|
|
// Ensure the page is prefetched
|
|
await waitFor(1000)
|
|
|
|
const before = Date.now()
|
|
await browser
|
|
.elementByCss('#to-dashboard')
|
|
.click()
|
|
.waitForElementByCss('#dashboard-layout')
|
|
const after = Date.now()
|
|
const timeToComplete = after - before
|
|
|
|
expect(timeToComplete < 1000).toBe(true)
|
|
|
|
expect(await browser.elementByCss('#dashboard-layout').text()).toBe(
|
|
'Dashboard Hello World'
|
|
)
|
|
|
|
await browser.waitForElementByCss('#dashboard-page')
|
|
|
|
expect(await browser.waitForElementByCss('#dashboard-page').text()).toBe(
|
|
'Welcome to the dashboard'
|
|
)
|
|
})
|
|
|
|
it('should not have prefetch error for static path', async () => {
|
|
const browser = await webdriver(next.url, '/')
|
|
await browser.eval('window.nd.router.prefetch("/dashboard/123")')
|
|
await waitFor(3000)
|
|
await browser.eval('window.nd.router.push("/dashboard/123")')
|
|
expect(next.cliOutput).not.toContain('ReferenceError')
|
|
expect(next.cliOutput).not.toContain('is not defined')
|
|
})
|
|
})
|