Skip to content

Commit 487b0db

Browse files
committed
test: initial build variants setup
1 parent e0b5143 commit 487b0db

File tree

28 files changed

+507
-351
lines changed

28 files changed

+507
-351
lines changed

tests/e2e/edge-middleware.test.ts

Lines changed: 58 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,74 @@
11
import { expect, Response } from '@playwright/test'
2-
import { nextVersionSatisfies } from '../utils/next-version-helpers.mjs'
2+
import { hasNodeMiddlewareSupport, nextVersionSatisfies } from '../utils/next-version-helpers.mjs'
33
import { test } from '../utils/playwright-helpers.js'
44
import { getImageSize } from 'next/dist/server/image-optimizer.js'
5+
import type { Fixture } from '../utils/create-e2e-fixture.js'
56

67
type ExtendedWindow = Window & {
78
didReload?: boolean
89
}
910

10-
test('Runs edge middleware', async ({ page, middleware }) => {
11-
await page.goto(`${middleware.url}/test/redirect`)
11+
for (const { expectedRuntime, label, testWithSwitchableMiddlewareRuntime } of [
12+
{
13+
expectedRuntime: 'edge-runtime',
14+
label: 'Edge runtime middleware',
15+
testWithSwitchableMiddlewareRuntime: test.extend<{}, { edgeOrNodeMiddleware: Fixture }>({
16+
edgeOrNodeMiddleware: [
17+
async ({ middleware }, use) => {
18+
await use(middleware)
19+
},
20+
{
21+
scope: 'worker',
22+
},
23+
],
24+
}),
25+
},
26+
hasNodeMiddlewareSupport()
27+
? {
28+
expectedRuntime: 'node',
29+
label: 'Node.js runtime middleware',
30+
testWithSwitchableMiddlewareRuntime: test.extend<{}, { edgeOrNodeMiddleware: Fixture }>({
31+
edgeOrNodeMiddleware: [
32+
async ({ middlewareNode }, use) => {
33+
await use(middlewareNode)
34+
},
35+
{
36+
scope: 'worker',
37+
},
38+
],
39+
}),
40+
}
41+
: undefined,
42+
].filter(function isDefined<T>(argument: T | undefined): argument is T {
43+
return typeof argument !== 'undefined'
44+
})) {
45+
const test = testWithSwitchableMiddlewareRuntime
46+
47+
test.describe(label, () => {
48+
test('Runs middleware', async ({ page, edgeOrNodeMiddleware }) => {
49+
const res = await page.goto(`${edgeOrNodeMiddleware.url}/test/redirect`)
50+
51+
await expect(page).toHaveTitle('Simple Next App')
52+
53+
const h1 = page.locator('h1')
54+
await expect(h1).toHaveText('Other')
55+
})
1256

13-
await expect(page).toHaveTitle('Simple Next App')
57+
test('Does not run middleware at the origin', async ({ page, edgeOrNodeMiddleware }) => {
58+
const res = await page.goto(`${edgeOrNodeMiddleware.url}/test/next`)
1459

15-
const h1 = page.locator('h1')
16-
await expect(h1).toHaveText('Other')
17-
})
18-
19-
test('Does not run edge middleware at the origin', async ({ page, middleware }) => {
20-
const res = await page.goto(`${middleware.url}/test/next`)
60+
expect(await res?.headerValue('x-deno')).toBeTruthy()
61+
expect(await res?.headerValue('x-node')).toBeNull()
2162

22-
expect(await res?.headerValue('x-deno')).toBeTruthy()
23-
expect(await res?.headerValue('x-node')).toBeNull()
63+
await expect(page).toHaveTitle('Simple Next App')
2464

25-
await expect(page).toHaveTitle('Simple Next App')
65+
const h1 = page.locator('h1')
66+
await expect(h1).toHaveText('Message from middleware: hello')
2667

27-
const h1 = page.locator('h1')
28-
await expect(h1).toHaveText('Message from middleware: hello')
29-
})
68+
expect(await res?.headerValue('x-runtime')).toEqual(expectedRuntime)
69+
})
70+
})
71+
}
3072

3173
test('does not run middleware again for rewrite target', async ({ page, middleware }) => {
3274
const direct = await page.goto(`${middleware.url}/test/rewrite-target`)

tests/fixtures/hello-world-turbopack/middleware.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,4 @@ export function middleware(request: NextRequest) {
99

1010
export const config = {
1111
matcher: '/middleware/:path*',
12-
runtime: 'nodejs',
1312
}

tests/fixtures/middleware-conditions/middleware.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,4 @@ export const config = {
2323
locale: false,
2424
},
2525
],
26-
runtime: 'nodejs',
2726
}

tests/fixtures/middleware-i18n-excluded-paths/middleware.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,4 @@ export const config = {
3333
*/
3434
'/((?!api|excluded|_next/static|_next/image|favicon.ico|sitemap.xml|robots.txt).*)',
3535
],
36-
runtime: 'nodejs',
3736
}

tests/fixtures/middleware-i18n-skip-normalize/middleware.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,3 @@ export async function middleware(request) {
8989
})
9090
}
9191
}
92-
93-
export const config = {
94-
runtime: 'nodejs',
95-
}

tests/fixtures/middleware-i18n/middleware.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,3 @@ export async function middleware(request) {
114114
})
115115
}
116116
}
117-
118-
export const config = {
119-
runtime: 'nodejs',
120-
}

tests/fixtures/middleware-node/app/layout.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

tests/fixtures/middleware-node/app/page.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

tests/fixtures/middleware-node/middleware.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

tests/fixtures/middleware-node/next.config.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)