(context, isProd = false)
| 15 | import { check } from 'next-test-utils' |
| 16 | |
| 17 | const 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 | |
| 72 | const context: any = {} |
| 73 | const appDir = join(__dirname, '../') |
no test coverage detected