@@ -1067,7 +1067,7 @@ describe('tools', () => {
1067
1067
name : edgeFunction . name ,
1068
1068
status : edgeFunction . status ,
1069
1069
entrypoint_path : 'index.ts' ,
1070
- import_map_path : null ,
1070
+ import_map_path : undefined ,
1071
1071
import_map : false ,
1072
1072
verify_jwt : true ,
1073
1073
created_at : expect . stringMatching (
@@ -1126,7 +1126,7 @@ describe('tools', () => {
1126
1126
name : functionName ,
1127
1127
status : 'ACTIVE' ,
1128
1128
entrypoint_path : expect . stringMatching ( / i n d e x \. t s $ / ) ,
1129
- import_map_path : null ,
1129
+ import_map_path : undefined ,
1130
1130
import_map : false ,
1131
1131
verify_jwt : true ,
1132
1132
created_at : expect . stringMatching (
@@ -1193,7 +1193,7 @@ describe('tools', () => {
1193
1193
name : functionName ,
1194
1194
status : 'ACTIVE' ,
1195
1195
entrypoint_path : expect . stringMatching ( / i n d e x \. t s $ / ) ,
1196
- import_map_path : null ,
1196
+ import_map_path : undefined ,
1197
1197
import_map : false ,
1198
1198
verify_jwt : true ,
1199
1199
created_at : expect . stringMatching (
@@ -1210,6 +1210,182 @@ describe('tools', () => {
1210
1210
) ;
1211
1211
} ) ;
1212
1212
1213
+ test ( 'custom edge function import map' , async ( ) => {
1214
+ const { callTool } = await setup ( ) ;
1215
+
1216
+ const org = await createOrganization ( {
1217
+ name : 'My Org' ,
1218
+ plan : 'free' ,
1219
+ allowed_release_channels : [ 'ga' ] ,
1220
+ } ) ;
1221
+
1222
+ const project = await createProject ( {
1223
+ name : 'Project 1' ,
1224
+ region : 'us-east-1' ,
1225
+ organization_id : org . id ,
1226
+ } ) ;
1227
+
1228
+ const functionName = 'hello-world' ;
1229
+ const functionCode = 'console.log("Hello, world!");' ;
1230
+
1231
+ const result = await callTool ( {
1232
+ name : 'deploy_edge_function' ,
1233
+ arguments : {
1234
+ project_id : project . id ,
1235
+ name : functionName ,
1236
+ import_map_path : 'custom-map.json' ,
1237
+ files : [
1238
+ {
1239
+ name : 'index.ts' ,
1240
+ content : functionCode ,
1241
+ } ,
1242
+ {
1243
+ name : 'custom-map.json' ,
1244
+ content : '{}' ,
1245
+ } ,
1246
+ ] ,
1247
+ } ,
1248
+ } ) ;
1249
+
1250
+ expect ( result . import_map ) . toBe ( true ) ;
1251
+ expect ( result . import_map_path ) . toMatch ( / c u s t o m - m a p \. j s o n $ / ) ;
1252
+ } ) ;
1253
+
1254
+ test ( 'default edge function import map to deno.json' , async ( ) => {
1255
+ const { callTool } = await setup ( ) ;
1256
+
1257
+ const org = await createOrganization ( {
1258
+ name : 'My Org' ,
1259
+ plan : 'free' ,
1260
+ allowed_release_channels : [ 'ga' ] ,
1261
+ } ) ;
1262
+
1263
+ const project = await createProject ( {
1264
+ name : 'Project 1' ,
1265
+ region : 'us-east-1' ,
1266
+ organization_id : org . id ,
1267
+ } ) ;
1268
+
1269
+ const functionName = 'hello-world' ;
1270
+ const functionCode = 'console.log("Hello, world!");' ;
1271
+
1272
+ const result = await callTool ( {
1273
+ name : 'deploy_edge_function' ,
1274
+ arguments : {
1275
+ project_id : project . id ,
1276
+ name : functionName ,
1277
+ files : [
1278
+ {
1279
+ name : 'index.ts' ,
1280
+ content : functionCode ,
1281
+ } ,
1282
+ {
1283
+ name : 'deno.json' ,
1284
+ content : '{}' ,
1285
+ } ,
1286
+ ] ,
1287
+ } ,
1288
+ } ) ;
1289
+
1290
+ expect ( result . import_map ) . toBe ( true ) ;
1291
+ expect ( result . import_map_path ) . toMatch ( / d e n o \. j s o n $ / ) ;
1292
+ } ) ;
1293
+
1294
+ test ( 'default edge function import map to import_map.json' , async ( ) => {
1295
+ const { callTool } = await setup ( ) ;
1296
+
1297
+ const org = await createOrganization ( {
1298
+ name : 'My Org' ,
1299
+ plan : 'free' ,
1300
+ allowed_release_channels : [ 'ga' ] ,
1301
+ } ) ;
1302
+
1303
+ const project = await createProject ( {
1304
+ name : 'Project 1' ,
1305
+ region : 'us-east-1' ,
1306
+ organization_id : org . id ,
1307
+ } ) ;
1308
+
1309
+ const functionName = 'hello-world' ;
1310
+ const functionCode = 'console.log("Hello, world!");' ;
1311
+
1312
+ const result = await callTool ( {
1313
+ name : 'deploy_edge_function' ,
1314
+ arguments : {
1315
+ project_id : project . id ,
1316
+ name : functionName ,
1317
+ files : [
1318
+ {
1319
+ name : 'index.ts' ,
1320
+ content : functionCode ,
1321
+ } ,
1322
+ {
1323
+ name : 'import_map.json' ,
1324
+ content : '{}' ,
1325
+ } ,
1326
+ ] ,
1327
+ } ,
1328
+ } ) ;
1329
+
1330
+ expect ( result . import_map ) . toBe ( true ) ;
1331
+ expect ( result . import_map_path ) . toMatch ( / i m p o r t _ m a p \. j s o n $ / ) ;
1332
+ } ) ;
1333
+
1334
+ test ( 'updating edge function with missing import_map_path defaults to previous value' , async ( ) => {
1335
+ const { callTool } = await setup ( ) ;
1336
+ const org = await createOrganization ( {
1337
+ name : 'My Org' ,
1338
+ plan : 'free' ,
1339
+ allowed_release_channels : [ 'ga' ] ,
1340
+ } ) ;
1341
+
1342
+ const project = await createProject ( {
1343
+ name : 'Project 1' ,
1344
+ region : 'us-east-1' ,
1345
+ organization_id : org . id ,
1346
+ } ) ;
1347
+ project . status = 'ACTIVE_HEALTHY' ;
1348
+
1349
+ const functionName = 'hello-world' ;
1350
+
1351
+ const edgeFunction = await project . deployEdgeFunction (
1352
+ {
1353
+ name : functionName ,
1354
+ entrypoint_path : 'index.ts' ,
1355
+ import_map_path : 'custom-map.json' ,
1356
+ } ,
1357
+ [
1358
+ new File ( [ 'console.log("Hello, world!");' ] , 'index.ts' , {
1359
+ type : 'application/typescript' ,
1360
+ } ) ,
1361
+ new File ( [ '{}' ] , 'custom-map.json' , {
1362
+ type : 'application/json' ,
1363
+ } ) ,
1364
+ ]
1365
+ ) ;
1366
+
1367
+ const result = await callTool ( {
1368
+ name : 'deploy_edge_function' ,
1369
+ arguments : {
1370
+ project_id : project . id ,
1371
+ name : functionName ,
1372
+ files : [
1373
+ {
1374
+ name : 'index.ts' ,
1375
+ content : 'console.log("Hello, world! v2");' ,
1376
+ } ,
1377
+ {
1378
+ name : 'custom-map.json' ,
1379
+ content : '{}' ,
1380
+ } ,
1381
+ ] ,
1382
+ } ,
1383
+ } ) ;
1384
+
1385
+ expect ( result . import_map ) . toBe ( true ) ;
1386
+ expect ( result . import_map_path ) . toMatch ( / c u s t o m - m a p \. j s o n $ / ) ;
1387
+ } ) ;
1388
+
1213
1389
test ( 'create branch' , async ( ) => {
1214
1390
const { callTool } = await setup ( ) ;
1215
1391
0 commit comments