Skip to content

Commit 3e98a08

Browse files
committed
test: add middleware to turbopack fixture
1 parent 7c71660 commit 3e98a08

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import type { NextRequest } from 'next/server'
2+
import { NextResponse } from 'next/server'
3+
4+
export function middleware(request: NextRequest) {
5+
return NextResponse.json({
6+
message: `Hello from middleware at ${request.nextUrl.pathname}`,
7+
})
8+
}
9+
10+
export const config = {
11+
matcher: '/middleware/:path*',
12+
}

tests/integration/hello-world-turbopack.test.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { setupServer } from 'msw/node'
55
import { v4 } from 'uuid'
66
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, test, vi } from 'vitest'
77
import { type FixtureTestContext } from '../utils/contexts.js'
8-
import { createFixture, invokeFunction, runPlugin } from '../utils/fixture.js'
8+
import { createFixture, invokeEdgeFunction, invokeFunction, runPlugin } from '../utils/fixture.js'
99
import { generateRandomObjectID, startMockBlobStore } from '../utils/helpers.js'
1010
import { nextVersionSatisfies } from '../utils/next-version-helpers.mjs'
1111

@@ -85,5 +85,22 @@ describe.skipIf(!nextVersionSatisfies('>=15.3.0-canary.43'))(
8585
expect(home.statusCode).toBe(200)
8686
expect(load(home.body)('h1').text()).toBe('Hello, Next.js!')
8787
})
88+
89+
test<FixtureTestContext>('middleware is working', async (ctx) => {
90+
await createFixture('hello-world-turbopack', ctx)
91+
await runPlugin(ctx)
92+
93+
const pathname = '/middleware/test'
94+
95+
const response = await invokeEdgeFunction(ctx, {
96+
functions: ['___netlify-edge-handler-middleware'],
97+
url: pathname,
98+
})
99+
100+
expect(response.status).toBe(200)
101+
expect(await response.json()).toEqual({
102+
message: `Hello from middleware at ${pathname}`,
103+
})
104+
})
88105
},
89106
)

0 commit comments

Comments
 (0)