Skip to content

Commit 8669b58

Browse files
committed
test: move middleware-i18n-static-asset-matcher to test variants
1 parent 61d261e commit 8669b58

File tree

8 files changed

+75
-14
lines changed

8 files changed

+75
-14
lines changed

tests/e2e/edge-middleware.test.ts

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ type ExtendedFixtures = {
1313
edgeOrNodeMiddlewarePages: Fixture
1414
edgeOrNodeMiddlewareI18n: Fixture
1515
edgeOrNodeMiddlewareI18nExcludedPaths: Fixture
16+
edgeOrNodeMiddlewareStaticAssetMatcher: Fixture
1617
}
1718

1819
for (const { expectedRuntime, label, testWithSwitchableMiddlewareRuntime } of [
@@ -52,6 +53,14 @@ for (const { expectedRuntime, label, testWithSwitchableMiddlewareRuntime } of [
5253
scope: 'worker',
5354
},
5455
],
56+
edgeOrNodeMiddlewareStaticAssetMatcher: [
57+
async ({ middlewareStaticAssetMatcher }, use) => {
58+
await use(middlewareStaticAssetMatcher)
59+
},
60+
{
61+
scope: 'worker',
62+
},
63+
],
5564
}),
5665
},
5766
hasNodeMiddlewareSupport()
@@ -91,6 +100,14 @@ for (const { expectedRuntime, label, testWithSwitchableMiddlewareRuntime } of [
91100
scope: 'worker',
92101
},
93102
],
103+
edgeOrNodeMiddlewareStaticAssetMatcher: [
104+
async ({ middlewareStaticAssetMatcherNode }, use) => {
105+
await use(middlewareStaticAssetMatcherNode)
106+
},
107+
{
108+
scope: 'worker',
109+
},
110+
],
94111
}),
95112
}
96113
: undefined,
@@ -468,16 +485,17 @@ for (const { expectedRuntime, label, testWithSwitchableMiddlewareRuntime } of [
468485
})
469486
})
470487

471-
if (expectedRuntime !== 'node') {
472-
test('requests with different encoding than matcher match anyway', async ({
473-
middlewareStaticAssetMatcher,
474-
}) => {
475-
const response = await fetch(`${middlewareStaticAssetMatcher.url}/hello%2Fworld.txt`)
488+
test('requests with different encoding than matcher match anyway', async ({
489+
edgeOrNodeMiddlewareStaticAssetMatcher,
490+
}) => {
491+
const response = await fetch(
492+
`${edgeOrNodeMiddlewareStaticAssetMatcher.url}/hello%2Fworld.txt`,
493+
)
476494

477-
// middleware was not skipped
478-
expect(await response.text()).toBe('hello from middleware')
479-
})
480-
}
495+
// middleware was not skipped
496+
expect(await response.text()).toBe('hello from middleware')
497+
expect(response.headers.get('x-runtime')).toEqual(expectedRuntime)
498+
})
481499

482500
test.describe('RSC cache poisoning', () => {
483501
test('Middleware rewrite', async ({ page, edgeOrNodeMiddleware }) => {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export { middleware } from './middleware-shared'
2+
3+
export const config = {
4+
matcher: '/hello/world.txt',
5+
runtime: 'nodejs',
6+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export function middleware() {
2+
return new Response('hello from middleware', {
3+
headers: {
4+
// report Next.js Middleware Runtime (not the execution runtime, but target runtime)
5+
// @ts-expect-error EdgeRuntime global not declared
6+
'x-runtime': typeof EdgeRuntime !== 'undefined' ? EdgeRuntime : 'node',
7+
},
8+
})
9+
}

tests/fixtures/middleware-static-asset-matcher/middleware.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
export default function middleware() {
2-
return new Response('hello from middleware')
3-
}
1+
export { middleware } from './middleware-shared'
42

53
export const config = {
64
matcher: '/hello/world.txt',

tests/fixtures/middleware-static-asset-matcher/next.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
/** @type {import('next').NextConfig} */
22
const nextConfig = {
33
output: 'standalone',
4+
distDir: process.env.NEXT_DIST_DIR ?? '.next',
45
eslint: {
56
ignoreDuringBuilds: true,
67
},
8+
experimental: {
9+
nodeMiddleware: true,
10+
},
711
outputFileTracingRoot: __dirname,
812
}
913

tests/fixtures/middleware-static-asset-matcher/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
"version": "0.1.0",
44
"private": true,
55
"scripts": {
6-
"postinstall": "next build",
6+
"postinstall": "npm run build",
77
"dev": "next dev",
8-
"build": "next build"
8+
"build": "node ../../utils/build-variants.mjs"
99
},
1010
"dependencies": {
1111
"next": "latest",
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"node-middleware": {
3+
"distDir": ".next-node-middleware",
4+
"files": {
5+
"middleware.ts": "middleware-node.ts"
6+
},
7+
"test": {
8+
"dependencies": {
9+
"next": [
10+
{
11+
"versionConstraint": ">=15.2.0",
12+
"canaryOnly": true
13+
},
14+
{
15+
"versionConstraint": ">=15.5.0"
16+
}
17+
]
18+
}
19+
}
20+
}
21+
}

tests/utils/create-e2e-fixture.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,11 @@ export const fixtureFactories = {
366366
publishDirectory: '.next-node-middleware',
367367
}),
368368
middlewareStaticAssetMatcher: () => createE2EFixture('middleware-static-asset-matcher'),
369+
middlewareStaticAssetMatcherNode: () =>
370+
createE2EFixture('middleware-static-asset-matcher', {
371+
buildCommand: getBuildFixtureVariantCommand('node-middleware'),
372+
publishDirectory: '.next-node-middleware',
373+
}),
369374
middlewareSubrequestVuln: () => createE2EFixture('middleware-subrequest-vuln'),
370375
pageRouter: () => createE2EFixture('page-router'),
371376
pageRouterBasePathI18n: () => createE2EFixture('page-router-base-path-i18n'),

0 commit comments

Comments
 (0)