-
Notifications
You must be signed in to change notification settings - Fork 26.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add additional tests for prefetch and trailingSlash (#40517)
Adds some of the tests we didn't have yet for app. <!-- Thanks for opening a PR! Your contribution is much appreciated. In order to make sure your PR is handled as smoothly as possible we request that you follow the checklist sections below. Choose the right checklist for the change that you're making: --> ## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have helpful link attached, see `contributing.md` ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have helpful link attached, see `contributing.md` ## Documentation / Examples - [ ] Make sure the linting passes by running `pnpm lint` - [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
- Loading branch information
1 parent
69d0e60
commit eadaca7
Showing
12 changed files
with
172 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { createNext, FileRef } from 'e2e-utils' | ||
import { NextInstance } from 'test/lib/next-modes/base' | ||
import { waitFor } from 'next-test-utils' | ||
import path from 'path' | ||
import webdriver from 'next-webdriver' | ||
|
||
describe('app dir prefetching', () => { | ||
if ((global as any).isNextDeploy) { | ||
it('should skip next deploy for now', () => {}) | ||
return | ||
} | ||
|
||
if (process.env.NEXT_TEST_REACT_VERSION === '^17') { | ||
it('should skip for react v17', () => {}) | ||
return | ||
} | ||
let next: NextInstance | ||
|
||
beforeAll(async () => { | ||
next = await createNext({ | ||
files: new FileRef(path.join(__dirname, 'app-prefetch')), | ||
dependencies: { | ||
react: 'experimental', | ||
'react-dom': 'experimental', | ||
}, | ||
skipStart: true, | ||
}) | ||
await next.start() | ||
}) | ||
afterAll(() => next.destroy()) | ||
|
||
it('should show layout eagerly when prefetched with loading one level down', async () => { | ||
const browser = await webdriver(next.url, '/') | ||
// Ensure the page is prefetched | ||
await waitFor(1000) | ||
|
||
const before = Date.now() | ||
await browser | ||
.elementByCss('#to-dashboard') | ||
.click() | ||
.waitForElementByCss('#dashboard-layout') | ||
const after = Date.now() | ||
const timeToComplete = after - before | ||
|
||
expect(timeToComplete < 1000).toBe(true) | ||
|
||
expect(await browser.elementByCss('#dashboard-layout').text()).toBe( | ||
'Dashboard Hello World' | ||
) | ||
|
||
await browser.waitForElementByCss('#dashboard-page') | ||
|
||
expect(await browser.waitForElementByCss('#dashboard-page').text()).toBe( | ||
'Welcome to the dashboard' | ||
) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { createNext, FileRef } from 'e2e-utils' | ||
import { NextInstance } from 'test/lib/next-modes/base' | ||
import { fetchViaHTTP, renderViaHTTP } from 'next-test-utils' | ||
import path from 'path' | ||
import cheerio from 'cheerio' | ||
import webdriver from 'next-webdriver' | ||
|
||
describe('app-dir trailingSlash handling', () => { | ||
if ((global as any).isNextDeploy) { | ||
it('should skip next deploy for now', () => {}) | ||
return | ||
} | ||
|
||
if (process.env.NEXT_TEST_REACT_VERSION === '^17') { | ||
it('should skip for react v17', () => {}) | ||
return | ||
} | ||
let next: NextInstance | ||
|
||
beforeAll(async () => { | ||
next = await createNext({ | ||
files: new FileRef(path.join(__dirname, 'trailingslash')), | ||
dependencies: { | ||
react: 'experimental', | ||
'react-dom': 'experimental', | ||
}, | ||
skipStart: true, | ||
}) | ||
|
||
await next.start() | ||
}) | ||
afterAll(() => next.destroy()) | ||
|
||
it('should redirect route when requesting it directly', async () => { | ||
const res = await fetchViaHTTP( | ||
next.url, | ||
'/a', | ||
{}, | ||
{ | ||
redirect: 'manual', | ||
} | ||
) | ||
expect(res.status).toBe(308) | ||
expect(res.headers.get('location')).toBe(next.url + '/a/') | ||
}) | ||
|
||
it('should render link with trailing slash', async () => { | ||
const html = await renderViaHTTP(next.url, '/') | ||
const $ = cheerio.load(html) | ||
expect($('#to-a-trailing-slash').attr('href')).toBe('/a/') | ||
}) | ||
|
||
it('should redirect route when requesting it directly by browser', async () => { | ||
const browser = await webdriver(next.url, '/a') | ||
expect(await browser.waitForElementByCss('#a-page').text()).toBe('A page') | ||
}) | ||
|
||
it('should redirect route when clicking link', async () => { | ||
const browser = await webdriver(next.url, '/') | ||
await browser | ||
.elementByCss('#to-a-trailing-slash') | ||
.click() | ||
.waitForElementByCss('#a-page') | ||
expect(await browser.waitForElementByCss('#a-page').text()).toBe('A page') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import Link from 'next/link' | ||
export default function HomePage() { | ||
return ( | ||
<> | ||
<h1 id="a-page">A page</h1> | ||
<Link href="/">To home</Link> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export default function Root({ children }) { | ||
return ( | ||
<html> | ||
<head> | ||
<title>Hello</title> | ||
</head> | ||
<body>{children}</body> | ||
</html> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import Link from 'next/link' | ||
export default function HomePage() { | ||
return ( | ||
<> | ||
<p> | ||
<Link href="/a/"> | ||
<a id="to-a-trailing-slash">To a with trailing slash</a> | ||
</Link> | ||
</p> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module.exports = { | ||
experimental: { | ||
appDir: true, | ||
serverComponents: true, | ||
legacyBrowsers: false, | ||
browsersListForSwc: true, | ||
}, | ||
trailingSlash: true, | ||
} |