@@ -376,6 +376,129 @@ test('installation with a dependency file', async () => {
376376 ) ;
377377} ) ;
378378
379+ test ( 'installation with a dependency file with exact dependencies' , async ( ) => {
380+ // The typing of `got` is not exactly correct for this - it expects a
381+ // buffer but depending on inputs `got` can actually return an object.
382+ // @ts -ignore
383+ mocked ( got ) . mockImplementation ( ( ) =>
384+ // @ts -ignore
385+ Promise . resolve ( {
386+ body : { dependencies : { foo : '1.0.0' , got : '6.9.0' } } ,
387+ } )
388+ ) ;
389+
390+ // For this test, getFirstMatchingDirectory never errors.
391+ mocked (
392+ fsHelpers . getFirstMatchingDirectory
393+ ) . mockImplementation ( ( basePath : string , directories : Array < string > ) : string =>
394+ path . join ( basePath , directories [ 0 ] )
395+ ) ;
396+
397+ await writeFiles (
398+ [
399+ {
400+ name : 'package.json' ,
401+ type : 'package.json' ,
402+ content : 'https://example.com/package.json' ,
403+ directory : '' ,
404+ } ,
405+ {
406+ name : '.env' ,
407+ type : '.env' ,
408+ content : 'https://example.com/.env' ,
409+ directory : '' ,
410+ } ,
411+ ] ,
412+ './testing/' ,
413+ 'example' ,
414+ 'hello'
415+ ) ;
416+
417+ expect ( downloadFile ) . toHaveBeenCalledTimes ( 1 ) ;
418+ expect ( downloadFile ) . toHaveBeenCalledWith (
419+ 'https://example.com/.env' ,
420+ join ( 'testing' , '.env' )
421+ ) ;
422+
423+ expect ( got ) . toHaveBeenCalledTimes ( 1 ) ;
424+ expect ( got ) . toHaveBeenCalledWith ( 'https://example.com/package.json' , {
425+ json : true ,
426+ } ) ;
427+
428+ expect ( install ) . toHaveBeenCalledTimes ( 1 ) ;
429+ expect ( install ) . toHaveBeenCalledWith (
430+ { foo : '1.0.0' , got : '6.9.0' } ,
431+ { cwd : './testing/' , exact : true }
432+ ) ;
433+ } ) ;
434+
435+ test ( 'installation with a dependency file with mixed dependencies' , async ( ) => {
436+ // The typing of `got` is not exactly correct for this - it expects a
437+ // buffer but depending on inputs `got` can actually return an object.
438+ // @ts -ignore
439+ mocked ( got ) . mockImplementation ( ( ) =>
440+ // @ts -ignore
441+ Promise . resolve ( {
442+ body : {
443+ dependencies : {
444+ foo : '^1.0.0' ,
445+ got : '6.9.0' ,
446+ twilio : '^3' ,
447+ '@twilio/runtime-handler' : '1.2.0-rc.3' ,
448+ } ,
449+ } ,
450+ } )
451+ ) ;
452+
453+ // For this test, getFirstMatchingDirectory never errors.
454+ mocked (
455+ fsHelpers . getFirstMatchingDirectory
456+ ) . mockImplementation ( ( basePath : string , directories : Array < string > ) : string =>
457+ path . join ( basePath , directories [ 0 ] )
458+ ) ;
459+
460+ await writeFiles (
461+ [
462+ {
463+ name : 'package.json' ,
464+ type : 'package.json' ,
465+ content : 'https://example.com/package.json' ,
466+ directory : '' ,
467+ } ,
468+ {
469+ name : '.env' ,
470+ type : '.env' ,
471+ content : 'https://example.com/.env' ,
472+ directory : '' ,
473+ } ,
474+ ] ,
475+ './testing/' ,
476+ 'example' ,
477+ 'hello'
478+ ) ;
479+
480+ expect ( downloadFile ) . toHaveBeenCalledTimes ( 1 ) ;
481+ expect ( downloadFile ) . toHaveBeenCalledWith (
482+ 'https://example.com/.env' ,
483+ join ( 'testing' , '.env' )
484+ ) ;
485+
486+ expect ( got ) . toHaveBeenCalledTimes ( 1 ) ;
487+ expect ( got ) . toHaveBeenCalledWith ( 'https://example.com/package.json' , {
488+ json : true ,
489+ } ) ;
490+
491+ expect ( install ) . toHaveBeenCalledTimes ( 2 ) ;
492+ expect ( install ) . toHaveBeenCalledWith (
493+ { foo : '^1.0.0' , twilio : '^3' } ,
494+ { cwd : './testing/' }
495+ ) ;
496+ expect ( install ) . toHaveBeenCalledWith (
497+ { got : '6.9.0' , '@twilio/runtime-handler' : '1.2.0-rc.3' } ,
498+ { cwd : './testing/' , exact : true }
499+ ) ;
500+ } ) ;
501+
379502test ( 'installation with an existing dot-env file' , async ( ) => {
380503 mocked ( fileExists ) . mockReturnValue ( Promise . resolve ( true ) ) ;
381504 mocked ( readFile ) . mockReturnValue ( Promise . resolve ( '# Comment\nFOO=BAR\n' ) ) ;
@@ -431,7 +554,7 @@ test('installation with overlapping function files throws errors before writing'
431554 path . join ( basePath , directories [ 0 ] )
432555 ) ;
433556
434- mocked ( fileExists ) . mockImplementation ( p =>
557+ mocked ( fileExists ) . mockImplementation ( ( p ) =>
435558 Promise . resolve ( p == join ( 'functions' , 'example' , 'hello.js' ) )
436559 ) ;
437560
@@ -470,7 +593,7 @@ test('installation with overlapping asset files throws errors before writing', a
470593 path . join ( basePath , directories [ 0 ] )
471594 ) ;
472595
473- mocked ( fileExists ) . mockImplementation ( p =>
596+ mocked ( fileExists ) . mockImplementation ( ( p ) =>
474597 Promise . resolve ( p == join ( 'assets' , 'example' , 'hello.wav' ) )
475598 ) ;
476599
0 commit comments