From aad1684a875ffa96d699babcafc8be51daf80596 Mon Sep 17 00:00:00 2001 From: Janka Uryga Date: Thu, 21 Nov 2024 14:40:14 +0100 Subject: [PATCH] test: fix test in turbopack dev --- .../custom-server/test/index.test.js | 129 +++++++++--------- 1 file changed, 66 insertions(+), 63 deletions(-) diff --git a/test/integration/custom-server/test/index.test.js b/test/integration/custom-server/test/index.test.js index bf64a636329c46..6d7b20e8dd9ac3 100644 --- a/test/integration/custom-server/test/index.test.js +++ b/test/integration/custom-server/test/index.test.js @@ -318,71 +318,74 @@ describe.each([ }) }) - describe.each(['development', 'production'])( - 'legacy NextCustomServer methods - %s mode', - (mode) => { - const isNextDev = mode === 'development' + const modes = process.env.TURBOPACK_DEV + ? ['development'] + : process.env.TURBOPACK_BUILD + ? ['production'] + : ['development', 'production'] + + describe.each(modes)('legacy NextCustomServer methods - %s mode', (mode) => { + const isNextDev = mode === 'development' + + beforeAll(async () => { + if (!isNextDev) { + await nextBuild(appDir) + } + await startServer({ NODE_ENV: mode }) + }) + afterAll(() => killApp(server)) - beforeAll(async () => { - if (!isNextDev) { - await nextBuild(appDir) - } - await startServer({ NODE_ENV: mode }) - }) - afterAll(() => killApp(server)) - - it('NextCustomServer.renderToHTML', async () => { - const rawHTML = await renderViaHTTP( - nextUrl, - '/legacy-methods/render-to-html?q=2', - undefined, - { agent } - ) - const $ = cheerio.load(rawHTML) - const text = $('p').text() - expect(text).toContain('made it to dynamic dashboard') - expect(text).toContain('query param: 1') - }) + it('NextCustomServer.renderToHTML', async () => { + const rawHTML = await renderViaHTTP( + nextUrl, + '/legacy-methods/render-to-html?q=2', + undefined, + { agent } + ) + const $ = cheerio.load(rawHTML) + const text = $('p').text() + expect(text).toContain('made it to dynamic dashboard') + expect(text).toContain('query param: 1') + }) - it('NextCustomServer.render404', async () => { - const html = await renderViaHTTP( - nextUrl, - '/legacy-methods/render404', - undefined, - { agent } - ) - expect(html).toContain('made it to 404') - }) + it('NextCustomServer.render404', async () => { + const html = await renderViaHTTP( + nextUrl, + '/legacy-methods/render404', + undefined, + { agent } + ) + expect(html).toContain('made it to 404') + }) - it('NextCustomServer.renderError', async () => { - const html = await renderViaHTTP( - nextUrl, - '/legacy-methods/render-error', - undefined, - { agent } - ) - if (isNextDev) { - // in dev, we always render error overlay + default error page, not /500 - expect(html).toContain('Error: kaboom') - } else { - expect(html).toContain('made it to 500') - } - }) + it('NextCustomServer.renderError', async () => { + const html = await renderViaHTTP( + nextUrl, + '/legacy-methods/render-error', + undefined, + { agent } + ) + if (isNextDev) { + // in dev, we always render error overlay + default error page, not /500 + expect(html).toContain('Error: kaboom') + } else { + expect(html).toContain('made it to 500') + } + }) - it('NextCustomServer.renderErrorToHTML', async () => { - const html = await renderViaHTTP( - nextUrl, - '/legacy-methods/render-error-to-html', - undefined, - { agent } - ) - if (isNextDev) { - // in dev, we always render error overlay + default error page, not /500 - expect(html).toContain('Error: kaboom') - } else { - expect(html).toContain('made it to 500') - } - }) - } - ) + it('NextCustomServer.renderErrorToHTML', async () => { + const html = await renderViaHTTP( + nextUrl, + '/legacy-methods/render-error-to-html', + undefined, + { agent } + ) + if (isNextDev) { + // in dev, we always render error overlay + default error page, not /500 + expect(html).toContain('Error: kaboom') + } else { + expect(html).toContain('made it to 500') + } + }) + }) })