@@ -4,7 +4,7 @@ import { join } from 'path'
4
4
5
5
import execa from 'execa'
6
6
import fetch from 'node-fetch'
7
- import { describe , expect , test } from 'vitest'
7
+ import { describe , test } from 'vitest'
8
8
9
9
import { withDevServer } from '../../utils/dev-server.js'
10
10
import { FixtureTestContext , setupFixtureTests } from '../../utils/fixture.js'
@@ -51,7 +51,7 @@ describe.skipIf(isWindows)('edge functions', async () => {
51
51
'dev-server-with-edge-functions' ,
52
52
{ devServer : true , mockApi : { routes } , setupAfterDev : recreateEdgeFunctions } ,
53
53
( ) => {
54
- test < FixtureTestContext > ( 'should run edge functions in correct order' , async ( { devServer } ) => {
54
+ test < FixtureTestContext > ( 'should run edge functions in correct order' , async ( { devServer, expect } ) => {
55
55
const response = await fetch ( `http://localhost:${ devServer ! . port } /ordertest` )
56
56
const body = await response . text ( )
57
57
@@ -71,7 +71,7 @@ describe.skipIf(isWindows)('edge functions', async () => {
71
71
] )
72
72
} )
73
73
74
- test < FixtureTestContext > ( 'should provide context properties' , async ( { devServer } ) => {
74
+ test < FixtureTestContext > ( 'should provide context properties' , async ( { devServer, expect } ) => {
75
75
const response = await fetch ( `http://localhost:${ devServer ! . port } /context` )
76
76
77
77
const body = await response . json ( )
@@ -87,7 +87,7 @@ describe.skipIf(isWindows)('edge functions', async () => {
87
87
} )
88
88
} )
89
89
90
- test < FixtureTestContext > ( 'should expose URL parameters' , async ( { devServer } ) => {
90
+ test < FixtureTestContext > ( 'should expose URL parameters' , async ( { devServer, expect } ) => {
91
91
const response = await fetch ( `http://localhost:${ devServer ! . port } /categories/foo/products/bar` )
92
92
93
93
const body = await response . json ( )
@@ -99,6 +99,7 @@ describe.skipIf(isWindows)('edge functions', async () => {
99
99
100
100
test < FixtureTestContext > ( 'should expose URL parameters to edge functions with `cache: "manual"`' , async ( {
101
101
devServer,
102
+ expect,
102
103
} ) => {
103
104
const response = await fetch ( `http://localhost:${ devServer ! . port } /categories-after-cache/foo/products/bar` )
104
105
@@ -109,7 +110,7 @@ describe.skipIf(isWindows)('edge functions', async () => {
109
110
} )
110
111
} )
111
112
112
- test < FixtureTestContext > ( 'should respect config.methods field' , async ( { devServer } ) => {
113
+ test < FixtureTestContext > ( 'should respect config.methods field' , async ( { devServer, expect } ) => {
113
114
const responseGet = await fetch ( `http://localhost:${ devServer ! . port } /products/really-bad-product` , {
114
115
method : 'GET' ,
115
116
} )
@@ -125,6 +126,7 @@ describe.skipIf(isWindows)('edge functions', async () => {
125
126
126
127
test < FixtureTestContext > ( 'should show an error page when an edge function has an uncaught exception' , async ( {
127
128
devServer,
129
+ expect,
128
130
} ) => {
129
131
const [ plainTextResponse , htmlResponse ] = await Promise . all ( [
130
132
fetch ( `http://localhost:${ devServer ! . port } /uncaught-exception` , {
@@ -148,6 +150,7 @@ describe.skipIf(isWindows)('edge functions', async () => {
148
150
149
151
test < FixtureTestContext > ( 'should set the `URL`, `SITE_ID`, and `SITE_NAME` environment variables' , async ( {
150
152
devServer,
153
+ expect,
151
154
} ) => {
152
155
const body = ( await fetch ( `http://localhost:${ devServer ! . port } /echo-env` ) . then ( ( res ) => res . json ( ) ) ) as Record <
153
156
string ,
@@ -171,6 +174,7 @@ describe.skipIf(isWindows)('edge functions', async () => {
171
174
( ) => {
172
175
test < FixtureTestContext > ( 'skips edge functions when --internal-disable-edge-functions is passed' , async ( {
173
176
devServer,
177
+ expect,
174
178
} ) => {
175
179
const response = await fetch ( `http://localhost:${ devServer ! . port } /ordertest` )
176
180
const body = await response . text ( )
@@ -183,7 +187,11 @@ describe.skipIf(isWindows)('edge functions', async () => {
183
187
)
184
188
185
189
await setupFixtureTests ( 'dev-server-with-edge-functions' , { devServer : true , mockApi : { routes } } , ( ) => {
186
- test < FixtureTestContext > ( 'should not remove other edge functions on change' , async ( { devServer, fixture } ) => {
190
+ test < FixtureTestContext > ( 'should not remove other edge functions on change' , async ( {
191
+ devServer,
192
+ expect,
193
+ fixture,
194
+ } ) => {
187
195
// we need to wait till file watchers are loaded
188
196
await pause ( 500 )
189
197
@@ -202,6 +210,8 @@ describe.skipIf(isWindows)('edge functions', async () => {
202
210
} )
203
211
204
212
test ( 'should reload on change to transitive dependency' , async ( t ) => {
213
+ const { expect } = t
214
+
205
215
await withSiteBuilder ( t , async ( builder ) => {
206
216
await builder
207
217
. withContentFile ( {
@@ -223,8 +233,9 @@ describe.skipIf(isWindows)('edge functions', async () => {
223
233
. build ( )
224
234
225
235
await withDevServer ( { cwd : builder . directory } , async ( server ) => {
226
- const response = await fetch ( server . url , { } ) . then ( ( res ) => res . text ( ) )
227
- t . expect ( response ) . toEqual ( 'foo' )
236
+ const response = await fetch ( server . url , { } )
237
+ const text = await response . text ( )
238
+ expect ( text ) . toEqual ( 'foo' )
228
239
229
240
// update file
230
241
await builder
@@ -236,13 +247,16 @@ describe.skipIf(isWindows)('edge functions', async () => {
236
247
237
248
await pause ( 500 )
238
249
239
- const response2 = await fetch ( server . url , { } ) . then ( ( res ) => res . text ( ) )
240
- t . expect ( response2 ) . toEqual ( 'bar' )
250
+ const response2 = await fetch ( server . url , { } )
251
+ const text2 = await response2 . text ( )
252
+ expect ( text2 ) . toEqual ( 'bar' )
241
253
} )
242
254
} )
243
255
} )
244
256
245
257
test ( 'functions and edge functions should receive url-encoded search params in the same way' , async ( t ) => {
258
+ const { expect } = t
259
+
246
260
await withSiteBuilder ( t , async ( builder ) => {
247
261
await builder
248
262
. withContentFile ( {
@@ -264,8 +278,8 @@ describe.skipIf(isWindows)('edge functions', async () => {
264
278
await withDevServer ( { cwd : builder . directory } , async ( server ) => {
265
279
const funcResponse = await fetch ( new URL ( '/func?1,2,3' , server . url ) , { } )
266
280
const efResponse = await fetch ( new URL ( '/ef?1,2,3' , server . url ) , { } )
267
- t . expect ( await funcResponse . text ( ) ) . toEqual ( '?1,2,3' )
268
- t . expect ( await efResponse . text ( ) ) . toEqual ( '?1,2,3' )
281
+ expect ( await funcResponse . text ( ) ) . toEqual ( '?1,2,3' )
282
+ expect ( await efResponse . text ( ) ) . toEqual ( '?1,2,3' )
269
283
} )
270
284
} )
271
285
} )
@@ -274,7 +288,10 @@ describe.skipIf(isWindows)('edge functions', async () => {
274
288
'dev-server-with-edge-functions-and-npm-modules' ,
275
289
{ devServer : true , mockApi : { routes } , setup } ,
276
290
( ) => {
277
- test < FixtureTestContext > ( 'should run an edge function that uses the Blobs npm module' , async ( { devServer } ) => {
291
+ test < FixtureTestContext > ( 'should run an edge function that uses the Blobs npm module' , async ( {
292
+ devServer,
293
+ expect,
294
+ } ) => {
278
295
const res = await fetch ( `http://localhost:${ devServer ! . port } /blobs` , {
279
296
method : 'GET' ,
280
297
} )
0 commit comments