mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
In development when handling the page request, we are sending the parsedUrl with the basePath stripped but not assetPrefix. As a result, when setting an assetPrefix, the chunk would 404 which causes a hard nav. It'd then recover and work correctly on subsequent navs. This applies the exact same handling we had for basePath, but for assetPrefix. Fixes #77241
51 lines
1.7 KiB
TypeScript
51 lines
1.7 KiB
TypeScript
import { join } from 'path'
|
|
import { nextTestSetup } from 'e2e-utils'
|
|
import { check, retry } from 'next-test-utils'
|
|
|
|
describe('asset-prefix', () => {
|
|
const { next } = nextTestSetup({
|
|
files: join(__dirname, 'fixture'),
|
|
})
|
|
|
|
it('should load the app properly without reloading', async () => {
|
|
const browser = await next.browser('/')
|
|
await browser.eval(`window.__v = 1`)
|
|
|
|
expect(await browser.elementByCss('#text').text()).toBe('Hello World')
|
|
|
|
await check(async () => {
|
|
const logs = await browser.log()
|
|
const hasError = logs.some((log) =>
|
|
log.message.includes('Failed to fetch')
|
|
)
|
|
return hasError ? 'error' : 'success'
|
|
}, 'success')
|
|
|
|
expect(await browser.eval(`window.__v`)).toBe(1)
|
|
})
|
|
|
|
it('should navigate to another page without hard navigating', async () => {
|
|
const browser = await next.browser('/')
|
|
await browser.eval(`window.__v = 1`)
|
|
await browser.elementByCss('[href="/page2"]').click()
|
|
await retry(async () => {
|
|
expect(await browser.elementByCss('div').text()).toBe('Page 2')
|
|
})
|
|
expect(await browser.eval(`window.__v`)).toBe(1)
|
|
})
|
|
|
|
describe('rewrites', () => {
|
|
it('rewrites that do not start with assetPrefix should still work', async () => {
|
|
const res = await next.fetch('/not-custom-asset-prefix/api/test-json', {})
|
|
expect(res.status).toBe(200)
|
|
expect(await res.text()).toBe('{"message":"test"}')
|
|
})
|
|
|
|
it('should respect rewrites that start with assetPrefix', async () => {
|
|
const res = await next.fetch('/custom-asset-prefix/api/test-json', {})
|
|
expect(res.status).toBe(200)
|
|
expect(await res.text()).toBe('{"message":"test"}')
|
|
})
|
|
})
|
|
})
|