From 2a260bca88c925d35d2afe87b62b8efeca0094b4 Mon Sep 17 00:00:00 2001 From: Joe Haddad Date: Mon, 24 Feb 2020 08:33:21 -0500 Subject: [PATCH 1/2] Improve Nested Catch-All Coverage --- .../prerender/pages/catchall/[...slug].js | 2 +- test/integration/prerender/test/index.test.js | 34 ++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/test/integration/prerender/pages/catchall/[...slug].js b/test/integration/prerender/pages/catchall/[...slug].js index c2ff67739caf080..b0010c612446468 100644 --- a/test/integration/prerender/pages/catchall/[...slug].js +++ b/test/integration/prerender/pages/catchall/[...slug].js @@ -29,5 +29,5 @@ export default ({ slug }) => { if (isFallback) { return

fallback

} - return

Hi {slug.join('/')}

+ return

Hi {slug.join(' ')}

} diff --git a/test/integration/prerender/test/index.test.js b/test/integration/prerender/test/index.test.js index bb2350a74c78ab6..638151a5b3356f3 100644 --- a/test/integration/prerender/test/index.test.js +++ b/test/integration/prerender/test/index.test.js @@ -376,7 +376,7 @@ const runTests = (dev = 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 () => { @@ -405,6 +405,38 @@ const runTests = (dev = false) => { } }) + 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 text1 = await browser.elementByCss('#catchall').text() + expect(text1).toBe('fallback') + + await new Promise(resolve => setTimeout(resolve, 4000)) + + const text2 = await browser.elementByCss('#catchall').text() + expect(text2).toMatch(/Hi.*?delayby3s nested/) + } + }) + if (dev) { // TODO: re-enable when this is supported in dev // it('should show error when rewriting to dynamic SSG page', async () => { From cbb15a16cad6e980a3008ff8055393329010f2e2 Mon Sep 17 00:00:00 2001 From: Joe Haddad Date: Mon, 24 Feb 2020 11:23:25 -0500 Subject: [PATCH 2/2] use check --- test/integration/prerender/test/index.test.js | 37 ++++++++++--------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/test/integration/prerender/test/index.test.js b/test/integration/prerender/test/index.test.js index e7bedeea59e3120..5d16451c997d38f 100644 --- a/test/integration/prerender/test/index.test.js +++ b/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, '..') @@ -398,10 +399,10 @@ const runTests = (dev = false, looseMode = false) => { const text1 = await browser.elementByCss('#catchall').text() expect(text1).toBe('fallback') - await new Promise(resolve => setTimeout(resolve, 4000)) - - const text2 = await browser.elementByCss('#catchall').text() - expect(text2).toMatch(/Hi.*?delayby3s/) + await check( + () => browser.elementByCss('#catchall').text(), + /Hi.*?delayby3s/ + ) } }) @@ -430,10 +431,10 @@ const runTests = (dev = false, looseMode = false) => { const text1 = await browser.elementByCss('#catchall').text() expect(text1).toBe('fallback') - await new Promise(resolve => setTimeout(resolve, 4000)) - - const text2 = await browser.elementByCss('#catchall').text() - expect(text2).toMatch(/Hi.*?delayby3s nested/) + await check( + () => browser.elementByCss('#catchall').text(), + /Hi.*?delayby3s nested/ + ) } })