From 1f9e958e97253eabdcf488c4787547fda0ef75e7 Mon Sep 17 00:00:00 2001 From: Jamie <5964236+jamsinclair@users.noreply.github.com> Date: Thu, 20 May 2021 21:39:56 +0900 Subject: [PATCH] Follow up rewrites regression test for #25208 (#25282) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 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? 😸 --- azure-pipelines.yml | 2 +- .../rewrites-has-condition/next.config.js | 20 ++++++ .../rewrites-has-condition/pages/another.js | 13 ++++ .../rewrites-has-condition/test/index.test.js | 72 +++++++++++++++++++ 4 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 test/integration/rewrites-has-condition/next.config.js create mode 100644 test/integration/rewrites-has-condition/pages/another.js create mode 100644 test/integration/rewrites-has-condition/test/index.test.js diff --git a/azure-pipelines.yml b/azure-pipelines.yml index da99194581a41..57857e0a62e33 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -86,7 +86,7 @@ stages: path: $(System.DefaultWorkingDirectory) displayName: Cache Build - script: | - yarn testie --forceExit test/integration/production/ test/integration/css-client-nav/ + yarn testie --forceExit test/integration/production/ test/integration/css-client-nav/ test/integration/rewrites-has-condition/ displayName: 'Run tests' - job: test_unit diff --git a/test/integration/rewrites-has-condition/next.config.js b/test/integration/rewrites-has-condition/next.config.js new file mode 100644 index 0000000000000..346841c3271ae --- /dev/null +++ b/test/integration/rewrites-has-condition/next.config.js @@ -0,0 +1,20 @@ +module.exports = { + rewrites() { + return [ + { + source: '/rewrite-simple', + destination: '/another', + }, + { + source: '/rewrite-with-has', + has: [ + { + type: 'query', + key: 'hasQuery', + }, + ], + destination: '/another', + }, + ] + }, +} diff --git a/test/integration/rewrites-has-condition/pages/another.js b/test/integration/rewrites-has-condition/pages/another.js new file mode 100644 index 0000000000000..35f8a8cd28a9e --- /dev/null +++ b/test/integration/rewrites-has-condition/pages/another.js @@ -0,0 +1,13 @@ +import { useRouter } from 'next/router' + +export default function Page() { + const router = useRouter() + + return ( + <> +

another page

+

{router.pathname}

+

{JSON.stringify(router.query)}

+ + ) +} diff --git a/test/integration/rewrites-has-condition/test/index.test.js b/test/integration/rewrites-has-condition/test/index.test.js new file mode 100644 index 0000000000000..8ada5130e3fb8 --- /dev/null +++ b/test/integration/rewrites-has-condition/test/index.test.js @@ -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() + }) +})