Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 55 additions & 42 deletions test/integration/dynamic-routing/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ let buildId
const appDir = join(__dirname, '../')
const buildIdPath = join(appDir, '.next/BUILD_ID')

function runTests({ dev }) {
function runTests({
dev,
withMiddleware,
}: {
dev: boolean
withMiddleware: boolean
}) {
if (!dev) {
it('should have correct cache entries on prefetch', async () => {
const browser = await webdriver(appPort, '/')
Expand All @@ -46,7 +52,7 @@ function runTests({ dev }) {

const cacheKeys = await getCacheKeys()
expect(cacheKeys).toEqual(
process.env.__MIDDLEWARE_TEST
withMiddleware
? [
'/_next/data/BUILD_ID/[name].json?another=value&name=%5Bname%5D',
'/_next/data/BUILD_ID/added-later/first.json?name=added-later&comment=first',
Expand Down Expand Up @@ -117,7 +123,7 @@ function runTests({ dev }) {
const newCacheKeys = await getCacheKeys()
expect(newCacheKeys).toEqual(
[
...(process.env.__MIDDLEWARE_TEST
...(withMiddleware
? // data route is fetched with middleware due to query hydration
// since middleware matches the index route
['/_next/data/BUILD_ID/index.json']
Expand Down Expand Up @@ -1205,7 +1211,7 @@ function runTests({ dev }) {
expect(text).toBe('slug: first')
})

if (!process.env.__MIDDLEWARE_TEST) {
if (!withMiddleware) {
it('should show error when interpolating fails for href', async () => {
const browser = await webdriver(appPort, '/')
await browser
Expand Down Expand Up @@ -1583,54 +1589,61 @@ function runTests({ dev }) {

const nextConfig = join(appDir, 'next.config.js')

describe('Dynamic Routing', () => {
if (process.env.__MIDDLEWARE_TEST) {
describe.each([{ withMiddleware: false }, { withMiddleware: true }])(
'Dynamic Routing (withMiddleware: $withMiddleware)',
({ withMiddleware }) => {
const middlewarePath = join(__dirname, '../middleware.js')

beforeAll(async () => {
await fs.writeFile(
middlewarePath,
`
if (withMiddleware) {
await fs.writeFile(
middlewarePath,
`
import { NextResponse } from 'next/server'
export default function middleware() {
return NextResponse.next()
}
`
)
)
}
})
afterAll(() => fs.remove(middlewarePath))
}

;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
await fs.remove(nextConfig)
afterAll(async () => {
if (withMiddleware) {
await fs.remove(middlewarePath)
}
})
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
await fs.remove(nextConfig)

appPort = await findPort()
app = await launchApp(appDir, appPort)
buildId = 'development'
})
afterAll(() => killApp(app))

appPort = await findPort()
app = await launchApp(appDir, appPort)
buildId = 'development'
})
afterAll(() => killApp(app))
runTests({ dev: true, withMiddleware })
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
beforeAll(async () => {
await fs.remove(nextConfig)

runTests({ dev: true })
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
beforeAll(async () => {
await fs.remove(nextConfig)

await nextBuild(appDir)
buildId = await fs.readFile(buildIdPath, 'utf8')

appPort = await findPort()
app = await nextStart(appDir, appPort)
})
afterAll(() => killApp(app))
await nextBuild(appDir)
buildId = await fs.readFile(buildIdPath, 'utf8')

runTests({ dev: false })
}
)
})
appPort = await findPort()
app = await nextStart(appDir, appPort)
})
afterAll(() => killApp(app))

runTests({ dev: false, withMiddleware })
}
)
}
)
7 changes: 0 additions & 7 deletions test/integration/dynamic-routing/test/middleware.test.ts

This file was deleted.

Loading