Skip to content

Commit 9934b12

Browse files
committed
[test] Enable scroll related tests in experimental tests
1 parent db1de21 commit 9934b12

File tree

23 files changed

+169
-136
lines changed

23 files changed

+169
-136
lines changed
Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1+
import { Suspense } from 'react'
2+
13
export default function Layout({ children }: any) {
24
return (
3-
<html
4-
style={{
5-
overflowY: 'scroll',
6-
}}
7-
>
8-
<head />
9-
<body style={{ margin: 0 }}>{children}</body>
10-
</html>
5+
<Suspense>
6+
<html
7+
style={{
8+
overflowY: 'scroll',
9+
}}
10+
>
11+
<head />
12+
<body style={{ margin: 0 }}>{children}</body>
13+
</html>
14+
</Suspense>
1115
)
1216
}

test/e2e/app-dir/autoscroll-with-css-modules/index.test.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { nextTestSetup } from 'e2e-utils'
2-
import { check } from 'next-test-utils'
2+
import { retry } from 'next-test-utils'
33

44
describe('router autoscrolling on navigation with css modules', () => {
55
const { next } = nextTestSetup({
@@ -14,17 +14,16 @@ describe('router autoscrolling on navigation with css modules', () => {
1414
const getLeftScroll = async (browser: Playwright) =>
1515
await browser.eval('document.documentElement.scrollLeft')
1616

17-
const waitForScrollToComplete = (
18-
browser,
17+
const waitForScrollToComplete = async (
18+
browser: Playwright,
1919
options: { x: number; y: number }
20-
) =>
21-
check(async () => {
20+
) => {
21+
await retry(async function expectScrolledTo() {
2222
const top = await getTopScroll(browser)
2323
const left = await getLeftScroll(browser)
24-
return top === options.y && left === options.x
25-
? 'success'
26-
: JSON.stringify({ top, left })
27-
}, 'success')
24+
expect({ top, left }).toEqual({ top: options.y, left: options.x })
25+
})
26+
}
2827

2928
const scrollTo = async (
3029
browser: Playwright,
@@ -37,6 +36,7 @@ describe('router autoscrolling on navigation with css modules', () => {
3736
describe('vertical scroll when page imports css modules', () => {
3837
it('should scroll to top of document when navigating between to pages without layout when', async () => {
3938
const browser = await next.browser('/1')
39+
await browser.waitForElementByCss('#lower', { state: 'visible' })
4040

4141
await scrollTo(browser, { x: 0, y: 1000 })
4242
expect(await getTopScroll(browser)).toBe(1000)
@@ -47,6 +47,7 @@ describe('router autoscrolling on navigation with css modules', () => {
4747

4848
it('should scroll when clicking in JS', async () => {
4949
const browser = await next.browser('/1')
50+
await browser.waitForElementByCss('#lower', { state: 'visible' })
5051

5152
await scrollTo(browser, { x: 0, y: 1000 })
5253
expect(await getTopScroll(browser)).toBe(1000)
Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
1-
export const dynamic = 'force-dynamic'
1+
import { connection } from 'next/server'
2+
import { Suspense } from 'react'
3+
4+
async function ForceDynamic({ children }) {
5+
await connection()
6+
return children
7+
}
28

39
export default function Layout({ children }) {
410
return (
5-
<html>
6-
<head></head>
7-
<body>{children}</body>
8-
</html>
11+
<Suspense>
12+
<ForceDynamic>
13+
<html>
14+
<head></head>
15+
<body>{children}</body>
16+
</html>
17+
</ForceDynamic>
18+
</Suspense>
919
)
1020
}

test/e2e/app-dir/navigation/app/metadata-await-promise/nested/page.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
import { connection } from 'next/server'
12
import React from 'react'
23

3-
// ensure this page is dynamically rendered so we always trigger a loading state
4-
export const dynamic = 'force-dynamic'
5-
6-
export default function Page() {
4+
export default async function Page() {
5+
// ensure this page is dynamically rendered so we always trigger a loading state
6+
await connection()
77
return <div id="page-content">Content</div>
88
}
99

test/e2e/app-dir/navigation/app/redirect/result/page.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
export default function Page() {
1+
import { connection } from 'next/server'
2+
3+
export default async function Page() {
4+
await connection()
25
return (
36
<div>
47
<h1 id="result-page">Result Page</h1>
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { redirect } from 'next/navigation'
2+
import { connection } from 'next/server'
23

3-
export const dynamic = 'force-dynamic'
4-
5-
export default function Page() {
4+
export default async function Page() {
5+
await connection()
66
return redirect('/?a=b;c')
77
}

test/e2e/app-dir/navigation/navigation.test.ts

Lines changed: 15 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -407,21 +407,6 @@ describe('app dir - navigation', () => {
407407
})
408408
})
409409

410-
describe('bots', () => {
411-
if (!isNextDeploy) {
412-
it('should block rendering for bots and return 404 status', async () => {
413-
const res = await next.fetch('/not-found/servercomponent', {
414-
headers: {
415-
'User-Agent': 'Googlebot',
416-
},
417-
})
418-
419-
expect(res.status).toBe(404)
420-
expect(await res.text()).toInclude('"noindex"')
421-
})
422-
}
423-
})
424-
425410
describe('redirect', () => {
426411
describe('components', () => {
427412
it('should redirect in a server component', async () => {
@@ -520,7 +505,9 @@ describe('app dir - navigation', () => {
520505

521506
// If the timestamp has changed, throw immediately.
522507
if (currentTimestamp !== initialTimestamp) {
523-
throw new Error('Timestamp has changed')
508+
throw new Error(
509+
`Timestamp has changed from the initial '${initialTimestamp}' to '${currentTimestamp}'`
510+
)
524511
}
525512

526513
// If we've reached the last attempt without the timestamp changing, force a retry failure to keep going.
@@ -582,27 +569,6 @@ describe('app dir - navigation', () => {
582569
expect(await browser.url()).toBe(next.url + '/redirect-dest')
583570
})
584571
})
585-
586-
describe('status code', () => {
587-
it('should respond with 307 status code in server component', async () => {
588-
const res = await next.fetch('/redirect/servercomponent', {
589-
redirect: 'manual',
590-
})
591-
expect(res.status).toBe(307)
592-
})
593-
it('should respond with 307 status code in client component', async () => {
594-
const res = await next.fetch('/redirect/clientcomponent', {
595-
redirect: 'manual',
596-
})
597-
expect(res.status).toBe(307)
598-
})
599-
it('should respond with 308 status code if permanent flag is set', async () => {
600-
const res = await next.fetch('/redirect/servercomponent-2', {
601-
redirect: 'manual',
602-
})
603-
expect(res.status).toBe(308)
604-
})
605-
})
606572
})
607573

608574
describe('external push', () => {
@@ -994,15 +960,18 @@ describe('app dir - navigation', () => {
994960
describe('locale warnings', () => {
995961
it('should warn about using the `locale` prop with `next/link` in app router', async () => {
996962
const browser = await next.browser('/locale-app')
997-
const logs = await browser.log()
998-
expect(logs).toContainEqual(
999-
expect.objectContaining({
1000-
message: expect.stringContaining(
1001-
'The `locale` prop is not supported in `next/link` while using the `app` router.'
1002-
),
1003-
source: 'warning',
1004-
})
1005-
)
963+
964+
await retry(async () => {
965+
const logs = await browser.log()
966+
expect(logs).toContainEqual(
967+
expect.objectContaining({
968+
message: expect.stringContaining(
969+
'The `locale` prop is not supported in `next/link` while using the `app` router.'
970+
),
971+
source: 'warning',
972+
})
973+
)
974+
})
1006975
})
1007976

1008977
it('should have no warnings in pages router', async () => {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { notFound } from 'next/navigation'
2+
3+
export default function ShellPage() {
4+
notFound()
5+
}

test/e2e/app-dir/not-found/basic/index.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ describe('app dir - not-found - basic', () => {
5959
}
6060

6161
const runTests = ({ isEdge }: { isEdge: boolean }) => {
62+
it('should return 404 status if notFound() is called in shell', async () => {
63+
const res = await next.fetch('/shell-not-found')
64+
65+
expect(res.status).toBe(404)
66+
expect(await res.text()).toInclude('"noindex"')
67+
})
68+
6269
it('should use the not-found page for non-matching routes', async () => {
6370
const browser = await next.browser('/random-content')
6471
expect(await browser.elementByCss('h1').text()).toContain(

test/e2e/app-dir/router-autoscroll/app/[layoutPaddingWidth]/[layoutPaddingHeight]/[pageWidth]/[pageHeight]/[param]/layout.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react'
1+
import React, { Suspense } from 'react'
22

33
export default async function Layout({
44
children,
@@ -27,7 +27,9 @@ export default async function Layout({
2727
display: 'flex',
2828
}}
2929
>
30-
{children}
30+
<Suspense fallback={<div id="loading">loading...</div>}>
31+
{children}
32+
</Suspense>
3133
</div>
3234
)
3335
}

0 commit comments

Comments
 (0)