MCPcopy
hub / github.com/vercel/next.js / clientNavigation

Function clientNavigation

test/integration/client-404/test/index.test.ts:17–70  ·  view source on GitHub ↗
(context, isProd = false)

Source from the content-addressed store, hash-verified

15import { check } from 'next-test-utils'
16
17const clientNavigation = (context, isProd = false) => {
18 describe('Client Navigation 404', () => {
19 describe('should show 404 upon client replacestate', () => {
20 it('should navigate the page', async () => {
21 const browser = await webdriver(context.appPort, '/asd')
22 const serverCode = await browser
23 .waitForElementByCss('#errorStatusCode')
24 .text()
25 await browser.waitForElementByCss('#errorGoHome').click()
26 await browser.waitForElementByCss('#hellom8').back()
27 const clientCode = await browser
28 .waitForElementByCss('#errorStatusCode')
29 .text()
30
31 expect({ serverCode, clientCode }).toMatchObject({
32 serverCode: '404',
33 clientCode: '404',
34 })
35 await browser.close()
36 })
37 })
38
39 it('should hard navigate to URL on failing to load bundle', async () => {
40 const browser = await webdriver(context.appPort, '/invalid-link')
41 await browser.eval(() => ((window as any).beforeNav = 'hi'))
42 await browser.elementByCss('#to-nonexistent').click()
43 await check(() => browser.elementByCss('#errorStatusCode').text(), /404/)
44 expect(await browser.eval(() => (window as any).beforeNav)).not.toBe('hi')
45 })
46
47 if (isProd) {
48 it('should hard navigate to URL on failing to load missing bundle', async () => {
49 let chunk = getClientBuildManifestLoaderChunkUrlPath(appDir, '/missing')
50 const browser = await webdriver(context.appPort, '/to-missing-link', {
51 beforePageLoad(page) {
52 page.route(`**/${chunk}*`, (route) => {
53 route.abort('internetdisconnected')
54 })
55 },
56 })
57 await browser.eval(() => ((window as any).beforeNav = 'hi'))
58 await browser.elementByCss('#to-missing').click()
59
60 await retry(async () => {
61 expect(await browser.url()).toContain('/missing')
62 })
63 expect(await browser.elementByCss('#missing').text()).toBe('poof')
64 expect(await browser.eval(() => (window as any).beforeNav)).not.toBe(
65 'hi'
66 )
67 })
68 }
69 })
70}
71
72const context: any = {}
73const appDir = join(__dirname, '../')

Callers 1

runTestsFunction · 0.85

Calls 15

checkFunction · 0.90
retryFunction · 0.90
describeFunction · 0.85
webdriverFunction · 0.85
waitForElementByCssMethod · 0.80
clickMethod · 0.80
evalMethod · 0.80
elementByCssMethod · 0.80
textMethod · 0.65
backMethod · 0.65
closeMethod · 0.65

Tested by

no test coverage detected