@@ -32,7 +32,7 @@ const testMatrix = [
3232 { args : [ ] } ,
3333
3434 // some tests are still failing with this enabled
35- // { args: ['--trafficMesh '] }
35+ // { args: ['--edgeHandlers '] }
3636]
3737
3838const testName = ( title , args ) => ( args . length <= 0 ? title : `${ title } - ${ args . join ( ' ' ) } ` )
@@ -1210,7 +1210,61 @@ testMatrix.forEach(({ args }) => {
12101210 const version = Number . parseInt ( process . version . slice ( 1 ) . split ( '.' ) [ 0 ] )
12111211 const EDGE_HANDLER_MIN_VERSION = 10
12121212 if ( version >= EDGE_HANDLER_MIN_VERSION ) {
1213- test ( testName ( 'should serve edge handlers' , args ) , async ( t ) => {
1213+ test ( testName ( 'should serve edge handlers with --edgeHandlers flag' , args ) , async ( t ) => {
1214+ await withSiteBuilder ( 'site-with-fully-qualified-redirect-rule' , async ( builder ) => {
1215+ const publicDir = 'public'
1216+ builder
1217+ . withNetlifyToml ( {
1218+ config : {
1219+ build : { publish : publicDir } ,
1220+ redirects : [
1221+ {
1222+ from : '/edge-handler' ,
1223+ to : 'index.html' ,
1224+ status : 200 ,
1225+ edge_handler : 'smoke' ,
1226+ force : true ,
1227+ } ,
1228+ ] ,
1229+ } ,
1230+ } )
1231+ . withContentFiles ( [
1232+ {
1233+ path : path . join ( publicDir , 'index.html' ) ,
1234+ content : '<html>index</html>' ,
1235+ } ,
1236+ ] )
1237+ . withEdgeHandlers ( {
1238+ fileName : 'smoke.js' ,
1239+ handlers : {
1240+ onRequest : ( event ) => {
1241+ event . replaceResponse (
1242+ // eslint-disable-next-line no-undef
1243+ new Response ( null , {
1244+ headers : {
1245+ Location : 'https://google.com/' ,
1246+ } ,
1247+ status : 301 ,
1248+ } ) ,
1249+ )
1250+ } ,
1251+ } ,
1252+ } )
1253+
1254+ await builder . buildAsync ( )
1255+
1256+ await withDevServer ( { cwd : builder . directory , args : [ ...args , '--edgeHandlers' ] } , async ( server ) => {
1257+ const response = await got ( `${ server . url } /edge-handler` , {
1258+ followRedirect : false ,
1259+ } )
1260+
1261+ t . is ( response . statusCode , 301 )
1262+ t . is ( response . headers . location , 'https://google.com/' )
1263+ } )
1264+ } )
1265+ } )
1266+
1267+ test ( testName ( 'should serve edge handlers with deprecated --trafficMesh flag' , args ) , async ( t ) => {
12141268 await withSiteBuilder ( 'site-with-fully-qualified-redirect-rule' , async ( builder ) => {
12151269 const publicDir = 'public'
12161270 builder
@@ -1282,7 +1336,7 @@ testMatrix.forEach(({ args }) => {
12821336
12831337 await builder . buildAsync ( )
12841338
1285- await withDevServer ( { cwd : builder . directory , args : [ ...args , '--trafficMesh ' ] } , async ( server ) => {
1339+ await withDevServer ( { cwd : builder . directory , args : [ ...args , '--edgeHandlers ' ] } , async ( server ) => {
12861340 const response = await got ( `${ server . url } /index.html` )
12871341
12881342 t . is ( response . statusCode , 200 )
0 commit comments