@@ -85,12 +85,19 @@ test('installation with basic functions', async () => {
85
85
name : 'hello.js' ,
86
86
type : 'functions' ,
87
87
content : 'https://example.com/hello.js' ,
88
+ directory : '' ,
89
+ } ,
90
+ {
91
+ name : '.env' ,
92
+ type : '.env' ,
93
+ content : 'https://example.com/.env' ,
94
+ directory : '' ,
88
95
} ,
89
- { name : '.env' , type : '.env' , content : 'https://example.com/.env' } ,
90
96
{
91
97
name : 'README.md' ,
92
98
type : 'README.md' ,
93
99
content : 'https://example.com/README.md' ,
100
+ directory : '' ,
94
101
} ,
95
102
] ,
96
103
'./testing/' ,
@@ -135,13 +142,20 @@ test('installation with functions and assets', async () => {
135
142
name : 'hello.js' ,
136
143
type : 'functions' ,
137
144
content : 'https://example.com/hello.js' ,
145
+ directory : '' ,
138
146
} ,
139
147
{
140
148
name : 'hello.wav' ,
141
149
type : 'assets' ,
142
150
content : 'https://example.com/hello.wav' ,
151
+ directory : '' ,
152
+ } ,
153
+ {
154
+ name : '.env' ,
155
+ type : '.env' ,
156
+ content : 'https://example.com/.env' ,
157
+ directory : '' ,
143
158
} ,
144
- { name : '.env' , type : '.env' , content : 'https://example.com/.env' } ,
145
159
] ,
146
160
'./testing/' ,
147
161
'example' ,
@@ -185,18 +199,26 @@ test('installation with functions and assets and blank namespace', async () => {
185
199
name : 'hello.js' ,
186
200
type : 'functions' ,
187
201
content : 'https://example.com/hello.js' ,
202
+ directory : '' ,
188
203
} ,
189
204
{
190
205
name : 'hello.wav' ,
191
206
type : 'assets' ,
192
207
content : 'https://example.com/hello.wav' ,
208
+ directory : '' ,
193
209
} ,
194
210
{
195
211
name : 'README.md' ,
196
212
type : 'README.md' ,
197
213
content : 'https://example.com/README.md' ,
214
+ directory : '' ,
215
+ } ,
216
+ {
217
+ name : '.env' ,
218
+ type : '.env' ,
219
+ content : 'https://example.com/.env' ,
220
+ directory : '' ,
198
221
} ,
199
- { name : '.env' , type : '.env' , content : 'https://example.com/.env' } ,
200
222
] ,
201
223
'./testing/' ,
202
224
'' ,
@@ -269,8 +291,14 @@ test('installation with an empty dependency file', async () => {
269
291
name : 'package.json' ,
270
292
type : 'package.json' ,
271
293
content : 'https://example.com/package.json' ,
294
+ directory : '' ,
295
+ } ,
296
+ {
297
+ name : '.env' ,
298
+ type : '.env' ,
299
+ content : 'https://example.com/.env' ,
300
+ directory : '' ,
272
301
} ,
273
- { name : '.env' , type : '.env' , content : 'https://example.com/.env' } ,
274
302
] ,
275
303
'./testing/' ,
276
304
'example' ,
@@ -314,8 +342,14 @@ test('installation with a dependency file', async () => {
314
342
name : 'package.json' ,
315
343
type : 'package.json' ,
316
344
content : 'https://example.com/package.json' ,
345
+ directory : '' ,
346
+ } ,
347
+ {
348
+ name : '.env' ,
349
+ type : '.env' ,
350
+ content : 'https://example.com/.env' ,
351
+ directory : '' ,
317
352
} ,
318
- { name : '.env' , type : '.env' , content : 'https://example.com/.env' } ,
319
353
] ,
320
354
'./testing/' ,
321
355
'example' ,
@@ -359,7 +393,14 @@ test('installation with an existing dot-env file', async () => {
359
393
) ;
360
394
361
395
await writeFiles (
362
- [ { name : '.env' , type : '.env' , content : 'https://example.com/.env' } ] ,
396
+ [
397
+ {
398
+ name : '.env' ,
399
+ type : '.env' ,
400
+ content : 'https://example.com/.env' ,
401
+ directory : '' ,
402
+ } ,
403
+ ] ,
363
404
'./testing/' ,
364
405
'example' ,
365
406
'hello'
@@ -398,8 +439,14 @@ test('installation with overlapping function files throws errors before writing'
398
439
name : 'hello.js' ,
399
440
type : 'functions' ,
400
441
content : 'https://example.com/hello.js' ,
442
+ directory : '' ,
443
+ } ,
444
+ {
445
+ name : '.env' ,
446
+ type : '.env' ,
447
+ content : 'https://example.com/.env' ,
448
+ directory : '' ,
401
449
} ,
402
- { name : '.env' , type : '.env' , content : 'https://example.com/.env' } ,
403
450
] ,
404
451
'./' ,
405
452
'example' ,
@@ -431,13 +478,20 @@ test('installation with overlapping asset files throws errors before writing', a
431
478
name : 'hello.js' ,
432
479
type : 'functions' ,
433
480
content : 'https://example.com/hello.js' ,
481
+ directory : '' ,
434
482
} ,
435
483
{
436
484
name : 'hello.wav' ,
437
485
type : 'assets' ,
438
486
content : 'https://example.com/hello.wav' ,
487
+ directory : '' ,
488
+ } ,
489
+ {
490
+ name : '.env' ,
491
+ type : '.env' ,
492
+ content : 'https://example.com/.env' ,
493
+ directory : '' ,
439
494
} ,
440
- { name : '.env' , type : '.env' , content : 'https://example.com/.env' } ,
441
495
] ,
442
496
'./' ,
443
497
'example' ,
@@ -450,3 +504,73 @@ test('installation with overlapping asset files throws errors before writing', a
450
504
expect ( downloadFile ) . toHaveBeenCalledTimes ( 0 ) ;
451
505
expect ( writeFile ) . toHaveBeenCalledTimes ( 0 ) ;
452
506
} ) ;
507
+
508
+ test ( 'installation with functions and assets in nested directories' , async ( ) => {
509
+ // For this test, getFirstMatchingDirectory never errors.
510
+ mocked (
511
+ fsHelpers . getFirstMatchingDirectory
512
+ ) . mockImplementation ( ( basePath : string , directories : Array < string > ) : string =>
513
+ path . join ( basePath , directories [ 0 ] )
514
+ ) ;
515
+
516
+ await writeFiles (
517
+ [
518
+ {
519
+ name : 'hello.js' ,
520
+ type : 'functions' ,
521
+ content : 'https://example.com/hello.js' ,
522
+ directory : 'admin' ,
523
+ } ,
524
+ {
525
+ name : 'woohoo.jpg' ,
526
+ type : 'assets' ,
527
+ content : 'https://example.com/woohoo.jpg' ,
528
+ directory : 'success' ,
529
+ } ,
530
+ {
531
+ name : '.env' ,
532
+ type : '.env' ,
533
+ content : 'https://example.com/.env' ,
534
+ directory : '' ,
535
+ } ,
536
+ {
537
+ name : 'README.md' ,
538
+ type : 'README.md' ,
539
+ content : 'https://example.com/README.md' ,
540
+ directory : '' ,
541
+ } ,
542
+ ] ,
543
+ './testing/' ,
544
+ 'example' ,
545
+ 'hello'
546
+ ) ;
547
+
548
+ expect ( downloadFile ) . toHaveBeenCalledTimes ( 4 ) ;
549
+ expect ( downloadFile ) . toHaveBeenCalledWith (
550
+ 'https://example.com/.env' ,
551
+ 'testing/.env'
552
+ ) ;
553
+ expect ( downloadFile ) . toHaveBeenCalledWith (
554
+ 'https://example.com/hello.js' ,
555
+ 'testing/functions/example/admin/hello.js'
556
+ ) ;
557
+ expect ( downloadFile ) . toHaveBeenCalledWith (
558
+ 'https://example.com/README.md' ,
559
+ 'testing/readmes/example/hello.md'
560
+ ) ;
561
+ expect ( downloadFile ) . toHaveBeenCalledWith (
562
+ 'https://example.com/woohoo.jpg' ,
563
+ 'testing/assets/example/success/woohoo.jpg'
564
+ ) ;
565
+
566
+ expect ( mkdir ) . toHaveBeenCalledTimes ( 3 ) ;
567
+ expect ( mkdir ) . toHaveBeenCalledWith ( 'testing/functions/example' , {
568
+ recursive : true ,
569
+ } ) ;
570
+ expect ( mkdir ) . toHaveBeenCalledWith ( 'testing/readmes/example' , {
571
+ recursive : true ,
572
+ } ) ;
573
+ expect ( mkdir ) . toHaveBeenCalledWith ( 'testing/assets/example' , {
574
+ recursive : true ,
575
+ } ) ;
576
+ } ) ;
0 commit comments