Skip to content

Commit

Permalink
Update failing tests from upstream resource (#34110)
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk committed Feb 8, 2022
1 parent 1efa892 commit 3f0a8d9
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 22 deletions.
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

0 comments on commit 3f0a8d9

Please sign in to comment.