Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test case for loading 404 on invalid bundle #14082

Merged
merged 1 commit into from
Jun 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions test/integration/client-404/pages/invalid-link.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Link from 'next/link'

export default () => (
<Link href="/[id]/non-existent" as="/another/non-existent">
<a id="to-nonexistent">to 404</a>
</Link>
)
9 changes: 9 additions & 0 deletions test/integration/client-404/test/client-navigation.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-env jest */
import webdriver from 'next-webdriver'
import { check } from 'next-test-utils'

export default (context) => {
describe('Client Navigation 404', () => {
Expand All @@ -22,5 +23,13 @@ export default (context) => {
await browser.close()
})
})

it('should hard navigate to URL on failing to load bundle', async () => {
const browser = await webdriver(context.appPort, '/invalid-link')
await browser.eval(() => (window.beforeNav = 'hi'))
await browser.elementByCss('#to-nonexistent').click()
await check(() => browser.elementByCss('#errorStatusCode').text(), /404/)
expect(await browser.eval(() => window.beforeNav)).not.toBe('hi')
})
})
}
41 changes: 33 additions & 8 deletions test/integration/client-404/test/index.test.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,48 @@
/* eslint-env jest */

import { join } from 'path'
import { renderViaHTTP, findPort, launchApp, killApp } from 'next-test-utils'
import {
renderViaHTTP,
findPort,
launchApp,
killApp,
nextBuild,
nextStart,
} from 'next-test-utils'

// test suite
import clientNavigation from './client-navigation'

const context = {}
const appDir = join(__dirname, '../')
jest.setTimeout(1000 * 60 * 5)

const runTests = () => {
clientNavigation(context, (p, q) => renderViaHTTP(context.appPort, p, q))
}

describe('Client 404', () => {
beforeAll(async () => {
context.appPort = await findPort()
context.server = await launchApp(join(__dirname, '../'), context.appPort)
describe('dev mode', () => {
beforeAll(async () => {
context.appPort = await findPort()
context.server = await launchApp(appDir, context.appPort)

// pre-build page at the start
await renderViaHTTP(context.appPort, '/')
})
afterAll(() => killApp(context.server))

// pre-build page at the start
await renderViaHTTP(context.appPort, '/')
runTests()
})
afterAll(() => killApp(context.server))

clientNavigation(context, (p, q) => renderViaHTTP(context.appPort, p, q))
describe('production mode', () => {
beforeAll(async () => {
await nextBuild(appDir)
context.appPort = await findPort()
context.server = await nextStart(appDir, context.appPort)
})
afterAll(() => killApp(context.server))

runTests()
})
})