Unverified Commit ba01f657 authored by Sebastian "Sebbie" Silbermann's avatar Sebastian "Sebbie" Silbermann Committed by GitHub

[test] Enable scroll related tests in Cache Component tests (#83245)

parent 24c6e3e4
...@@ -146,7 +146,6 @@ ...@@ -146,7 +146,6 @@
"test/e2e/app-dir/app/useReportWebVitals.test.ts", "test/e2e/app-dir/app/useReportWebVitals.test.ts",
"test/e2e/app-dir/bun-externals/bun-externals.test.ts", "test/e2e/app-dir/bun-externals/bun-externals.test.ts",
"test/e2e/app-dir/async-component-preload/async-component-preload.test.ts", "test/e2e/app-dir/async-component-preload/async-component-preload.test.ts",
"test/e2e/app-dir/autoscroll-with-css-modules/index.test.ts",
"test/e2e/app-dir/back-forward-cache/back-forward-cache.test.ts", "test/e2e/app-dir/back-forward-cache/back-forward-cache.test.ts",
"test/e2e/app-dir/crypto-globally-available/crypto-globally-available.test.ts", "test/e2e/app-dir/crypto-globally-available/crypto-globally-available.test.ts",
"test/e2e/app-dir/css-chunking/css-chunking.test.ts", "test/e2e/app-dir/css-chunking/css-chunking.test.ts",
...@@ -244,7 +243,6 @@ ...@@ -244,7 +243,6 @@
"test/e2e/app-dir/rewrites-redirects/rewrites-redirects.test.ts", "test/e2e/app-dir/rewrites-redirects/rewrites-redirects.test.ts",
"test/e2e/app-dir/root-layout-render-once/index.test.ts", "test/e2e/app-dir/root-layout-render-once/index.test.ts",
"test/e2e/app-dir/root-layout/root-layout.test.ts", "test/e2e/app-dir/root-layout/root-layout.test.ts",
"test/e2e/app-dir/router-autoscroll/router-autoscroll.test.ts",
"test/e2e/app-dir/router-stuck-dynamic-static-segment/router-stuck-dynamic-static-segment.test.ts", "test/e2e/app-dir/router-stuck-dynamic-static-segment/router-stuck-dynamic-static-segment.test.ts",
"test/e2e/app-dir/rsc-basic/rsc-basic-react-experimental.test.ts", "test/e2e/app-dir/rsc-basic/rsc-basic-react-experimental.test.ts",
"test/e2e/app-dir/rsc-basic/rsc-basic.test.ts", "test/e2e/app-dir/rsc-basic/rsc-basic.test.ts",
......
import { Suspense } from 'react'
export default function Layout({ children }: any) { export default function Layout({ children }: any) {
return ( return (
<html <Suspense
style={{ fallback={
overflowY: 'scroll', <html>
}} <body />
</html>
}
> >
<head /> <html
<body style={{ margin: 0 }}>{children}</body> style={{
</html> overflowY: 'scroll',
}}
>
<head />
<body style={{ margin: 0 }}>{children}</body>
</html>
</Suspense>
) )
} }
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
import { check } from 'next-test-utils' import { retry } from 'next-test-utils'
describe('router autoscrolling on navigation with css modules', () => { describe('router autoscrolling on navigation with css modules', () => {
const { next } = nextTestSetup({ const { next } = nextTestSetup({
...@@ -14,17 +14,16 @@ describe('router autoscrolling on navigation with css modules', () => { ...@@ -14,17 +14,16 @@ describe('router autoscrolling on navigation with css modules', () => {
const getLeftScroll = async (browser: Playwright) => const getLeftScroll = async (browser: Playwright) =>
await browser.eval('document.documentElement.scrollLeft') await browser.eval('document.documentElement.scrollLeft')
const waitForScrollToComplete = ( const waitForScrollToComplete = async (
browser, browser: Playwright,
options: { x: number; y: number } options: { x: number; y: number }
) => ) => {
check(async () => { await retry(async function expectScrolledTo() {
const top = await getTopScroll(browser) const top = await getTopScroll(browser)
const left = await getLeftScroll(browser) const left = await getLeftScroll(browser)
return top === options.y && left === options.x expect({ top, left }).toEqual({ top: options.y, left: options.x })
? 'success' })
: JSON.stringify({ top, left }) }
}, 'success')
const scrollTo = async ( const scrollTo = async (
browser: Playwright, browser: Playwright,
...@@ -37,6 +36,7 @@ describe('router autoscrolling on navigation with css modules', () => { ...@@ -37,6 +36,7 @@ describe('router autoscrolling on navigation with css modules', () => {
describe('vertical scroll when page imports css modules', () => { describe('vertical scroll when page imports css modules', () => {
it('should scroll to top of document when navigating between to pages without layout when', async () => { it('should scroll to top of document when navigating between to pages without layout when', async () => {
const browser = await next.browser('/1') const browser = await next.browser('/1')
await browser.waitForElementByCss('#lower')
await scrollTo(browser, { x: 0, y: 1000 }) await scrollTo(browser, { x: 0, y: 1000 })
expect(await getTopScroll(browser)).toBe(1000) expect(await getTopScroll(browser)).toBe(1000)
...@@ -47,6 +47,7 @@ describe('router autoscrolling on navigation with css modules', () => { ...@@ -47,6 +47,7 @@ describe('router autoscrolling on navigation with css modules', () => {
it('should scroll when clicking in JS', async () => { it('should scroll when clicking in JS', async () => {
const browser = await next.browser('/1') const browser = await next.browser('/1')
await browser.waitForElementByCss('#lower')
await scrollTo(browser, { x: 0, y: 1000 }) await scrollTo(browser, { x: 0, y: 1000 })
expect(await getTopScroll(browser)).toBe(1000) expect(await getTopScroll(browser)).toBe(1000)
......
export const dynamic = 'force-dynamic' import { connection } from 'next/server'
import { Suspense } from 'react'
async function ForceDynamic({ children }) {
await connection()
return children
}
export default function Layout({ children }) { export default function Layout({ children }) {
return ( return (
<html> <Suspense
<head></head> fallback={
<body>{children}</body> <html>
</html> <body />
</html>
}
>
<ForceDynamic>
<html>
<head></head>
<body>{children}</body>
</html>
</ForceDynamic>
</Suspense>
) )
} }
import { setTimeout } from 'node:timers/promises'
import React from 'react' import React from 'react'
// ensure this page is dynamically rendered so we always trigger a loading state export default async function Page() {
export const dynamic = 'force-dynamic' // Ensure we trigger the loading state.
// `connection` isn't sufficient since a parent might've already suspended
export default function Page() { // on connection.
await setTimeout(50)
return <div id="page-content">Content</div> return <div id="page-content">Content</div>
} }
async function getTitle() { async function getTitle() {
return await new Promise((resolve) => return setTimeout(5000, 'Async Title')
setTimeout(() => resolve('Async Title'), 5000)
)
} }
export async function generateMetadata() { export async function generateMetadata() {
......
import { redirect } from 'next/navigation' import { redirect } from 'next/navigation'
import { connection } from 'next/server'
export const dynamic = 'force-dynamic' export default async function Page() {
await connection()
export default function Page() {
return redirect('/?a=b;c') return redirect('/?a=b;c')
} }
...@@ -407,21 +407,6 @@ describe('app dir - navigation', () => { ...@@ -407,21 +407,6 @@ describe('app dir - navigation', () => {
}) })
}) })
describe('bots', () => {
if (!isNextDeploy) {
it('should block rendering for bots and return 404 status', async () => {
const res = await next.fetch('/not-found/servercomponent', {
headers: {
'User-Agent': 'Googlebot',
},
})
expect(res.status).toBe(404)
expect(await res.text()).toInclude('"noindex"')
})
}
})
describe('redirect', () => { describe('redirect', () => {
describe('components', () => { describe('components', () => {
it('should redirect in a server component', async () => { it('should redirect in a server component', async () => {
...@@ -519,7 +504,9 @@ describe('app dir - navigation', () => { ...@@ -519,7 +504,9 @@ describe('app dir - navigation', () => {
// If the timestamp has changed, throw immediately. // If the timestamp has changed, throw immediately.
if (currentTimestamp !== initialTimestamp) { if (currentTimestamp !== initialTimestamp) {
throw new Error('Timestamp has changed') throw new Error(
`Timestamp has changed from the initial '${initialTimestamp}' to '${currentTimestamp}'`
)
} }
// If we've reached the last attempt without the timestamp changing, force a retry failure to keep going. // If we've reached the last attempt without the timestamp changing, force a retry failure to keep going.
...@@ -581,27 +568,6 @@ describe('app dir - navigation', () => { ...@@ -581,27 +568,6 @@ describe('app dir - navigation', () => {
expect(await browser.url()).toBe(next.url + '/redirect-dest') expect(await browser.url()).toBe(next.url + '/redirect-dest')
}) })
}) })
describe('status code', () => {
it('should respond with 307 status code in server component', async () => {
const res = await next.fetch('/redirect/servercomponent', {
redirect: 'manual',
})
expect(res.status).toBe(307)
})
it('should respond with 307 status code in client component', async () => {
const res = await next.fetch('/redirect/clientcomponent', {
redirect: 'manual',
})
expect(res.status).toBe(307)
})
it('should respond with 308 status code if permanent flag is set', async () => {
const res = await next.fetch('/redirect/servercomponent-2', {
redirect: 'manual',
})
expect(res.status).toBe(308)
})
})
}) })
describe('external push', () => { describe('external push', () => {
...@@ -993,15 +959,18 @@ describe('app dir - navigation', () => { ...@@ -993,15 +959,18 @@ describe('app dir - navigation', () => {
describe('locale warnings', () => { describe('locale warnings', () => {
it('should warn about using the `locale` prop with `next/link` in app router', async () => { it('should warn about using the `locale` prop with `next/link` in app router', async () => {
const browser = await next.browser('/locale-app') const browser = await next.browser('/locale-app')
const logs = await browser.log()
expect(logs).toContainEqual( await retry(async () => {
expect.objectContaining({ const logs = await browser.log()
message: expect.stringContaining( expect(logs).toContainEqual(
'The `locale` prop is not supported in `next/link` while using the `app` router.' expect.objectContaining({
), message: expect.stringContaining(
source: 'warning', 'The `locale` prop is not supported in `next/link` while using the `app` router.'
}) ),
) source: 'warning',
})
)
})
}) })
it('should have no warnings in pages router', async () => { it('should have no warnings in pages router', async () => {
......
import { notFound } from 'next/navigation'
export default function ShellPage() {
notFound()
}
...@@ -59,6 +59,13 @@ describe('app dir - not-found - basic', () => { ...@@ -59,6 +59,13 @@ describe('app dir - not-found - basic', () => {
} }
const runTests = ({ isEdge }: { isEdge: boolean }) => { const runTests = ({ isEdge }: { isEdge: boolean }) => {
it('should return 404 status if notFound() is called in shell', async () => {
const res = await next.fetch('/shell-not-found')
expect(res.status).toBe(404)
expect(await res.text()).toInclude('"noindex"')
})
it('should use the not-found page for non-matching routes', async () => { it('should use the not-found page for non-matching routes', async () => {
const browser = await next.browser('/random-content') const browser = await next.browser('/random-content')
expect(await browser.elementByCss('h1').text()).toContain( expect(await browser.elementByCss('h1').text()).toContain(
......
import React from 'react' import React, { Suspense } from 'react'
export default async function Layout({ export default async function Layout({
children, children,
...@@ -27,7 +27,9 @@ export default async function Layout({ ...@@ -27,7 +27,9 @@ export default async function Layout({
display: 'flex', display: 'flex',
}} }}
> >
{children} <Suspense fallback={<div id="loading">loading...</div>}>
{children}
</Suspense>
</div> </div>
) )
} }
export default function Page() { import { connection } from 'next/server'
export default async function Page() {
await connection()
const randomColor = Math.floor(Math.random() * 16777215).toString(16) const randomColor = Math.floor(Math.random() * 16777215).toString(16)
return ( return (
<div <div
......
'use client' 'use client'
import Link from 'next/link' import Link from 'next/link'
import React, { useEffect } from 'react' import React, { Suspense, useEffect } from 'react'
import { useRouter } from 'next/navigation' import { useRouter } from 'next/navigation'
export default function Layout({ children }: { children: React.ReactNode }) { export default function Layout({ children }: { children: React.ReactNode }) {
...@@ -16,24 +16,32 @@ export default function Layout({ children }: { children: React.ReactNode }) { ...@@ -16,24 +16,32 @@ export default function Layout({ children }: { children: React.ReactNode }) {
}, [router]) }, [router])
return ( return (
<html> <Suspense
<head></head> fallback={
<body <html>
style={{ <body />
margin: 0, </html>
}} }
> >
<div <html>
<head></head>
<body
style={{ style={{
position: 'fixed', margin: 0,
top: 0,
left: 0,
}} }}
> >
<Link id="to-vertical-page" href="1" /> <div
</div> style={{
{children} position: 'fixed',
</body> top: 0,
</html> left: 0,
}}
>
<Link id="to-vertical-page" href="1" />
</div>
{children}
</body>
</html>
</Suspense>
) )
} }
import Link from 'next/link' import Link from 'next/link'
export const dynamic = 'force-dynamic'
export default async function Page(props: PageProps<'/loading-scroll'>) { export default async function Page(props: PageProps<'/loading-scroll'>) {
const search = await props.searchParams const search = await props.searchParams
const skipSleep = !!search.skipSleep const skipSleep = !!search.skipSleep
......
module.exports = {} /**
* @type {import('next').NextConfig}
*/
const config = {}
module.exports = config
import webdriver, { type Playwright } from 'next-webdriver' import type { Playwright } from 'next-webdriver'
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
import { check, assertNoConsoleErrors, retry } from 'next-test-utils' import { check, assertNoConsoleErrors, retry } from 'next-test-utils'
...@@ -17,7 +17,7 @@ describe('router autoscrolling on navigation', () => { ...@@ -17,7 +17,7 @@ describe('router autoscrolling on navigation', () => {
browser: Playwright, browser: Playwright,
options: { x: number; y: number } options: { x: number; y: number }
) => { ) => {
await retry(async () => { await retry(async function expectScrolledTo() {
const top = await getTopScroll(browser) const top = await getTopScroll(browser)
const left = await getLeftScroll(browser) const left = await getLeftScroll(browser)
expect({ top, left }).toEqual({ top: options.y, left: options.x }) expect({ top, left }).toEqual({ top: options.y, left: options.x })
...@@ -35,17 +35,16 @@ describe('router autoscrolling on navigation', () => { ...@@ -35,17 +35,16 @@ describe('router autoscrolling on navigation', () => {
describe('vertical scroll', () => { describe('vertical scroll', () => {
it('should scroll to top of document when navigating between to pages without layout', async () => { it('should scroll to top of document when navigating between to pages without layout', async () => {
const browser = await webdriver(next.url, '/0/0/100/10000/page1') const browser = await next.browser('/0/0/100/10000/page1')
await scrollTo(browser, { x: 0, y: 1000 }) await scrollTo(browser, { x: 0, y: 1000 })
expect(await getTopScroll(browser)).toBe(1000)
await browser.eval(`window.router.push("/0/0/100/10000/page2")`) await browser.eval(`window.router.push("/0/0/100/10000/page2")`)
await waitForScrollToComplete(browser, { x: 0, y: 0 }) await waitForScrollToComplete(browser, { x: 0, y: 0 })
}) })
it("should scroll to top of page when scrolling to phe top of the document wouldn't have the page in the viewport", async () => { it("should scroll to top of page when scrolling to phe top of the document wouldn't have the page in the viewport", async () => {
const browser = await webdriver(next.url, '/0/1000/100/1000/page1') const browser = await next.browser('/0/1000/100/1000/page1')
await scrollTo(browser, { x: 0, y: 1500 }) await scrollTo(browser, { x: 0, y: 1500 })
expect(await getTopScroll(browser)).toBe(1500) expect(await getTopScroll(browser)).toBe(1500)
...@@ -55,7 +54,7 @@ describe('router autoscrolling on navigation', () => { ...@@ -55,7 +54,7 @@ describe('router autoscrolling on navigation', () => {
}) })
it("should scroll down to the navigated page when it's below viewort", async () => { it("should scroll down to the navigated page when it's below viewort", async () => {
const browser = await webdriver(next.url, '/0/1000/100/1000/page1') const browser = await next.browser('/0/1000/100/1000/page1')
expect(await getTopScroll(browser)).toBe(0) expect(await getTopScroll(browser)).toBe(0)
await browser.eval(`window.router.push("/0/1000/100/1000/page2")`) await browser.eval(`window.router.push("/0/1000/100/1000/page2")`)
...@@ -63,37 +62,34 @@ describe('router autoscrolling on navigation', () => { ...@@ -63,37 +62,34 @@ describe('router autoscrolling on navigation', () => {
}) })
it('should not scroll when the top of the page is in the viewport', async () => { it('should not scroll when the top of the page is in the viewport', async () => {
const browser = await webdriver(next.url, '/10/1000/100/1000/page1') const browser = await next.browser('/10/1000/100/1000/page1')
await scrollTo(browser, { x: 0, y: 800 }) await scrollTo(browser, { x: 0, y: 800 })
expect(await getTopScroll(browser)).toBe(800)
await browser.eval(`window.router.push("/10/1000/100/1000/page2")`) await browser.eval(`window.router.push("/10/1000/100/1000/page2")`)
await waitForScrollToComplete(browser, { x: 0, y: 800 }) await waitForScrollToComplete(browser, { x: 0, y: 800 })
}) })
it('should not scroll to top of document if page in viewport', async () => { it('should not scroll to top of document if page in viewport', async () => {
const browser = await webdriver(next.url, '/10/100/100/1000/page1') const browser = await next.browser('/10/100/100/1000/page1')
await scrollTo(browser, { x: 0, y: 50 }) await scrollTo(browser, { x: 0, y: 50 })
expect(await getTopScroll(browser)).toBe(50)
await browser.eval(`window.router.push("/10/100/100/1000/page2")`) await browser.eval(`window.router.push("/10/100/100/1000/page2")`)
await waitForScrollToComplete(browser, { x: 0, y: 50 }) await waitForScrollToComplete(browser, { x: 0, y: 50 })
}) })
it('should scroll to top of document if possible while giving focus to page', async () => { it('should scroll to top of document if possible while giving focus to page', async () => {
const browser = await webdriver(next.url, '/10/100/100/1000/page1') const browser = await next.browser('/10/100/100/1000/page1')
await scrollTo(browser, { x: 0, y: 200 }) await scrollTo(browser, { x: 0, y: 200 })
expect(await getTopScroll(browser)).toBe(200)
await browser.eval(`window.router.push("/10/100/100/1000/page2")`) await browser.eval(`window.router.push("/10/100/100/1000/page2")`)
await waitForScrollToComplete(browser, { x: 0, y: 0 }) await waitForScrollToComplete(browser, { x: 0, y: 0 })
}) })
it('should scroll to top of document with new metadata', async () => { it('should scroll to top of document with new metadata', async () => {
const browser = await webdriver(next.url, '/') const browser = await next.browser('/')
// scroll to bottom // scroll to bottom
await browser.eval( await browser.eval(
...@@ -112,11 +108,9 @@ describe('router autoscrolling on navigation', () => { ...@@ -112,11 +108,9 @@ describe('router autoscrolling on navigation', () => {
describe('horizontal scroll', () => { describe('horizontal scroll', () => {
it("should't scroll horizontally", async () => { it("should't scroll horizontally", async () => {
const browser = await webdriver(next.url, '/0/0/10000/10000/page1') const browser = await next.browser('/0/0/10000/10000/page1')
await scrollTo(browser, { x: 1000, y: 1000 }) await scrollTo(browser, { x: 1000, y: 1000 })
expect(await getLeftScroll(browser)).toBe(1000)
expect(await getTopScroll(browser)).toBe(1000)
await browser.eval(`window.router.push("/0/0/10000/10000/page2")`) await browser.eval(`window.router.push("/0/0/10000/10000/page2")`)
await waitForScrollToComplete(browser, { x: 1000, y: 0 }) await waitForScrollToComplete(browser, { x: 1000, y: 0 })
...@@ -125,20 +119,18 @@ describe('router autoscrolling on navigation', () => { ...@@ -125,20 +119,18 @@ describe('router autoscrolling on navigation', () => {
describe('router.refresh()', () => { describe('router.refresh()', () => {
it('should not scroll when called alone', async () => { it('should not scroll when called alone', async () => {
const browser = await webdriver(next.url, '/10/10000/100/1000/page1') const browser = await next.browser('/10/10000/100/1000/page1')
await scrollTo(browser, { x: 0, y: 12000 }) await scrollTo(browser, { x: 0, y: 12000 })
expect(await getTopScroll(browser)).toBe(12000)
await browser.eval(`window.router.refresh()`) await browser.eval(`window.router.refresh()`)
await waitForScrollToComplete(browser, { x: 0, y: 12000 }) await waitForScrollToComplete(browser, { x: 0, y: 12000 })
}) })
it('should not stop router.push() from scrolling', async () => { it('should not stop router.push() from scrolling', async () => {
const browser = await webdriver(next.url, '/10/10000/100/1000/page1') const browser = await next.browser('/10/10000/100/1000/page1')
await scrollTo(browser, { x: 0, y: 12000 }) await scrollTo(browser, { x: 0, y: 12000 })
expect(await getTopScroll(browser)).toBe(12000)
await browser.eval(` await browser.eval(`
window.React.startTransition(() => { window.React.startTransition(() => {
...@@ -154,7 +146,7 @@ describe('router autoscrolling on navigation', () => { ...@@ -154,7 +146,7 @@ describe('router autoscrolling on navigation', () => {
;(isNextDev ? it : it.skip)( ;(isNextDev ? it : it.skip)(
'should not scroll the page when we hot reload', 'should not scroll the page when we hot reload',
async () => { async () => {
const browser = await webdriver(next.url, '/10/10000/100/1000/page1') const browser = await next.browser('/10/10000/100/1000/page1')
await scrollTo(browser, { x: 0, y: 12000 }) await scrollTo(browser, { x: 0, y: 12000 })
...@@ -180,7 +172,7 @@ describe('router autoscrolling on navigation', () => { ...@@ -180,7 +172,7 @@ describe('router autoscrolling on navigation', () => {
describe('bugs', () => { describe('bugs', () => {
it('Should scroll to the top of the layout when the first child is display none', async () => { it('Should scroll to the top of the layout when the first child is display none', async () => {
const browser = await webdriver(next.url, '/') const browser = await next.browser('/')
await browser.eval('window.scrollTo(0, 500)') await browser.eval('window.scrollTo(0, 500)')
await browser await browser
.elementByCss('#to-invisible-first-element') .elementByCss('#to-invisible-first-element')
...@@ -190,7 +182,7 @@ describe('router autoscrolling on navigation', () => { ...@@ -190,7 +182,7 @@ describe('router autoscrolling on navigation', () => {
}) })
it('Should scroll to the top of the layout when the first child is position fixed', async () => { it('Should scroll to the top of the layout when the first child is position fixed', async () => {
const browser = await webdriver(next.url, '/') const browser = await next.browser('/')
await browser.eval('window.scrollTo(0, 500)') await browser.eval('window.scrollTo(0, 500)')
await browser await browser
.elementByCss('#to-fixed-first-element') .elementByCss('#to-fixed-first-element')
...@@ -200,7 +192,7 @@ describe('router autoscrolling on navigation', () => { ...@@ -200,7 +192,7 @@ describe('router autoscrolling on navigation', () => {
}) })
it('Should scroll to the top of the layout when the first child is position sticky', async () => { it('Should scroll to the top of the layout when the first child is position sticky', async () => {
const browser = await webdriver(next.url, '/') const browser = await next.browser('/')
await browser.eval('window.scrollTo(0, 500)') await browser.eval('window.scrollTo(0, 500)')
await browser await browser
.elementByCss('#to-sticky-first-element') .elementByCss('#to-sticky-first-element')
...@@ -210,12 +202,10 @@ describe('router autoscrolling on navigation', () => { ...@@ -210,12 +202,10 @@ describe('router autoscrolling on navigation', () => {
}) })
it('Should apply scroll when loading.js is used', async () => { it('Should apply scroll when loading.js is used', async () => {
const browser = await webdriver(next.url, '/') const browser = await next.browser('/')
await browser.eval('window.scrollTo(0, 500)') await browser.eval('window.scrollTo(0, 500)')
await browser await browser.elementByCss('#to-loading-scroll').click()
.elementByCss('#to-loading-scroll') await browser.waitForElementByCss('#loading-component')
.click()
.waitForElementByCss('#loading-component')
await check(() => browser.eval('window.scrollY'), 0) await check(() => browser.eval('window.scrollY'), 0)
await browser.waitForElementByCss('#content-that-is-visible') await browser.waitForElementByCss('#content-that-is-visible')
await check(() => browser.eval('window.scrollY'), 0) await check(() => browser.eval('window.scrollY'), 0)
......
...@@ -3,5 +3,3 @@ import { notFound } from 'next/navigation' ...@@ -3,5 +3,3 @@ import { notFound } from 'next/navigation'
export default function Page() { export default function Page() {
notFound() notFound()
} }
export const dynamic = 'force-static'
'use client'
import { redirect } from 'next/navigation'
export default function ClientComp() {
redirect('/')
return <></>
}
import ClientComp from './client-component'
export default function Page() {
return <ClientComp />
}
...@@ -3,5 +3,3 @@ import { redirect } from 'next/navigation' ...@@ -3,5 +3,3 @@ import { redirect } from 'next/navigation'
export default function Page() { export default function Page() {
redirect('/') redirect('/')
} }
export const dynamic = 'force-static'
import { permanentRedirect, RedirectType } from 'next/navigation' import { permanentRedirect, RedirectType } from 'next/navigation'
export default function Page() { export default function Page() {
permanentRedirect('/redirect/result', RedirectType.push) permanentRedirect('/', RedirectType.push)
return <></> return <></>
} }
...@@ -17,6 +17,20 @@ describe('app-dir static-generation-status', () => { ...@@ -17,6 +17,20 @@ describe('app-dir static-generation-status', () => {
expect(status).toBe(307) expect(status).toBe(307)
}) })
it('should render the client page using redirect with status 307', async () => {
const { status } = await next.fetch('/redirect-client-page', {
redirect: 'manual',
})
expect(status).toBe(307)
})
it('should respond with 308 status code if permanent flag is set', async () => {
const { status } = await next.fetch('/redirect-permanent', {
redirect: 'manual',
})
expect(status).toBe(308)
})
it('should render the non existed route redirect with status 404', async () => { it('should render the non existed route redirect with status 404', async () => {
expect((await next.fetch('/does-not-exist')).status).toBe(404) expect((await next.fetch('/does-not-exist')).status).toBe(404)
}) })
......
...@@ -818,7 +818,7 @@ export async function retry<T>( ...@@ -818,7 +818,7 @@ export async function retry<T>(
fn: () => T | Promise<T>, fn: () => T | Promise<T>,
duration: number = 3000, duration: number = 3000,
interval: number = 500, interval: number = 500,
description?: string description: string = fn.name
): Promise<T> { ): Promise<T> {
if (duration % interval !== 0) { if (duration % interval !== 0) {
throw new Error( throw new Error(
......
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