-
Notifications
You must be signed in to change notification settings - Fork 27.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Break assetPrefix app tests into separate suite (#40701)
As discussed in slack this breaks out the `assetPrefix` tests to a separate suite to speed up the main `app` suite. x-ref: [slack thread](https://vercel.slack.com/archives/C035J346QQL/p1663623560467579)
- Loading branch information
Showing
7 changed files
with
113 additions
and
19 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
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 assetPrefix 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, 'asset-prefix')), | ||
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', 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,14 @@ | ||
module.exports = { | ||
experimental: { | ||
appDir: true, | ||
serverComponents: true, | ||
legacyBrowsers: false, | ||
browsersListForSwc: true, | ||
}, | ||
assetPrefix: '/assets', | ||
rewrites() { | ||
return { | ||
beforeFiles: [{ source: '/assets/:path*', destination: '/:path*' }], | ||
} | ||
}, | ||
} |
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