Unverified Commit 3f9f403a authored by Benjamin Woodruff's avatar Benjamin Woodruff Committed by GitHub

chore(CI): Split basepath test suite into smaller and more parallel test suites (#78892)

Same basic idea as https://github.com/vercel/next.js/pull/78787

This test suite has a lot of timeouts with rspack, which causes it to take a long time to run (though not quite long enough that it breaks the job).

In general, large test suites are good to break up, because they benefit from parallelism.
parent 140a2662
......@@ -801,7 +801,8 @@ jobs:
NEXT_TEST_MODE=start BROWSER_NAME=safari node run-tests.js \
test/production/pages-dir/production/test/index.test.ts \
test/e2e/basepath/basepath.test.ts
test/e2e/basepath/basepath.test.ts \
test/e2e/basepath/error-pages.test.ts
BROWSER_NAME=safari DEVICE_NAME='iPhone XR' node run-tests.js \
test/production/prerender-prefetch/index.test.ts
......
This diff is collapsed.
import webdriver from 'next-webdriver'
import { nextTestSetup } from 'e2e-utils'
import { check, renderViaHTTP } from 'next-test-utils'
describe('basePath', () => {
const basePath = '/docs'
const { next, isNextDeploy } = nextTestSetup({
files: __dirname,
nextConfig: {
basePath,
onDemandEntries: {
// Make sure entries are not getting disposed.
maxInactiveAge: 1000 * 60 * 60,
},
},
})
describe('client-side navigation', () => {
it('should navigate to /404 correctly client-side', async () => {
const browser = await webdriver(next.url, `${basePath}/slug-1`)
await check(
() => browser.eval('document.documentElement.innerHTML'),
/slug-1/
)
await browser.eval('next.router.push("/404", "/slug-2")')
await check(
() => browser.eval('document.documentElement.innerHTML'),
/page could not be found/
)
expect(await browser.eval('location.pathname')).toBe(`${basePath}/slug-2`)
})
it('should navigate to /_error correctly client-side', async () => {
const browser = await webdriver(next.url, `${basePath}/slug-1`)
await check(
() => browser.eval('document.documentElement.innerHTML'),
/slug-1/
)
await browser.eval('next.router.push("/_error", "/slug-2")')
await check(
() => browser.eval('document.documentElement.innerHTML'),
/page could not be found/
)
expect(await browser.eval('location.pathname')).toBe(`${basePath}/slug-2`)
})
})
if (process.env.BROWSER_NAME === 'safari') {
// currently only testing the above tests in safari
// we can investigate testing more cases below if desired
return
}
it('should not update URL for a 404', async () => {
const browser = await webdriver(next.url, '/missing')
if (isNextDeploy) {
// the custom 404 only shows inside of the basePath so this
// will be the Vercel default 404 page
expect(
await browser.eval('document.documentElement.innerHTML')
).toContain('NOT_FOUND')
} else {
const pathname = await browser.eval(() => window.location.pathname)
expect(await browser.eval(() => (window as any).next.router.asPath)).toBe(
'/missing'
)
expect(pathname).toBe('/missing')
}
})
it('should handle 404 urls that start with basePath', async () => {
const browser = await webdriver(next.url, `${basePath}hello`)
if (isNextDeploy) {
// the custom 404 only shows inside of the basePath so this
// will be the Vercel default 404 page
expect(
await browser.eval('document.documentElement.innerHTML')
).toContain('404: This page could not be found')
} else {
expect(await browser.eval(() => (window as any).next.router.asPath)).toBe(
`${basePath}hello`
)
expect(await browser.eval(() => window.location.pathname)).toBe(
`${basePath}hello`
)
}
})
// TODO: this test has been passing incorrectly since the below check
// wasn't being awaited. We need to investigate if this test is
// correct or not.
it.skip('should navigate back to a non-basepath 404 that starts with basepath', async () => {
const browser = await webdriver(next.url, `${basePath}hello`)
await browser.eval(() => ((window as any).navigationMarker = true))
await browser.eval(() => (window as any).next.router.push('/hello'))
await browser.waitForElementByCss('#pathname')
await browser.back()
await check(
() => browser.eval(() => window.location.pathname),
`${basePath}hello`
)
expect(await browser.eval(() => (window as any).next.router.asPath)).toBe(
`${basePath}hello`
)
expect(await browser.eval(() => (window as any).navigationMarker)).toBe(
true
)
})
describe('manually added basePath in application logic', () => {
it('should 404 when manually adding basePath with <Link>', async () => {
const browser = await webdriver(
next.url,
`${basePath}/invalid-manual-basepath`
)
await browser.eval('window.beforeNav = "hi"')
await browser.elementByCss('#other-page-link').click()
await check(() => browser.eval('window.beforeNav'), {
test(content) {
return content !== 'hi'
},
})
await check(
() => browser.eval('document.documentElement.innerHTML'),
/This page could not be found/
)
})
it('should 404 when manually adding basePath with router.push', async () => {
const browser = await webdriver(next.url, `${basePath}/hello`)
await browser.eval('window.beforeNav = "hi"')
await browser.eval(`window.next.router.push("${basePath}/other-page")`)
await check(() => browser.eval('window.beforeNav'), {
test(content) {
return content !== 'hi'
},
})
const html = await browser.eval('document.documentElement.innerHTML')
expect(html).toContain('This page could not be found')
})
it('should 404 when manually adding basePath with router.replace', async () => {
const browser = await webdriver(next.url, `${basePath}/hello`)
await browser.eval('window.beforeNav = "hi"')
await browser.eval(`window.next.router.replace("${basePath}/other-page")`)
await check(() => browser.eval('window.beforeNav'), {
test(content) {
return content !== 'hi'
},
})
const html = await browser.eval('document.documentElement.innerHTML')
expect(html).toContain('This page could not be found')
})
})
it('should show 404 for page not under the /docs prefix', async () => {
const text = await renderViaHTTP(next.url, '/hello')
expect(text).not.toContain('Hello World')
expect(text).toContain(
isNextDeploy ? 'NOT_FOUND' : 'This page could not be found'
)
})
})
......@@ -42,7 +42,9 @@ function Page() {
</Link>
<br />
<div id="base-path">{router.basePath}</div>
<div id="pathname">{routerObj.pathname}</div>
<div id="pathname" suppressHydrationWarning>
{routerObj.pathname}
</div>
<div
id="trigger-error"
onClick={() => {
......@@ -52,7 +54,9 @@ function Page() {
click me for error
</div>
<br />
<div id="as-path">{routerObj.asPath}</div>
<div id="as-path" suppressHydrationWarning>
{routerObj.asPath}
</div>
<Link href="/slow-route" id="slow-route">
<h1>Slow route</h1>
</Link>
......
import webdriver from 'next-webdriver'
import { check } from 'next-test-utils'
import { nextTestSetup } from 'e2e-utils'
describe('basePath query/hash handling', () => {
const basePath = '/docs'
const { next } = nextTestSetup({
files: __dirname,
nextConfig: {
basePath,
onDemandEntries: {
// Make sure entries are not getting disposed.
maxInactiveAge: 1000 * 60 * 60,
},
},
})
it.each([
{ hash: '#hello?' },
{ hash: '#?' },
{ hash: '##' },
{ hash: '##?' },
{ hash: '##hello?' },
{ hash: '##hello' },
{ hash: '#hello?world' },
{ search: '?hello=world', hash: '#a', query: { hello: 'world' } },
{ search: '?hello', hash: '#a', query: { hello: '' } },
{ search: '?hello=', hash: '#a', query: { hello: '' } },
])(
'is correct during query updating $hash $search',
async ({ hash, search, query }) => {
const browser = await webdriver(
next.url,
`${basePath}${search || ''}${hash || ''}`
)
await check(
() =>
browser.eval('window.next.router.isReady ? "ready" : "not ready"'),
'ready'
)
expect(await browser.eval('window.location.pathname')).toBe(basePath)
expect(await browser.eval('window.location.search')).toBe(search || '')
expect(await browser.eval('window.location.hash')).toBe(hash || '')
expect(await browser.eval('next.router.pathname')).toBe('/')
expect(
JSON.parse(await browser.eval('JSON.stringify(next.router.query)'))
).toEqual(query || {})
}
)
it('should work with hash links', async () => {
const browser = await webdriver(next.url, `${basePath}/hello`)
await browser.elementByCss('#hashlink').click()
const url = new URL(await browser.eval(() => window.location.href))
expect(url.pathname).toBe(`${basePath}/hello`)
expect(url.hash).toBe('#hashlink')
})
})
import url from 'url'
import { nextTestSetup } from 'e2e-utils'
import { fetchViaHTTP, renderViaHTTP } from 'next-test-utils'
describe('basePath', () => {
const basePath = '/docs'
const { next, isNextDeploy } = nextTestSetup({
files: __dirname,
nextConfig: {
basePath,
onDemandEntries: {
// Make sure entries are not getting disposed.
maxInactiveAge: 1000 * 60 * 60,
},
async rewrites() {
return [
{
source: '/rewrite-1',
destination: '/gssp',
},
{
source: '/rewrite-no-basepath',
destination: 'https://example.vercel.sh',
basePath: false,
},
{
source: '/rewrite/chain-1',
destination: '/rewrite/chain-2',
},
{
source: '/rewrite/chain-2',
destination: '/gssp',
},
]
},
async redirects() {
return [
{
source: '/redirect-1',
destination: '/somewhere-else',
permanent: false,
},
{
source: '/redirect-no-basepath',
destination: '/another-destination',
permanent: false,
basePath: false,
},
]
},
async headers() {
return [
{
source: '/add-header',
headers: [
{
key: 'x-hello',
value: 'world',
},
],
},
{
source: '/add-header-no-basepath',
basePath: false,
headers: [
{
key: 'x-hello',
value: 'world',
},
],
},
]
},
},
})
it('should rewrite with basePath by default', async () => {
const html = await renderViaHTTP(next.url, `${basePath}/rewrite-1`)
expect(html).toContain('getServerSideProps')
})
it('should not rewrite without basePath without disabling', async () => {
const res = await fetchViaHTTP(next.url, '/rewrite-1')
expect(res.status).toBe(404)
})
it('should not rewrite with basePath when set to false', async () => {
// won't 404 as it matches the dynamic [slug] route
const html = await renderViaHTTP(
next.url,
`${basePath}/rewrite-no-basePath`
)
expect(html).toContain('slug')
})
it('should rewrite without basePath when set to false', async () => {
const html = await renderViaHTTP(next.url, '/rewrite-no-basePath')
expect(html).toContain('Example Domain')
})
it('should redirect with basePath by default', async () => {
const res = await fetchViaHTTP(
next.url,
`${basePath}/redirect-1`,
undefined,
{
redirect: 'manual',
}
)
const { pathname } = url.parse(res.headers.get('location') || '')
expect(pathname).toBe(`${basePath}/somewhere-else`)
expect(res.status).toBe(307)
const text = await res.text()
if (!isNextDeploy) {
expect(text).toContain(`${basePath}/somewhere-else`)
}
})
it('should not redirect without basePath without disabling', async () => {
const res = await fetchViaHTTP(next.url, '/redirect-1', undefined, {
redirect: 'manual',
})
expect(res.status).toBe(404)
})
it('should not redirect with basePath when set to false', async () => {
// won't 404 as it matches the dynamic [slug] route
const html = await renderViaHTTP(
next.url,
`${basePath}/rewrite-no-basePath`
)
expect(html).toContain('slug')
})
it('should redirect without basePath when set to false', async () => {
const res = await fetchViaHTTP(
next.url,
'/redirect-no-basepath',
undefined,
{
redirect: 'manual',
}
)
const { pathname } = url.parse(res.headers.get('location') || '')
expect(pathname).toBe('/another-destination')
expect(res.status).toBe(307)
const text = await res.text()
if (!isNextDeploy) {
expect(text).toContain('/another-destination')
}
})
})
import assert from 'assert'
import webdriver from 'next-webdriver'
import { nextTestSetup } from 'e2e-utils'
import { check, retry } from 'next-test-utils'
describe('basePath', () => {
const basePath = '/docs'
const { next } = nextTestSetup({
files: __dirname,
nextConfig: {
basePath,
onDemandEntries: {
// Make sure entries are not getting disposed.
maxInactiveAge: 1000 * 60 * 60,
},
},
})
it('should use urls with basepath in router events', async () => {
const browser = await webdriver(next.url, `${basePath}/hello`)
try {
await check(
() => browser.eval('window.next.router.isReady ? "ready" : "no"'),
'ready'
)
await browser.eval('window._clearEventLog()')
await browser
.elementByCss('#other-page-link')
.click()
.waitForElementByCss('#other-page-title')
const eventLog = await browser.eval('window._getEventLog()')
expect(
eventLog.filter((item) => item[1]?.endsWith('/other-page'))
).toEqual([
['routeChangeStart', `${basePath}/other-page`, { shallow: false }],
['beforeHistoryChange', `${basePath}/other-page`, { shallow: false }],
['routeChangeComplete', `${basePath}/other-page`, { shallow: false }],
])
} finally {
await browser.close()
}
})
it('should use urls with basepath in router events for hash changes', async () => {
const browser = await webdriver(next.url, `${basePath}/hello`)
try {
await check(
() => browser.eval('window.next.router.isReady ? "ready" : "no"'),
'ready'
)
await browser.eval('window._clearEventLog()')
await browser.elementByCss('#hash-change').click()
const eventLog = await browser.eval('window._getEventLog()')
expect(eventLog).toEqual([
['hashChangeStart', `${basePath}/hello#some-hash`, { shallow: false }],
[
'hashChangeComplete',
`${basePath}/hello#some-hash`,
{ shallow: false },
],
])
} finally {
await browser.close()
}
})
it('should use urls with basepath in router events for cancelled routes', async () => {
const browser = await webdriver(next.url, `${basePath}/hello`)
try {
await check(
() => browser.eval('window.next.router.isReady ? "ready" : "no"'),
'ready'
)
await browser.eval('window._clearEventLog()')
await browser
.elementByCss('#slow-route')
.click()
.elementByCss('#other-page-link')
.click()
.waitForElementByCss('#other-page-title')
const eventLog = await browser.eval('window._getEventLog()')
expect(eventLog).toEqual([
['routeChangeStart', `${basePath}/slow-route`, { shallow: false }],
[
'routeChangeError',
'Route Cancelled',
true,
`${basePath}/slow-route`,
{ shallow: false },
],
['routeChangeStart', `${basePath}/other-page`, { shallow: false }],
['beforeHistoryChange', `${basePath}/other-page`, { shallow: false }],
['routeChangeComplete', `${basePath}/other-page`, { shallow: false }],
])
} finally {
await browser.close()
}
})
it('should use urls with basepath in router events for failed route change', async () => {
const browser = await webdriver(next.url, `${basePath}/hello`)
try {
await check(
() => browser.eval('window.next.router.isReady ? "ready" : "no"'),
'ready'
)
await browser.eval('window._clearEventLog()')
await browser.elementByCss('#error-route').click()
await retry(async () => {
const eventLog = await browser.eval('window._getEventLog()')
assert.deepEqual(eventLog, [
['routeChangeStart', `${basePath}/error-route`, { shallow: false }],
[
'routeChangeError',
'Failed to load static props',
null,
`${basePath}/error-route`,
{ shallow: false },
],
])
})
} finally {
await browser.close()
}
})
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment