Skip to content

Commit

Permalink
test: fix test in turbopack dev
Browse files Browse the repository at this point in the history
  • Loading branch information
lubieowoce committed Nov 21, 2024
1 parent b5de7fb commit aad1684
Showing 1 changed file with 66 additions and 63 deletions.
129 changes: 66 additions & 63 deletions test/integration/custom-server/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
})
})
})

0 comments on commit aad1684

Please sign in to comment.