Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2031077

Browse files
committed
test: make sure to use appropiate edge handler name
1 parent b5a3269 commit 2031077

File tree

4 files changed

+57
-32
lines changed

4 files changed

+57
-32
lines changed

‎tests/integration/edge-handler.test.ts

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import { v4 } from 'uuid'
22
import { beforeEach, describe, expect, test, vi } from 'vitest'
33
import { type FixtureTestContext } from '../utils/contexts.js'
4-
import { createFixture, invokeEdgeFunction, runPlugin } from '../utils/fixture.js'
4+
import {
5+
createFixture,
6+
EDGE_MIDDLEWARE_FUNCTION_NAME,
7+
EDGE_MIDDLEWARE_SRC_FUNCTION_NAME,
8+
invokeEdgeFunction,
9+
runPlugin,
10+
} from '../utils/fixture.js'
511
import { generateRandomObjectID, startMockBlobStore } from '../utils/helpers.js'
612
import { LocalServer } from '../utils/local-server.js'
713
import { nextVersionSatisfies } from '../utils/next-version-helpers.mjs'
@@ -30,7 +36,7 @@ test<FixtureTestContext>('should add request/response headers', async (ctx) => {
3036
ctx.cleanup?.push(() => origin.stop())
3137

3238
const response = await invokeEdgeFunction(ctx, {
33-
functions: ['___netlify-edge-handler-middleware'],
39+
functions: [EDGE_MIDDLEWARE_FUNCTION_NAME],
3440
origin,
3541
url: '/test/next',
3642
})
@@ -58,7 +64,7 @@ test<FixtureTestContext>('should add request/response headers when using src dir
5864
ctx.cleanup?.push(() => origin.stop())
5965

6066
const response = await invokeEdgeFunction(ctx, {
61-
functions: ['___netlify-edge-handler-src-middleware'],
67+
functions: [EDGE_MIDDLEWARE_SRC_FUNCTION_NAME],
6268
origin,
6369
url: '/test/next',
6470
})
@@ -78,7 +84,7 @@ describe('redirect', () => {
7884

7985
const origin = new LocalServer()
8086
const response = await invokeEdgeFunction(ctx, {
81-
functions: ['___netlify-edge-handler-middleware'],
87+
functions: [EDGE_MIDDLEWARE_FUNCTION_NAME],
8288
origin,
8389
redirect: 'manual',
8490
url: '/test/redirect',
@@ -101,7 +107,7 @@ describe('redirect', () => {
101107

102108
const origin = new LocalServer()
103109
const response = await invokeEdgeFunction(ctx, {
104-
functions: ['___netlify-edge-handler-middleware'],
110+
functions: [EDGE_MIDDLEWARE_FUNCTION_NAME],
105111
origin,
106112
redirect: 'manual',
107113
url: '/test/redirect-with-headers',
@@ -140,7 +146,7 @@ describe('rewrite', () => {
140146
ctx.cleanup?.push(() => origin.stop())
141147

142148
const response = await invokeEdgeFunction(ctx, {
143-
functions: ['___netlify-edge-handler-middleware'],
149+
functions: [EDGE_MIDDLEWARE_FUNCTION_NAME],
144150
origin,
145151
url: `/test/rewrite-external?external-url=http://localhost:${external.port}/some-path`,
146152
})
@@ -167,7 +173,7 @@ describe('rewrite', () => {
167173
ctx.cleanup?.push(() => origin.stop())
168174

169175
const response = await invokeEdgeFunction(ctx, {
170-
functions: ['___netlify-edge-handler-middleware'],
176+
functions: [EDGE_MIDDLEWARE_FUNCTION_NAME],
171177
origin,
172178
url: `/test/rewrite-external?external-url=http://localhost:${external.port}/some-path`,
173179
redirect: 'manual',
@@ -196,7 +202,7 @@ describe("aborts middleware execution when the matcher conditions don't match th
196202
ctx.cleanup?.push(() => origin.stop())
197203

198204
const response = await invokeEdgeFunction(ctx, {
199-
functions: ['___netlify-edge-handler-middleware'],
205+
functions: [EDGE_MIDDLEWARE_FUNCTION_NAME],
200206
origin,
201207
url: '/_next/data',
202208
})
@@ -223,7 +229,7 @@ describe("aborts middleware execution when the matcher conditions don't match th
223229

224230
// Request 1: Middleware should run because we're not sending the header.
225231
const response1 = await invokeEdgeFunction(ctx, {
226-
functions: ['___netlify-edge-handler-middleware'],
232+
functions: [EDGE_MIDDLEWARE_FUNCTION_NAME],
227233
origin,
228234
url: '/foo',
229235
})
@@ -238,7 +244,7 @@ describe("aborts middleware execution when the matcher conditions don't match th
238244
headers: {
239245
'x-custom-header': 'custom-value',
240246
},
241-
functions: ['___netlify-edge-handler-middleware'],
247+
functions: [EDGE_MIDDLEWARE_FUNCTION_NAME],
242248
origin,
243249
url: '/foo',
244250
})
@@ -264,7 +270,7 @@ describe("aborts middleware execution when the matcher conditions don't match th
264270

265271
for (const path of ['/hello', '/en/hello', '/nl/hello', '/nl/about']) {
266272
const response = await invokeEdgeFunction(ctx, {
267-
functions: ['___netlify-edge-handler-middleware'],
273+
functions: [EDGE_MIDDLEWARE_FUNCTION_NAME],
268274
origin,
269275
url: path,
270276
})
@@ -278,7 +284,7 @@ describe("aborts middleware execution when the matcher conditions don't match th
278284

279285
for (const path of ['/invalid/hello', '/hello/invalid', '/about', '/en/about']) {
280286
const response = await invokeEdgeFunction(ctx, {
281-
functions: ['___netlify-edge-handler-middleware'],
287+
functions: [EDGE_MIDDLEWARE_FUNCTION_NAME],
282288
origin,
283289
url: path,
284290
})
@@ -299,7 +305,7 @@ describe('should run middleware on data requests', () => {
299305

300306
const origin = new LocalServer()
301307
const response = await invokeEdgeFunction(ctx, {
302-
functions: ['___netlify-edge-handler-middleware'],
308+
functions: [EDGE_MIDDLEWARE_FUNCTION_NAME],
303309
origin,
304310
redirect: 'manual',
305311
url: '/_next/data/dJvEyLV8MW7CBLFf0Ecbk/test/redirect-with-headers.json',
@@ -323,7 +329,7 @@ describe('should run middleware on data requests', () => {
323329

324330
const origin = new LocalServer()
325331
const response = await invokeEdgeFunction(ctx, {
326-
functions: ['___netlify-edge-handler-middleware'],
332+
functions: [EDGE_MIDDLEWARE_FUNCTION_NAME],
327333
origin,
328334
redirect: 'manual',
329335
url: '/_next/data/dJvEyLV8MW7CBLFf0Ecbk/test/redirect-with-headers.json',
@@ -357,7 +363,7 @@ describe('page router', () => {
357363
})
358364
ctx.cleanup?.push(() => origin.stop())
359365
const response = await invokeEdgeFunction(ctx, {
360-
functions: ['___netlify-edge-handler-middleware'],
366+
functions: [EDGE_MIDDLEWARE_FUNCTION_NAME],
361367
origin,
362368
url: `/api/edge-headers`,
363369
})
@@ -379,7 +385,7 @@ describe('page router', () => {
379385
})
380386
ctx.cleanup?.push(() => origin.stop())
381387
const response = await invokeEdgeFunction(ctx, {
382-
functions: ['___netlify-edge-handler-middleware'],
388+
functions: [EDGE_MIDDLEWARE_FUNCTION_NAME],
383389
headers: {
384390
'x-nextjs-data': '1',
385391
},
@@ -408,7 +414,7 @@ describe('page router', () => {
408414
})
409415
ctx.cleanup?.push(() => origin.stop())
410416
const response = await invokeEdgeFunction(ctx, {
411-
functions: ['___netlify-edge-handler-middleware'],
417+
functions: [EDGE_MIDDLEWARE_FUNCTION_NAME],
412418
origin,
413419
url: `/_next/static/build-id/_devMiddlewareManifest.json?foo=1`,
414420
})
@@ -434,7 +440,7 @@ describe('page router', () => {
434440
})
435441
ctx.cleanup?.push(() => origin.stop())
436442
const response = await invokeEdgeFunction(ctx, {
437-
functions: ['___netlify-edge-handler-middleware'],
443+
functions: [EDGE_MIDDLEWARE_FUNCTION_NAME],
438444
headers: {
439445
'x-nextjs-data': '1',
440446
},
@@ -462,7 +468,7 @@ describe('page router', () => {
462468
})
463469
ctx.cleanup?.push(() => origin.stop())
464470
const response = await invokeEdgeFunction(ctx, {
465-
functions: ['___netlify-edge-handler-middleware'],
471+
functions: [EDGE_MIDDLEWARE_FUNCTION_NAME],
466472
headers: {
467473
'x-nextjs-data': '1',
468474
},
@@ -491,7 +497,7 @@ describe('page router', () => {
491497
})
492498
ctx.cleanup?.push(() => origin.stop())
493499
const response = await invokeEdgeFunction(ctx, {
494-
functions: ['___netlify-edge-handler-middleware'],
500+
functions: [EDGE_MIDDLEWARE_FUNCTION_NAME],
495501
origin,
496502
url: `/fr/old-home`,
497503
redirect: 'manual',
@@ -515,7 +521,7 @@ describe('page router', () => {
515521
})
516522
ctx.cleanup?.push(() => origin.stop())
517523
const response = await invokeEdgeFunction(ctx, {
518-
functions: ['___netlify-edge-handler-middleware'],
524+
functions: [EDGE_MIDDLEWARE_FUNCTION_NAME],
519525
origin,
520526
url: `/fr/redirect-to-same-page-but-default-locale`,
521527
redirect: 'manual',
@@ -540,7 +546,7 @@ describe('page router', () => {
540546
ctx.cleanup?.push(() => origin.stop())
541547

542548
const response = await invokeEdgeFunction(ctx, {
543-
functions: ['___netlify-edge-handler-middleware'],
549+
functions: [EDGE_MIDDLEWARE_FUNCTION_NAME],
544550
origin,
545551
url: `/json`,
546552
})
@@ -552,7 +558,7 @@ describe('page router', () => {
552558
expect(body.nextUrlLocale).toBe('en')
553559

554560
const responseEn = await invokeEdgeFunction(ctx, {
555-
functions: ['___netlify-edge-handler-middleware'],
561+
functions: [EDGE_MIDDLEWARE_FUNCTION_NAME],
556562
origin,
557563
url: `/en/json`,
558564
})
@@ -564,7 +570,7 @@ describe('page router', () => {
564570
expect(bodyEn.nextUrlLocale).toBe('en')
565571

566572
const responseFr = await invokeEdgeFunction(ctx, {
567-
functions: ['___netlify-edge-handler-middleware'],
573+
functions: [EDGE_MIDDLEWARE_FUNCTION_NAME],
568574
origin,
569575
url: `/fr/json`,
570576
})
@@ -591,7 +597,7 @@ describe('page router', () => {
591597
ctx.cleanup?.push(() => origin.stop())
592598

593599
const response = await invokeEdgeFunction(ctx, {
594-
functions: ['___netlify-edge-handler-middleware'],
600+
functions: [EDGE_MIDDLEWARE_FUNCTION_NAME],
595601
origin,
596602
url: `/json`,
597603
})
@@ -603,7 +609,7 @@ describe('page router', () => {
603609
expect(body.nextUrlLocale).toBe('en')
604610

605611
const responseEn = await invokeEdgeFunction(ctx, {
606-
functions: ['___netlify-edge-handler-middleware'],
612+
functions: [EDGE_MIDDLEWARE_FUNCTION_NAME],
607613
origin,
608614
url: `/en/json`,
609615
})
@@ -615,7 +621,7 @@ describe('page router', () => {
615621
expect(bodyEn.nextUrlLocale).toBe('en')
616622

617623
const responseFr = await invokeEdgeFunction(ctx, {
618-
functions: ['___netlify-edge-handler-middleware'],
624+
functions: [EDGE_MIDDLEWARE_FUNCTION_NAME],
619625
origin,
620626
url: `/fr/json`,
621627
})

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ 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, invokeEdgeFunction, invokeFunction, runPlugin } from '../utils/fixture.js'
8+
import {
9+
createFixture,
10+
EDGE_MIDDLEWARE_FUNCTION_NAME,
11+
invokeEdgeFunction,
12+
invokeFunction,
13+
runPlugin,
14+
} from '../utils/fixture.js'
915
import { generateRandomObjectID, startMockBlobStore } from '../utils/helpers.js'
1016
import { nextVersionSatisfies } from '../utils/next-version-helpers.mjs'
1117

@@ -93,7 +99,7 @@ describe.skipIf(!nextVersionSatisfies('>=15.3.0-canary.43'))(
9399
const pathname = '/middleware/test'
94100

95101
const response = await invokeEdgeFunction(ctx, {
96-
functions: ['___netlify-edge-handler-middleware'],
102+
functions: [EDGE_MIDDLEWARE_FUNCTION_NAME],
97103
url: pathname,
98104
})
99105

‎tests/integration/wasm.test.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@ import { platform } from 'node:process'
33
import { v4 } from 'uuid'
44
import { beforeEach, describe, expect, test, vi } from 'vitest'
55
import { type FixtureTestContext } from '../utils/contexts.js'
6-
import { createFixture, invokeEdgeFunction, invokeFunction, runPlugin } from '../utils/fixture.js'
6+
import {
7+
createFixture,
8+
EDGE_MIDDLEWARE_FUNCTION_NAME,
9+
EDGE_MIDDLEWARE_SRC_FUNCTION_NAME,
10+
invokeEdgeFunction,
11+
invokeFunction,
12+
runPlugin,
13+
} from '../utils/fixture.js'
714
import { generateRandomObjectID, startMockBlobStore } from '../utils/helpers.js'
815
import { LocalServer } from '../utils/local-server.js'
916

@@ -23,8 +30,8 @@ beforeEach<FixtureTestContext>(async (ctx) => {
2330
})
2431

2532
describe.each([
26-
{ fixture: 'wasm', edgeHandlerFunction: '___netlify-edge-handler-middleware' },
27-
{ fixture: 'wasm-src', edgeHandlerFunction: '___netlify-edge-handler-src-middleware' },
33+
{ fixture: 'wasm', edgeHandlerFunction: EDGE_MIDDLEWARE_FUNCTION_NAME },
34+
{ fixture: 'wasm-src', edgeHandlerFunction: EDGE_MIDDLEWARE_SRC_FUNCTION_NAME },
2835
])('$fixture', ({ fixture, edgeHandlerFunction }) => {
2936
beforeEach<FixtureTestContext>(async (ctx) => {
3037
// set for each test a new deployID and siteID

‎tests/utils/fixture.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,3 +560,9 @@ export async function invokeSandboxedFunction(
560560
exit()
561561
return result
562562
}
563+
564+
// export const EDGE_MIDDLEWARE_FUNCTION_NAME = '___netlify-edge-handler-middleware'
565+
// export const EDGE_MIDDLEWARE_SRC_FUNCTION_NAME = '___netlify-edge-handler-src-middleware'
566+
// for right now we will use node middleware in tests
567+
export const EDGE_MIDDLEWARE_FUNCTION_NAME = '___netlify-edge-handler-node-middleware'
568+
export const EDGE_MIDDLEWARE_SRC_FUNCTION_NAME = EDGE_MIDDLEWARE_FUNCTION_NAME

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /