-
Notifications
You must be signed in to change notification settings - Fork 26.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
## Summary Follow up regression test for rewrites with a `has` condition throwing errors in older browsers #25208. @timneutkens Let me know if this is what you had in mind? 😸
- Loading branch information
1 parent
14cedc7
commit 1f9e958
Showing
4 changed files
with
106 additions
and
1 deletion.
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,20 @@ | ||
module.exports = { | ||
rewrites() { | ||
return [ | ||
{ | ||
source: '/rewrite-simple', | ||
destination: '/another', | ||
}, | ||
{ | ||
source: '/rewrite-with-has', | ||
has: [ | ||
{ | ||
type: 'query', | ||
key: 'hasQuery', | ||
}, | ||
], | ||
destination: '/another', | ||
}, | ||
] | ||
}, | ||
} |
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,13 @@ | ||
import { useRouter } from 'next/router' | ||
|
||
export default function Page() { | ||
const router = useRouter() | ||
|
||
return ( | ||
<> | ||
<p id="another">another page</p> | ||
<p id="pathname">{router.pathname}</p> | ||
<p id="query">{JSON.stringify(router.query)}</p> | ||
</> | ||
) | ||
} |
72 changes: 72 additions & 0 deletions
72
test/integration/rewrites-has-condition/test/index.test.js
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,72 @@ | ||
/* eslint-env jest */ | ||
|
||
import { join } from 'path' | ||
import { | ||
findPort, | ||
killApp, | ||
launchApp, | ||
nextBuild, | ||
nextStart, | ||
} from 'next-test-utils' | ||
import webdriver from 'next-webdriver' | ||
|
||
jest.setTimeout(1000 * 60 * 2) | ||
|
||
const appDir = join(__dirname, '../') | ||
|
||
let appPort | ||
let app | ||
|
||
const runTests = () => { | ||
it('should load page rewrite without browser errors', async () => { | ||
const browser = await webdriver(appPort, '/rewrite-simple') | ||
|
||
expect(await browser.waitForElementByCss('#another').text()).toBe( | ||
'another page' | ||
) | ||
|
||
const browserLogs = await browser.log('browser') | ||
const errorLogs = browserLogs.filter((log) => { | ||
return log.level.name === 'SEVERE' && log.message.includes('Error:') | ||
}) | ||
expect(errorLogs).toEqual([]) | ||
}) | ||
|
||
// Regression test for https://github.com/vercel/next.js/issues/25207 | ||
it('should load page rewrite, with "has" condition, without browser errors', async () => { | ||
const browser = await webdriver(appPort, '/rewrite-with-has?hasQuery=123') | ||
|
||
expect(await browser.waitForElementByCss('#another').text()).toBe( | ||
'another page' | ||
) | ||
|
||
const browserLogs = await browser.log('browser') | ||
const errorLogs = browserLogs.filter((log) => { | ||
return log.level.name === 'SEVERE' && log.message.includes('Error:') | ||
}) | ||
expect(errorLogs).toEqual([]) | ||
}) | ||
} | ||
|
||
describe('rewrites has condition', () => { | ||
describe('dev mode', () => { | ||
beforeAll(async () => { | ||
appPort = await findPort() | ||
app = await launchApp(appDir, appPort) | ||
}) | ||
afterAll(() => killApp(app)) | ||
|
||
runTests() | ||
}) | ||
|
||
describe('production mode', () => { | ||
beforeAll(async () => { | ||
await nextBuild(appDir) | ||
appPort = await findPort() | ||
app = await nextStart(appDir, appPort) | ||
}) | ||
afterAll(() => killApp(app)) | ||
|
||
runTests() | ||
}) | ||
}) |