Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update failing tests from upstream resource #34110

Merged
merged 3 commits into from Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/integration/custom-routes/next.config.js
Expand Up @@ -222,7 +222,7 @@ module.exports = {
},
{
source: '/overridden',
destination: 'https://example.com',
destination: 'https://vercel.com',
},
],
}
Expand Down
33 changes: 19 additions & 14 deletions test/integration/custom-routes/test/index.test.js
Expand Up @@ -39,19 +39,6 @@ let appPort
let app

const runTests = (isDev = false) => {
it('should handle external beforeFiles rewrite correctly', async () => {
const res = await fetchViaHTTP(appPort, '/overridden')
expect(res.status).toBe(200)
expect(await res.text()).toContain('Example Domain')

const browser = await webdriver(appPort, '/nav')
await browser.elementByCss('#to-before-files-overridden').click()
await check(
() => browser.eval('document.documentElement.innerHTML'),
/Example Domain/
)
})

it('should handle has query encoding correctly', async () => {
for (const expected of [
{
Expand Down Expand Up @@ -94,6 +81,24 @@ const runTests = (isDev = false) => {
}
})

it('should handle external beforeFiles rewrite correctly', async () => {
const res = await fetchViaHTTP(appPort, '/overridden')
const html = await res.text()

if (res.status !== 200) {
console.error('Invalid response', html)
}
expect(res.status).toBe(200)
expect(html).toContain('Vercel')

const browser = await webdriver(appPort, '/nav')
await browser.elementByCss('#to-before-files-overridden').click()
await check(
() => browser.eval('document.documentElement.innerHTML'),
/Vercel/
)
})

it('should support long URLs for rewrites', async () => {
const res = await fetchViaHTTP(
appPort,
Expand Down Expand Up @@ -1711,7 +1716,7 @@ const runTests = (isDev = false) => {
source: '/old-blog/:path*',
},
{
destination: 'https://example.com',
destination: 'https://vercel.com',
regex: normalizeRegEx('^\\/overridden(?:\\/)?$'),
source: '/overridden',
},
Expand Down
Expand Up @@ -12,7 +12,7 @@ export async function middleware(request) {
) {
const isExternal = url.searchParams.get('override') === 'external'
return NextResponse.rewrite(
isExternal ? 'https://example.com' : '/rewrites/a'
isExternal ? 'https://vercel.com' : '/rewrites/a'
)
}

Expand Down
14 changes: 8 additions & 6 deletions test/integration/middleware/core/test/index.test.js
Expand Up @@ -165,7 +165,7 @@ function rewriteTests(log, locale = '') {
it('should override with rewrite internally correctly', async () => {
const res = await fetchViaHTTP(
context.appPort,
'/rewrites/about',
`${locale}/rewrites/about`,
{ override: 'internal' },
{ redirect: 'manual' }
)
Expand All @@ -190,24 +190,26 @@ function rewriteTests(log, locale = '') {
it('should override with rewrite externally correctly', async () => {
const res = await fetchViaHTTP(
context.appPort,
'/rewrites/about',
`${locale}/rewrites/about`,
{ override: 'external' },
{ redirect: 'manual' }
)

expect(res.status).toBe(200)
expect(await res.text()).toContain('Example Domain')
expect(await res.text()).toContain('Vercel')

const browser = await webdriver(context.appPort, `${locale}/rewrites`)
await browser.elementByCss('#override-with-external-rewrite').click()
await check(
() => browser.eval('document.documentElement.innerHTML'),
/Example Domain/
/Vercel/
)
expect(await browser.eval('window.location.pathname')).toBe(
await check(
() => browser.eval('window.location.pathname'),
`${locale || ''}/rewrites/about`
)
expect(await browser.eval('window.location.search')).toBe(
await check(
() => browser.eval('window.location.search'),
'?override=external'
)
})
Expand Down