@@ -11,6 +11,7 @@ const { Response } = require('node-fetch')
11
11
12
12
const { withDevServer } = require ( './utils/dev-server' )
13
13
const got = require ( './utils/got' )
14
+ const { pause } = require ( './utils/pause' )
14
15
const { withSiteBuilder } = require ( './utils/site-builder' )
15
16
16
17
const test = isCI ? avaTest . serial . bind ( avaTest ) : avaTest
@@ -377,4 +378,98 @@ test(`catches invalid function names`, async (t) => {
377
378
} )
378
379
} )
379
380
} )
381
+
382
+ test ( 'should detect content changes in edge functions' , async ( t ) => {
383
+ await withSiteBuilder ( 'site-with-edge-functions' , async ( builder ) => {
384
+ const publicDir = 'public'
385
+ await builder
386
+ . withNetlifyToml ( {
387
+ config : {
388
+ build : {
389
+ publish : publicDir ,
390
+ edge_functions : 'netlify/edge-functions' ,
391
+ } ,
392
+ edge_functions : [
393
+ {
394
+ function : 'hello' ,
395
+ path : '/hello' ,
396
+ } ,
397
+ ] ,
398
+ } ,
399
+ } )
400
+ . withEdgeFunction ( {
401
+ handler : ( ) => new Response ( 'Hello world' ) ,
402
+ name : 'hello' ,
403
+ } )
404
+
405
+ await builder . buildAsync ( )
406
+
407
+ await withDevServer ( { cwd : builder . directory } , async ( { port } ) => {
408
+ const helloWorldMessage = await got ( `http://localhost:${ port } /hello` ) . then ( ( response ) => response . body )
409
+
410
+ await builder
411
+ . withEdgeFunction ( {
412
+ handler : ( ) => new Response ( 'Hello builder' ) ,
413
+ name : 'hello' ,
414
+ } )
415
+ . buildAsync ( )
416
+
417
+ const DETECT_FILE_CHANGE_DELAY = 500
418
+ await pause ( DETECT_FILE_CHANGE_DELAY )
419
+
420
+ const helloBuilderMessage = await got ( `http://localhost:${ port } /hello` ) . then ( ( response ) => response . body )
421
+
422
+ t . is ( helloWorldMessage , 'Hello world' )
423
+ t . is ( helloBuilderMessage , 'Hello builder' )
424
+ } )
425
+ } )
426
+ } )
427
+
428
+ test ( 'should detect deleted edge functions' , async ( t ) => {
429
+ await withSiteBuilder ( 'site-with-edge-functions' , async ( builder ) => {
430
+ const publicDir = 'public'
431
+ builder
432
+ . withNetlifyToml ( {
433
+ config : {
434
+ build : {
435
+ publish : publicDir ,
436
+ edge_functions : 'netlify/edge-functions' ,
437
+ } ,
438
+ edge_functions : [
439
+ {
440
+ function : 'auth' ,
441
+ path : '/auth' ,
442
+ } ,
443
+ ] ,
444
+ } ,
445
+ } )
446
+ . withEdgeFunction ( {
447
+ handler : ( ) => new Response ( 'Auth response' ) ,
448
+ name : 'auth' ,
449
+ } )
450
+
451
+ await builder . buildAsync ( )
452
+
453
+ await withDevServer ( { cwd : builder . directory } , async ( { port } ) => {
454
+ const authResponseMessage = await got ( `http://localhost:${ port } /auth` ) . then ( ( response ) => response . body )
455
+
456
+ await builder
457
+ . withoutFile ( {
458
+ path : 'netlify/edge-functions/auth.js' ,
459
+ } )
460
+ . buildAsync ( )
461
+
462
+ const DETECT_FILE_CHANGE_DELAY = 500
463
+ await pause ( DETECT_FILE_CHANGE_DELAY )
464
+
465
+ const authNotFoundMessage = await got ( `http://localhost:${ port } /auth` , { throwHttpErrors : false } ) . then (
466
+ ( response ) => response . body ,
467
+ )
468
+
469
+ t . is ( authResponseMessage , 'Auth response' )
470
+ t . is ( authNotFoundMessage , 'Not Found' )
471
+ } )
472
+ } )
473
+ } )
474
+
380
475
/* eslint-enable require-await */
0 commit comments