Unverified Commit ddc26c99 authored by OJ Kwon's avatar OJ Kwon Committed by GitHub

test(turbopack): migrate 404-related tests from next-dev (#55243)




Closes WEB-1535
parent 476fe4a1
import { useTestHarness } from '@turbo/pack-test-harness'
export default function ErrorPage(props: { static: 'static' }) {
useTestHarness((harness) => harness.markAsHydrated())
return <div data-test-error>{props.static}</div>
}
export function getStaticProps() {
return {
props: {
static: 'static',
},
}
}
import { useRef } from 'react'
import { Harness, useTestHarness } from '@turbo/pack-test-harness'
export default function Page() {
const iframeRef = useRef<HTMLIFrameElement | null>(null)
useTestHarness((harness) => runTests(harness, iframeRef.current!))
return (
<iframe style={{ width: 800, height: 600 }} src="/link" ref={iframeRef} />
)
}
function runTests(harness: Harness, iframe: HTMLIFrameElement) {
// These tests requires a longer timeout because we're rendering the 404 page as well.
const TIMEOUT = 20000
it(
'returns a 404 status code',
async () => {
const res = await fetch('/not-found')
expect(res.status).toBe(404)
},
TIMEOUT
)
it(
'navigates to the 404 page',
async () => {
await harness.waitForHydration(iframe, '/link')
const link = iframe.contentDocument!.querySelector('a[data-test-link]')
expect(link).not.toBeNull()
expect(link!).toBeInstanceOf(
(iframe.contentWindow as any).HTMLAnchorElement
)
expect(link!.textContent).toBe('Not found')
;(link as HTMLAnchorElement).click()
await harness.waitForHydration(iframe, '/not-found')
const error = iframe.contentDocument!.querySelector('[data-test-error]')
expect(error).not.toBeNull()
expect(error!.textContent).toBe('static')
},
TIMEOUT
)
}
import Link from 'next/link'
import { useTestHarness } from '@turbo/pack-test-harness'
export default function Page() {
useTestHarness((mod) => mod.markAsHydrated())
return (
<Link href="/not-found" data-test-link>
Not found
</Link>
)
}
export default function Page() {
return <div>Page</div>
}
export function getStaticProps() {
return {
notFound: true,
}
}
...@@ -109,6 +109,10 @@ const enabledTests = [ ...@@ -109,6 +109,10 @@ const enabledTests = [
'test/e2e/typescript-version-no-warning/typescript-version-no-warning.test.ts', 'test/e2e/typescript-version-no-warning/typescript-version-no-warning.test.ts',
'test/e2e/typescript-version-warning/typescript-version-warning.test.ts', 'test/e2e/typescript-version-warning/typescript-version-warning.test.ts',
'test/e2e/undici-fetch/index.test.ts', 'test/e2e/undici-fetch/index.test.ts',
'test/integration/404-page/test/index.test.js',
'test/integration/404-page-app/test/index.test.js',
'test/integration/404-page-custom-error/test/index.test.js',
'test/integration/404-page-ssg/test/index.test.js',
'test/integration/create-next-app/templates-app.test.ts', 'test/integration/create-next-app/templates-app.test.ts',
'test/integration/create-next-app/templates-pages.test.ts', 'test/integration/create-next-app/templates-pages.test.ts',
'test/integration/custom-routes-i18n-index-redirect/test/index.test.js', 'test/integration/custom-routes-i18n-index-redirect/test/index.test.js',
......
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