@@ -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 , expectTypeOf , test } from 'vitest'
7
+ import { describe , expectTypeOf , 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', () => {
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', () => {
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 { deploy, geo, ip, params, requestId, server, site } = await response . json ( )
@@ -85,7 +85,7 @@ describe.skipIf(isWindows)('edge functions', () => {
85
85
expect ( site ) . toEqual ( { id : 'foo' , name : 'site-name' , url : `http://localhost:${ devServer . port } ` } )
86
86
} )
87
87
88
- test < FixtureTestContext > ( 'should expose URL parameters' , async ( { devServer } ) => {
88
+ test < FixtureTestContext > ( 'should expose URL parameters' , async ( { devServer, expect } ) => {
89
89
const response = await fetch ( `http://localhost:${ devServer . port } /categories/foo/products/bar` )
90
90
91
91
const { params } = await response . json ( )
@@ -97,6 +97,7 @@ describe.skipIf(isWindows)('edge functions', () => {
97
97
98
98
test < FixtureTestContext > ( 'should expose URL parameters to edge functions with `cache: "manual"`' , async ( {
99
99
devServer,
100
+ expect,
100
101
} ) => {
101
102
const response = await fetch ( `http://localhost:${ devServer . port } /categories-after-cache/foo/products/bar` )
102
103
@@ -107,7 +108,7 @@ describe.skipIf(isWindows)('edge functions', () => {
107
108
} )
108
109
} )
109
110
110
- test < FixtureTestContext > ( 'should respect config.methods field' , async ( { devServer } ) => {
111
+ test < FixtureTestContext > ( 'should respect config.methods field' , async ( { devServer, expect } ) => {
111
112
const responseGet = await fetch ( `http://localhost:${ devServer . port } /products/really-bad-product` , {
112
113
method : 'GET' ,
113
114
} )
@@ -123,6 +124,7 @@ describe.skipIf(isWindows)('edge functions', () => {
123
124
124
125
test < FixtureTestContext > ( 'should show an error page when an edge function has an uncaught exception' , async ( {
125
126
devServer,
127
+ expect,
126
128
} ) => {
127
129
const [ plainTextResponse , htmlResponse ] = await Promise . all ( [
128
130
fetch ( `http://localhost:${ devServer . port } /uncaught-exception` , {
@@ -146,6 +148,7 @@ describe.skipIf(isWindows)('edge functions', () => {
146
148
147
149
test < FixtureTestContext > ( 'should set the `URL`, `SITE_ID`, and `SITE_NAME` environment variables' , async ( {
148
150
devServer,
151
+ expect,
149
152
} ) => {
150
153
const body = ( await fetch ( `http://localhost:${ devServer . port } /echo-env` ) . then ( ( res ) => res . json ( ) ) ) as Record <
151
154
string ,
@@ -169,6 +172,7 @@ describe.skipIf(isWindows)('edge functions', () => {
169
172
( ) => {
170
173
test < FixtureTestContext > ( 'skips edge functions when --internal-disable-edge-functions is passed' , async ( {
171
174
devServer,
175
+ expect,
172
176
} ) => {
173
177
const response = await fetch ( `http://localhost:${ devServer . port } /ordertest` )
174
178
const body = await response . text ( )
@@ -181,7 +185,11 @@ describe.skipIf(isWindows)('edge functions', () => {
181
185
)
182
186
183
187
setupFixtureTests ( 'dev-server-with-edge-functions' , { devServer : true , mockApi : { routes } } , ( ) => {
184
- test < FixtureTestContext > ( 'should not remove other edge functions on change' , async ( { devServer, fixture } ) => {
188
+ test < FixtureTestContext > ( 'should not remove other edge functions on change' , async ( {
189
+ devServer,
190
+ expect,
191
+ fixture,
192
+ } ) => {
185
193
// we need to wait till file watchers are loaded
186
194
await pause ( 500 )
187
195
@@ -199,7 +207,9 @@ describe.skipIf(isWindows)('edge functions', () => {
199
207
} )
200
208
} )
201
209
202
- test ( 'should reload on change to transitive dependency' , async ( t ) => {
210
+ test . only ( 'should reload on change to transitive dependency' , async ( t ) => {
211
+ const { expect } = t
212
+
203
213
await withSiteBuilder ( t , async ( builder ) => {
204
214
await builder
205
215
. withContentFile ( {
@@ -221,8 +231,9 @@ describe.skipIf(isWindows)('edge functions', () => {
221
231
. build ( )
222
232
223
233
await withDevServer ( { cwd : builder . directory } , async ( server ) => {
224
- const response = await fetch ( server . url , { } ) . then ( ( res ) => res . text ( ) )
225
- t . expect ( response ) . toEqual ( 'foo' )
234
+ const response = await fetch ( server . url , { } )
235
+ const text = await response . text ( )
236
+ expect ( text ) . toEqual ( 'foo' )
226
237
227
238
// update file
228
239
await builder
@@ -234,13 +245,16 @@ describe.skipIf(isWindows)('edge functions', () => {
234
245
235
246
await pause ( 500 )
236
247
237
- const response2 = await fetch ( server . url , { } ) . then ( ( res ) => res . text ( ) )
238
- t . expect ( response2 ) . toEqual ( 'bar' )
248
+ const response2 = await fetch ( server . url , { } )
249
+ const text2 = await response2 . text ( )
250
+ expect ( text2 ) . toEqual ( 'bar' )
239
251
} )
240
252
} )
241
253
} )
242
254
243
255
test ( 'functions and edge functions should receive url-encoded search params in the same way' , async ( t ) => {
256
+ const { expect } = t
257
+
244
258
await withSiteBuilder ( t , async ( builder ) => {
245
259
await builder
246
260
. withContentFile ( {
@@ -262,8 +276,8 @@ describe.skipIf(isWindows)('edge functions', () => {
262
276
await withDevServer ( { cwd : builder . directory } , async ( server ) => {
263
277
const funcResponse = await fetch ( new URL ( '/func?1,2,3' , server . url ) , { } )
264
278
const efResponse = await fetch ( new URL ( '/ef?1,2,3' , server . url ) , { } )
265
- t . expect ( await funcResponse . text ( ) ) . toEqual ( '?1,2,3' )
266
- t . expect ( await efResponse . text ( ) ) . toEqual ( '?1,2,3' )
279
+ expect ( await funcResponse . text ( ) ) . toEqual ( '?1,2,3' )
280
+ expect ( await efResponse . text ( ) ) . toEqual ( '?1,2,3' )
267
281
} )
268
282
} )
269
283
} )
@@ -272,7 +286,10 @@ describe.skipIf(isWindows)('edge functions', () => {
272
286
'dev-server-with-edge-functions-and-npm-modules' ,
273
287
{ devServer : true , mockApi : { routes } , setup } ,
274
288
( ) => {
275
- test < FixtureTestContext > ( 'should run an edge function that uses the Blobs npm module' , async ( { devServer } ) => {
289
+ test < FixtureTestContext > ( 'should run an edge function that uses the Blobs npm module' , async ( {
290
+ devServer,
291
+ expect,
292
+ } ) => {
276
293
const res = await fetch ( `http://localhost:${ devServer . port } /blobs` , {
277
294
method : 'GET' ,
278
295
} )
0 commit comments