Commit d8ece3e2 authored by Janka Uryga's avatar Janka Uryga

test: convert app-static.test.ts to nextTestSetup

parent a4ff1329
...@@ -2,7 +2,7 @@ import globOrig from 'glob' ...@@ -2,7 +2,7 @@ import globOrig from 'glob'
import cheerio from 'cheerio' import cheerio from 'cheerio'
import { promisify } from 'util' import { promisify } from 'util'
import { join } from 'path' import { join } from 'path'
import { createNextDescribe } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
import { import {
check, check,
fetchViaHTTP, fetchViaHTTP,
...@@ -14,9 +14,13 @@ import stripAnsi from 'strip-ansi' ...@@ -14,9 +14,13 @@ import stripAnsi from 'strip-ansi'
const glob = promisify(globOrig) const glob = promisify(globOrig)
createNextDescribe( describe('app-dir static/dynamic handling', () => {
'app-dir static/dynamic handling', const {
{ next,
isNextDev: isDev,
isNextStart,
isNextDeploy,
} = nextTestSetup({
files: __dirname, files: __dirname,
env: { env: {
NEXT_DEBUG_BUILD: '1', NEXT_DEBUG_BUILD: '1',
...@@ -26,8 +30,7 @@ createNextDescribe( ...@@ -26,8 +30,7 @@ createNextDescribe(
} }
: {}), : {}),
}, },
}, })
({ next, isNextDev: isDev, isNextStart, isNextDeploy }) => {
let prerenderManifest let prerenderManifest
let buildCliOutputIndex = 0 let buildCliOutputIndex = 0
...@@ -115,9 +118,7 @@ createNextDescribe( ...@@ -115,9 +118,7 @@ createNextDescribe(
'.next/server/app/variable-revalidate/revalidate-360-isr.meta' '.next/server/app/variable-revalidate/revalidate-360-isr.meta'
) )
) )
expect(meta.headers['x-next-cache-tags']).toContain( expect(meta.headers['x-next-cache-tags']).toContain('unstable_cache_tag1')
'unstable_cache_tag1'
)
}) })
if (!process.env.CUSTOM_CACHE_HANDLER) { if (!process.env.CUSTOM_CACHE_HANDLER) {
...@@ -324,9 +325,7 @@ createNextDescribe( ...@@ -324,9 +325,7 @@ createNextDescribe(
])( ])(
'it should revalidate tag correctly with $type', 'it should revalidate tag correctly with $type',
async ({ revalidateApi }) => { async ({ revalidateApi }) => {
const initRes = await next.fetch( const initRes = await next.fetch('/variable-revalidate/revalidate-360')
'/variable-revalidate/revalidate-360'
)
const html = await initRes.text() const html = await initRes.text()
const $ = cheerio.load(html) const $ = cheerio.load(html)
const initLayoutData = $('#layout-data').text() const initLayoutData = $('#layout-data').text()
...@@ -352,9 +351,7 @@ createNextDescribe( ...@@ -352,9 +351,7 @@ createNextDescribe(
) )
expect((await revalidateRes.json()).revalidated).toBe(true) expect((await revalidateRes.json()).revalidated).toBe(true)
const newRes = await next.fetch( const newRes = await next.fetch('/variable-revalidate/revalidate-360')
'/variable-revalidate/revalidate-360'
)
const cacheHeader = newRes.headers.get('x-nextjs-cache') const cacheHeader = newRes.headers.get('x-nextjs-cache')
if ((global as any).isNextStart && cacheHeader) { if ((global as any).isNextStart && cacheHeader) {
...@@ -535,9 +532,7 @@ createNextDescribe( ...@@ -535,9 +532,7 @@ createNextDescribe(
// wait for a fresh revalidation // wait for a fresh revalidation
await check(async () => { await check(async () => {
const $ = await next.render$( const $ = await next.render$('/variable-config-revalidate/revalidate-3')
'/variable-config-revalidate/revalidate-3'
)
prevInitialDate = $('#date').text() prevInitialDate = $('#date').text()
prevInitialRandomData = $('#random-data').text() prevInitialRandomData = $('#random-data').text()
...@@ -549,9 +544,7 @@ createNextDescribe( ...@@ -549,9 +544,7 @@ createNextDescribe(
// the date should revalidate first after 3 seconds // the date should revalidate first after 3 seconds
// while the fetch data stays in place for 9 seconds // while the fetch data stays in place for 9 seconds
await check(async () => { await check(async () => {
const $ = await next.render$( const $ = await next.render$('/variable-config-revalidate/revalidate-3')
'/variable-config-revalidate/revalidate-3'
)
const curDate = $('#date').text() const curDate = $('#date').text()
const curRandomData = $('#random-data').text() const curRandomData = $('#random-data').text()
...@@ -2024,9 +2017,7 @@ createNextDescribe( ...@@ -2024,9 +2017,7 @@ createNextDescribe(
const curHtml = await curRes.text() const curHtml = await curRes.text()
const cur$ = cheerio.load(curHtml) const cur$ = cheerio.load(curHtml)
expect(cur$('#data-no-cache').text()).toBe( expect(cur$('#data-no-cache').text()).toBe(prev$('#data-no-cache').text())
prev$('#data-no-cache').text()
)
expect(cur$('#data-force-cache').text()).toBe( expect(cur$('#data-force-cache').text()).toBe(
prev$('#data-force-cache').text() prev$('#data-force-cache').text()
) )
...@@ -2637,10 +2628,7 @@ createNextDescribe( ...@@ -2637,10 +2628,7 @@ createNextDescribe(
it('should cache correctly with utf8 encoding', async () => { it('should cache correctly with utf8 encoding', async () => {
await check(async () => { await check(async () => {
const res = await fetchViaHTTP( const res = await fetchViaHTTP(next.url, '/variable-revalidate/encoding')
next.url,
'/variable-revalidate/encoding'
)
expect(res.status).toBe(200) expect(res.status).toBe(200)
const html = await res.text() const html = await res.text()
const $ = cheerio.load(html) const $ = cheerio.load(html)
...@@ -2652,10 +2640,7 @@ createNextDescribe( ...@@ -2652,10 +2640,7 @@ createNextDescribe(
'超鬼畜!激辛ボム兵スピンジャンプ Bomb Spin Jump' '超鬼畜!激辛ボム兵スピンジャンプ Bomb Spin Jump'
) )
const res2 = await fetchViaHTTP( const res2 = await fetchViaHTTP(next.url, '/variable-revalidate/encoding')
next.url,
'/variable-revalidate/encoding'
)
expect(res2.status).toBe(200) expect(res2.status).toBe(200)
const html2 = await res2.text() const html2 = await res2.text()
const $2 = cheerio.load(html2) const $2 = cheerio.load(html2)
...@@ -2699,10 +2684,7 @@ createNextDescribe( ...@@ -2699,10 +2684,7 @@ createNextDescribe(
it('should cache correctly handle JSON body', async () => { it('should cache correctly handle JSON body', async () => {
await check(async () => { await check(async () => {
const res = await fetchViaHTTP( const res = await fetchViaHTTP(next.url, '/variable-revalidate-edge/body')
next.url,
'/variable-revalidate-edge/body'
)
expect(res.status).toBe(200) expect(res.status).toBe(200)
const html = await res.text() const html = await res.text()
const $ = cheerio.load(html) const $ = cheerio.load(html)
...@@ -2729,9 +2711,7 @@ createNextDescribe( ...@@ -2729,9 +2711,7 @@ createNextDescribe(
it('should not throw Dynamic Server Usage error when using generateStaticParams with draftMode', async () => { it('should not throw Dynamic Server Usage error when using generateStaticParams with draftMode', async () => {
const browserOnIndexPage = await next.browser('/ssg-draft-mode') const browserOnIndexPage = await next.browser('/ssg-draft-mode')
const content = await browserOnIndexPage const content = await browserOnIndexPage.elementByCss('#draft-mode').text()
.elementByCss('#draft-mode')
.text()
expect(content).toBe('{"isEnabled":false}') expect(content).toBe('{"isEnabled":false}')
}) })
...@@ -2981,9 +2961,7 @@ createNextDescribe( ...@@ -2981,9 +2961,7 @@ createNextDescribe(
await browser.elementByCss('#author-2').click() await browser.elementByCss('#author-2').click()
await check(async () => { await check(async () => {
const params = JSON.parse( const params = JSON.parse(await browser.elementByCss('#params').text())
await browser.elementByCss('#params').text()
)
return params.author === 'seb' ? 'found' : params return params.author === 'seb' ? 'found' : params
}, 'found') }, 'found')
...@@ -2991,9 +2969,7 @@ createNextDescribe( ...@@ -2991,9 +2969,7 @@ createNextDescribe(
await browser.elementByCss('#author-1-post-1').click() await browser.elementByCss('#author-1-post-1').click()
await check(async () => { await check(async () => {
const params = JSON.parse( const params = JSON.parse(await browser.elementByCss('#params').text())
await browser.elementByCss('#params').text()
)
return params.author === 'tim' && params.slug === 'first-post' return params.author === 'tim' && params.slug === 'first-post'
? 'found' ? 'found'
: params : params
...@@ -3003,9 +2979,7 @@ createNextDescribe( ...@@ -3003,9 +2979,7 @@ createNextDescribe(
await browser.back() await browser.back()
await check(async () => { await check(async () => {
const params = JSON.parse( const params = JSON.parse(await browser.elementByCss('#params').text())
await browser.elementByCss('#params').text()
)
return params.author === 'seb' ? 'found' : params return params.author === 'seb' ? 'found' : params
}, 'found') }, 'found')
...@@ -3117,9 +3091,7 @@ createNextDescribe( ...@@ -3117,9 +3091,7 @@ createNextDescribe(
'/hooks/use-search-params/with-suspense?first=value&second=other&third' '/hooks/use-search-params/with-suspense?first=value&second=other&third'
const browser = await next.browser(url) const browser = await next.browser(url)
expect(await browser.elementByCss('#params-first').text()).toBe( expect(await browser.elementByCss('#params-first').text()).toBe('value')
'value'
)
expect(await browser.elementByCss('#params-second').text()).toBe( expect(await browser.elementByCss('#params-second').text()).toBe(
'other' 'other'
) )
...@@ -3140,9 +3112,7 @@ createNextDescribe( ...@@ -3140,9 +3112,7 @@ createNextDescribe(
) )
expect(await browser.elementByCss('#params-first').text()).toBe('N/A') expect(await browser.elementByCss('#params-first').text()).toBe('N/A')
expect(await browser.elementByCss('#params-second').text()).toBe( expect(await browser.elementByCss('#params-second').text()).toBe('N/A')
'N/A'
)
expect(await browser.elementByCss('#params-third').text()).toBe('N/A') expect(await browser.elementByCss('#params-third').text()).toBe('N/A')
expect(await browser.elementByCss('#params-not-real').text()).toBe( expect(await browser.elementByCss('#params-not-real').text()).toBe(
'N/A' 'N/A'
...@@ -3168,9 +3138,7 @@ createNextDescribe( ...@@ -3168,9 +3138,7 @@ createNextDescribe(
) )
expect(await browser.elementByCss('#params-first').text()).toBe('a') expect(await browser.elementByCss('#params-first').text()).toBe('a')
expect(await browser.elementByCss('#params-second').text()).toBe( expect(await browser.elementByCss('#params-second').text()).toBe('b')
'b'
)
expect(await browser.elementByCss('#params-third').text()).toBe('c') expect(await browser.elementByCss('#params-third').text()).toBe('c')
expect(await browser.elementByCss('#params-not-real').text()).toBe( expect(await browser.elementByCss('#params-not-real').text()).toBe(
'N/A' 'N/A'
...@@ -3182,9 +3150,7 @@ createNextDescribe( ...@@ -3182,9 +3150,7 @@ createNextDescribe(
if (!isDev) { if (!isDev) {
describe('server response', () => { describe('server response', () => {
it('should bailout to client rendering - with suspense boundary', async () => { it('should bailout to client rendering - with suspense boundary', async () => {
const res = await next.fetch( const res = await next.fetch('/hooks/use-search-params/with-suspense')
'/hooks/use-search-params/with-suspense'
)
const html = await res.text() const html = await res.text()
expect(html).toInclude('<p>search params suspense</p>') expect(html).toInclude('<p>search params suspense</p>')
}) })
...@@ -3375,8 +3341,7 @@ createNextDescribe( ...@@ -3375,8 +3341,7 @@ createNextDescribe(
await check(async () => { await check(async () => {
expect( expect(
next.cliOutput.substring(cliOutputStart).match(/Load data/g) next.cliOutput.substring(cliOutputStart).match(/Load data/g).length
.length
).toBe(2) ).toBe(2)
expect(next.cliOutput.substring(cliOutputStart)).toContain( expect(next.cliOutput.substring(cliOutputStart)).toContain(
'Error: Failed to set Next.js data cache, items over 2MB can not be cached' 'Error: Failed to set Next.js data cache, items over 2MB can not be cached'
...@@ -3403,8 +3368,7 @@ createNextDescribe( ...@@ -3403,8 +3368,7 @@ createNextDescribe(
await check(async () => { await check(async () => {
expect( expect(
next.cliOutput.substring(cliOutputStart).match(/Load data/g) next.cliOutput.substring(cliOutputStart).match(/Load data/g).length
.length
).toBe(1) ).toBe(1)
return 'success' return 'success'
}, 'success') }, 'success')
...@@ -3420,5 +3384,4 @@ createNextDescribe( ...@@ -3420,5 +3384,4 @@ createNextDescribe(
const browser = await next.browser('/dynamic-param-edge/hello') const browser = await next.browser('/dynamic-param-edge/hello')
expect(await browser.elementByCss('#slug').text()).toBe('hello') expect(await browser.elementByCss('#slug').text()).toBe('hello')
}) })
} })
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment