@@ -31,6 +31,10 @@ func TestDeployCommand(t *testing.T) {
31
31
// Setup in-memory fs
32
32
fsys := afero .NewMemMapFs ()
33
33
require .NoError (t , utils .WriteConfig (fsys , false ))
34
+
35
+ require .NoError (t , afero .WriteFile (fsys , filepath .Join (utils .FunctionsDir , slug , "index.ts" ), []byte {}, 0644 ))
36
+ require .NoError (t , afero .WriteFile (fsys , filepath .Join (utils .FunctionsDir , slug + "-2" , "index.ts" ), []byte {}, 0644 ))
37
+
34
38
// Setup valid access token
35
39
token := apitest .RandomAccessToken (t )
36
40
t .Setenv ("SUPABASE_ACCESS_TOKEN" , string (token ))
@@ -120,6 +124,47 @@ import_map = "./import_map.json"
120
124
assert .Empty (t , apitest .ListUnmatchedRequests ())
121
125
})
122
126
127
+ t .Run ("deploys functions with main.ts as entrypoint" , func (t * testing.T ) {
128
+ t .Cleanup (func () { clear (utils .Config .Functions ) })
129
+ // Setup in-memory fs
130
+ fsys := afero .NewMemMapFs ()
131
+
132
+ // Setup function entrypoint
133
+ entrypointPath := filepath .Join (utils .FunctionsDir , slug , "main.ts" )
134
+ require .NoError (t , afero .WriteFile (fsys , entrypointPath , []byte {}, 0644 ))
135
+
136
+ // Setup valid access token
137
+ token := apitest .RandomAccessToken (t )
138
+ t .Setenv ("SUPABASE_ACCESS_TOKEN" , string (token ))
139
+ // Setup valid deno path
140
+ _ , err := fsys .Create (utils .DenoPathOverride )
141
+ require .NoError (t , err )
142
+ // Setup mock api
143
+ defer gock .OffAll ()
144
+ gock .New (utils .DefaultApiHost ).
145
+ Get ("/v1/projects/" + flags .ProjectRef + "/functions" ).
146
+ Reply (http .StatusOK ).
147
+ JSON ([]api.FunctionResponse {})
148
+ gock .New (utils .DefaultApiHost ).
149
+ Post ("/v1/projects/" + flags .ProjectRef + "/functions" ).
150
+ MatchParam ("slug" , slug ).
151
+ ParamPresent ("import_map_path" ).
152
+ Reply (http .StatusCreated ).
153
+ JSON (api.FunctionResponse {Id : "1" })
154
+ // Setup mock docker
155
+ require .NoError (t , apitest .MockDocker (utils .Docker ))
156
+ apitest .MockDockerStart (utils .Docker , imageUrl , containerId )
157
+ require .NoError (t , apitest .MockDockerLogs (utils .Docker , containerId , "bundled" ))
158
+ // Setup output file
159
+ outputDir := filepath .Join (utils .TempDir , fmt .Sprintf (".output_%s" , slug ))
160
+ require .NoError (t , afero .WriteFile (fsys , filepath .Join (outputDir , "output.eszip" ), []byte ("" ), 0644 ))
161
+ // Run test
162
+ err = Run (context .Background (), []string {slug }, true , nil , "" , 1 , fsys )
163
+ // Check error
164
+ assert .NoError (t , err )
165
+ assert .Empty (t , apitest .ListUnmatchedRequests ())
166
+ })
167
+
123
168
t .Run ("skip disabled functions from config" , func (t * testing.T ) {
124
169
t .Cleanup (func () { clear (utils .Config .Functions ) })
125
170
// Setup in-memory fs
@@ -190,6 +235,47 @@ import_map = "./import_map.json"
190
235
assert .ErrorContains (t , err , "No Functions specified or found in supabase/functions" )
191
236
})
192
237
238
+ t .Run ("throws error on missing entrypoint" , func (t * testing.T ) {
239
+ t .Cleanup (func () { clear (utils .Config .Functions ) })
240
+ // Setup in-memory fs
241
+ fsys := afero .NewMemMapFs ()
242
+ require .NoError (t , utils .WriteConfig (fsys , false ))
243
+
244
+ // Setup function entrypoint
245
+ entrypointPath := filepath .Join (utils .FunctionsDir , slug , "not-entrypoint.ts" )
246
+ require .NoError (t , afero .WriteFile (fsys , entrypointPath , []byte {}, 0644 ))
247
+
248
+ // Setup valid access token
249
+ token := apitest .RandomAccessToken (t )
250
+ t .Setenv ("SUPABASE_ACCESS_TOKEN" , string (token ))
251
+ // Setup valid deno path
252
+ _ , err := fsys .Create (utils .DenoPathOverride )
253
+ require .NoError (t , err )
254
+ // Setup mock api
255
+ defer gock .OffAll ()
256
+ gock .New (utils .DefaultApiHost ).
257
+ Get ("/v1/projects/" + flags .ProjectRef + "/functions" ).
258
+ Reply (http .StatusOK ).
259
+ JSON ([]api.FunctionResponse {})
260
+ gock .New (utils .DefaultApiHost ).
261
+ Post ("/v1/projects/" + flags .ProjectRef + "/functions" ).
262
+ MatchParam ("slug" , slug ).
263
+ ParamPresent ("import_map_path" ).
264
+ Reply (http .StatusCreated ).
265
+ JSON (api.FunctionResponse {Id : "1" })
266
+ // Setup mock docker
267
+ require .NoError (t , apitest .MockDocker (utils .Docker ))
268
+ apitest .MockDockerStart (utils .Docker , imageUrl , containerId )
269
+ require .NoError (t , apitest .MockDockerLogs (utils .Docker , containerId , "bundled" ))
270
+ // Setup output file
271
+ outputDir := filepath .Join (utils .TempDir , fmt .Sprintf (".output_%s" , slug ))
272
+ require .NoError (t , afero .WriteFile (fsys , filepath .Join (outputDir , "output.eszip" ), []byte ("" ), 0644 ))
273
+ // Run test
274
+ err = Run (context .Background (), []string {slug }, true , nil , "" , 1 , fsys )
275
+ // Check error
276
+ assert .ErrorContains (t , err , "Cannot find a valid entrypoint file" )
277
+ })
278
+
193
279
t .Run ("verify_jwt param falls back to config" , func (t * testing.T ) {
194
280
t .Cleanup (func () { clear (utils .Config .Functions ) })
195
281
// Setup in-memory fs
@@ -283,6 +369,10 @@ func TestImportMapPath(t *testing.T) {
283
369
// Setup in-memory fs
284
370
fsys := afero .NewMemMapFs ()
285
371
require .NoError (t , afero .WriteFile (fsys , utils .FallbackImportMapPath , []byte ("{}" ), 0644 ))
372
+
373
+ // Write function entrypoints
374
+ require .NoError (t , afero .WriteFile (fsys , filepath .Join (utils .FunctionsDir , "test" , "index.ts" ), []byte {}, 0644 ))
375
+
286
376
// Run test
287
377
fc , err := GetFunctionConfig ([]string {"test" }, "" , nil , fsys )
288
378
// Check error
@@ -299,6 +389,10 @@ func TestImportMapPath(t *testing.T) {
299
389
// Setup in-memory fs
300
390
fsys := afero .NewMemMapFs ()
301
391
require .NoError (t , afero .WriteFile (fsys , utils .FallbackImportMapPath , []byte ("{}" ), 0644 ))
392
+
393
+ // Write function entrypoints
394
+ require .NoError (t , afero .WriteFile (fsys , filepath .Join (utils .FunctionsDir , slug , "index.ts" ), []byte {}, 0644 ))
395
+
302
396
// Run test
303
397
fc , err := GetFunctionConfig ([]string {slug }, "" , nil , fsys )
304
398
// Check error
@@ -319,6 +413,9 @@ func TestImportMapPath(t *testing.T) {
319
413
require .NoError (t , afero .WriteFile (fsys , customImportMapPath , []byte ("{}" ), 0644 ))
320
414
// Create fallback import map to test precedence order
321
415
require .NoError (t , afero .WriteFile (fsys , utils .FallbackImportMapPath , []byte ("{}" ), 0644 ))
416
+ // Write function entrypoints
417
+ require .NoError (t , afero .WriteFile (fsys , filepath .Join (utils .FunctionsDir , slug , "index.ts" ), []byte {}, 0644 ))
418
+
322
419
// Run test
323
420
fc , err := GetFunctionConfig ([]string {slug }, customImportMapPath , cast .Ptr (false ), fsys )
324
421
// Check error
@@ -329,6 +426,10 @@ func TestImportMapPath(t *testing.T) {
329
426
t .Run ("returns empty string if no fallback" , func (t * testing.T ) {
330
427
// Setup in-memory fs
331
428
fsys := afero .NewMemMapFs ()
429
+
430
+ // Write function entrypoints
431
+ require .NoError (t , afero .WriteFile (fsys , filepath .Join (utils .FunctionsDir , "test" , "index.ts" ), []byte {}, 0644 ))
432
+
332
433
// Run test
333
434
fc , err := GetFunctionConfig ([]string {"test" }, "" , nil , fsys )
334
435
// Check error
@@ -341,6 +442,10 @@ func TestImportMapPath(t *testing.T) {
341
442
// Setup in-memory fs
342
443
fsys := afero .NewMemMapFs ()
343
444
require .NoError (t , afero .WriteFile (fsys , utils .FallbackImportMapPath , []byte ("{}" ), 0644 ))
445
+
446
+ // Write function entrypoints
447
+ require .NoError (t , afero .WriteFile (fsys , filepath .Join (utils .FunctionsDir , "test" , "index.ts" ), []byte {}, 0644 ))
448
+
344
449
// Run test
345
450
fc , err := GetFunctionConfig ([]string {"test" }, path , nil , fsys )
346
451
// Check error
0 commit comments