Skip to content

Commit

Permalink
Improve Nested Catch-All Coverage (#10659)
Browse files Browse the repository at this point in the history
* Improve Nested Catch-All Coverage

* use check
  • Loading branch information
Timer committed Feb 24, 2020
1 parent 51b35f1 commit c3f11c2
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 15 deletions.
2 changes: 1 addition & 1 deletion test/integration/prerender/pages/catchall/[...slug].js
Expand Up @@ -29,5 +29,5 @@ export default ({ slug }) => {
if (isFallback) {
return <p id="catchall">fallback</p>
}
return <p id="catchall">Hi {slug.join('/')}</p>
return <p id="catchall">Hi {slug.join(' ')}</p>
}
61 changes: 47 additions & 14 deletions test/integration/prerender/test/index.test.js
@@ -1,26 +1,27 @@
/* eslint-env jest */
/* global jasmine */
import fs from 'fs-extra'
import { join, dirname } from 'path'
import cheerio from 'cheerio'
import webdriver from 'next-webdriver'
import escapeRegex from 'escape-string-regexp'
import fs from 'fs-extra'
import {
renderViaHTTP,
check,
fetchViaHTTP,
findPort,
launchApp,
getReactErrorOverlayContent,
initNextServerScript,
killApp,
waitFor,
launchApp,
nextBuild,
nextStart,
stopApp,
nextExport,
nextStart,
normalizeRegEx,
renderViaHTTP,
startStaticServer,
initNextServerScript,
getReactErrorOverlayContent,
stopApp,
waitFor,
} from 'next-test-utils'
import webdriver from 'next-webdriver'
import { dirname, join } from 'path'

jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 2
const appDir = join(__dirname, '..')
Expand Down Expand Up @@ -376,7 +377,7 @@ const runTests = (dev = false, looseMode = false) => {
.text()
).isFallback
).toBe(false)
expect($('#catchall').text()).toMatch(/Hi.*?another\/value/)
expect($('#catchall').text()).toMatch(/Hi.*?another value/)
})

it('should support lazy catchall route', async () => {
Expand All @@ -398,10 +399,42 @@ const runTests = (dev = false, looseMode = false) => {
const text1 = await browser.elementByCss('#catchall').text()
expect(text1).toBe('fallback')

await new Promise(resolve => setTimeout(resolve, 4000))
await check(
() => browser.elementByCss('#catchall').text(),
/Hi.*?delayby3s/
)
}
})

it('should support nested lazy catchall route', async () => {
// Dev doesn't support fallback yet
if (dev) {
const html = await renderViaHTTP(
appPort,
'/catchall/notreturnedinpaths/nested'
)
const $ = cheerio.load(html)
expect($('#catchall').text()).toMatch(/Hi.*?notreturnedinpaths nested/)
}
// Production will render fallback for a "lazy" route
else {
const html = await renderViaHTTP(
appPort,
'/catchall/notreturnedinpaths/nested'
)
const $ = cheerio.load(html)
expect($('#catchall').text()).toBe('fallback')

// hydration
const browser = await webdriver(appPort, '/catchall/delayby3s/nested')

const text2 = await browser.elementByCss('#catchall').text()
expect(text2).toMatch(/Hi.*?delayby3s/)
const text1 = await browser.elementByCss('#catchall').text()
expect(text1).toBe('fallback')

await check(
() => browser.elementByCss('#catchall').text(),
/Hi.*?delayby3s nested/
)
}
})

Expand Down

0 comments on commit c3f11c2

Please sign in to comment.