@@ -9,7 +9,7 @@ import getNode from 'get-node'
99import moize from 'moize'
1010import { pathExists } from 'path-exists'
1111import semver from 'semver'
12- import sinon from 'sinon '
12+ import { spy , spyOn } from 'tinyspy '
1313import { tmpName } from 'tmp-promise'
1414
1515import { zipItAndShipIt } from '../../lib/plugins_core/functions/index.js'
@@ -425,8 +425,8 @@ test('Print warning when headers file is missing from publish directory', async
425425} )
426426
427427test . serial ( 'Passes the right properties to zip-it-and-ship-it' , async ( t ) => {
428- const mockZipFunctions = sinon . stub ( ) . resolves ( )
429- const stub = sinon . stub ( zipItAndShipIt , 'zipFunctions' ) . get ( ( ) => mockZipFunctions )
428+ const mockZipFunctions = spy ( ( ) => Promise . resolve ( ) )
429+ const stub = spyOn ( zipItAndShipIt , 'zipFunctions' , mockZipFunctions )
430430 const fixtureDir = join ( FIXTURES_DIR , 'core' )
431431
432432 await new Fixture ( './fixtures/core' ) . runWithBuild ( )
@@ -439,7 +439,7 @@ test.serial('Passes the right properties to zip-it-and-ship-it', async (t) => {
439439
440440 t . is ( mockZipFunctions . callCount , 2 )
441441
442- const params1 = mockZipFunctions . firstCall . args [ 2 ]
442+ const params1 = mockZipFunctions . calls [ 0 ] [ 2 ]
443443
444444 t . is ( params1 . basePath , fixtureDir )
445445 t . true ( params1 . config [ '*' ] . zipGo )
@@ -453,15 +453,15 @@ test.serial('Passes the right properties to zip-it-and-ship-it', async (t) => {
453453 t . is ( params1 . config [ '*' ] . nodeVersion , undefined )
454454 }
455455
456- const params2 = mockZipFunctions . secondCall . args [ 2 ]
456+ const params2 = mockZipFunctions . calls [ 1 ] [ 2 ]
457457
458458 t . is ( params2 . config [ '*' ] . nodeVersion , 'nodejs00.x' )
459459 t . is ( params2 . config [ '*' ] . zipGo , undefined )
460460} )
461461
462462test . serial ( 'Passes functions generated by build plugins to zip-it-and-ship-it' , async ( t ) => {
463- const mockZipFunctions = sinon . stub ( ) . resolves ( [ ] )
464- const stub = sinon . stub ( zipItAndShipIt , 'zipFunctions' ) . get ( ( ) => mockZipFunctions )
463+ const mockZipFunctions = spy ( ( ) => Promise . resolve ( [ ] ) )
464+ const stub = spyOn ( zipItAndShipIt , 'zipFunctions' , mockZipFunctions )
465465 const fixtureName = 'functions_generated_from_steps'
466466 const fixtureDir = join ( FIXTURES_DIR , fixtureName )
467467
@@ -474,7 +474,7 @@ test.serial('Passes functions generated by build plugins to zip-it-and-ship-it',
474474 t . true ( success )
475475 t . is ( mockZipFunctions . callCount , 1 )
476476
477- const { generated, user } = mockZipFunctions . firstCall . args [ 0 ]
477+ const { generated, user } = mockZipFunctions . calls [ 0 ] [ 0 ]
478478
479479 t . is ( generated . directories . length , 2 )
480480 t . true ( generated . directories . includes ( resolve ( fixtureDir , '.netlify/functions-internal' ) ) )
@@ -501,8 +501,8 @@ test.serial('Passes functions generated by build plugins to zip-it-and-ship-it',
501501} )
502502
503503test . serial ( 'Passes the right feature flags to zip-it-and-ship-it' , async ( t ) => {
504- const mockZipFunctions = sinon . stub ( ) . resolves ( )
505- const stub = sinon . stub ( zipItAndShipIt , 'zipFunctions' ) . get ( ( ) => mockZipFunctions )
504+ const mockZipFunctions = spy ( ( ) => Promise . resolve ( ) )
505+ const stub = spyOn ( zipItAndShipIt , 'zipFunctions' , mockZipFunctions )
506506
507507 await new Fixture ( './fixtures/schedule' ) . runWithBuild ( )
508508 await new Fixture ( './fixtures/schedule' ) . withFlags ( { featureFlags : { buildbot_zisi_trace_nft : true } } ) . runWithBuild ( )
@@ -517,16 +517,16 @@ test.serial('Passes the right feature flags to zip-it-and-ship-it', async (t) =>
517517
518518 t . is ( mockZipFunctions . callCount , 4 )
519519
520- t . false ( mockZipFunctions . getCall ( 0 ) . args [ 2 ] . featureFlags . traceWithNft )
521- t . false ( mockZipFunctions . getCall ( 0 ) . args [ 2 ] . featureFlags . parseWithEsbuild )
522- t . is ( mockZipFunctions . getCall ( 0 ) . args [ 2 ] . config . test . schedule , '@daily' )
523- t . is ( mockZipFunctions . getCall ( 0 ) . args [ 2 ] . featureFlags . this_is_a_mock_flag , undefined )
524- t . is ( mockZipFunctions . getCall ( 0 ) . args [ 2 ] . featureFlags . and_another_one , undefined )
520+ t . false ( mockZipFunctions . calls [ 0 ] [ 2 ] . featureFlags . traceWithNft )
521+ t . false ( mockZipFunctions . calls [ 0 ] [ 2 ] . featureFlags . parseWithEsbuild )
522+ t . is ( mockZipFunctions . calls [ 0 ] [ 2 ] . config . test . schedule , '@daily' )
523+ t . is ( mockZipFunctions . calls [ 0 ] [ 2 ] . featureFlags . this_is_a_mock_flag , undefined )
524+ t . is ( mockZipFunctions . calls [ 0 ] [ 2 ] . featureFlags . and_another_one , undefined )
525525
526- t . true ( mockZipFunctions . getCall ( 1 ) . args [ 2 ] . featureFlags . traceWithNft )
527- t . true ( mockZipFunctions . getCall ( 2 ) . args [ 2 ] . featureFlags . parseWithEsbuild )
528- t . true ( mockZipFunctions . getCall ( 3 ) . args [ 2 ] . featureFlags . this_is_a_mock_flag )
529- t . true ( mockZipFunctions . getCall ( 3 ) . args [ 2 ] . featureFlags . and_another_one )
526+ t . true ( mockZipFunctions . calls [ 1 ] [ 2 ] . featureFlags . traceWithNft )
527+ t . true ( mockZipFunctions . calls [ 2 ] [ 2 ] . featureFlags . parseWithEsbuild )
528+ t . true ( mockZipFunctions . calls [ 3 ] [ 2 ] . featureFlags . this_is_a_mock_flag )
529+ t . true ( mockZipFunctions . calls [ 3 ] [ 2 ] . featureFlags . and_another_one )
530530} )
531531
532532test ( 'Print warning on lingering processes' , async ( t ) => {
@@ -597,8 +597,8 @@ test('Removes duplicate function names from the list of processed functions', as
597597
598598test . serial ( '`rustTargetDirectory` is passed to zip-it-and-ship-it only when running in buildbot' , async ( t ) => {
599599 const runCount = 4
600- const mockZipFunctions = sinon . stub ( ) . resolves ( )
601- const stub = sinon . stub ( zipItAndShipIt , 'zipFunctions' ) . get ( ( ) => mockZipFunctions )
600+ const mockZipFunctions = spy ( ( ) => Promise . resolve ( ) )
601+ const stub = spyOn ( zipItAndShipIt , 'zipFunctions' , mockZipFunctions )
602602
603603 await new Fixture ( './fixtures/functions_config_1' ) . withFlags ( { mode : 'buildbot' } ) . runWithBuild ( )
604604 await new Fixture ( './fixtures/functions_config_1' ) . runWithBuild ( )
@@ -609,10 +609,7 @@ test.serial('`rustTargetDirectory` is passed to zip-it-and-ship-it only when run
609609
610610 t . is ( mockZipFunctions . callCount , runCount )
611611
612- const { args : call1Args } = mockZipFunctions . getCall ( 0 )
613- const { args : call2Args } = mockZipFunctions . getCall ( 1 )
614- const { args : call3Args } = mockZipFunctions . getCall ( 2 )
615- const { args : call4Args } = mockZipFunctions . getCall ( 3 )
612+ const [ call1Args , call2Args , call3Args , call4Args ] = mockZipFunctions . calls
616613
617614 t . is (
618615 call1Args [ 2 ] . config [ '*' ] . rustTargetDirectory ,
@@ -628,23 +625,23 @@ test.serial('`rustTargetDirectory` is passed to zip-it-and-ship-it only when run
628625
629626test . serial ( 'configFileDirectories is passed to zip-it-and-ship-it' , async ( t ) => {
630627 const runCount = 1
631- const mockZipFunctions = sinon . stub ( ) . resolves ( )
632- const stub = sinon . stub ( zipItAndShipIt , 'zipFunctions' ) . get ( ( ) => mockZipFunctions )
628+ const mockZipFunctions = spy ( ( ) => Promise . resolve ( ) )
629+ const stub = spyOn ( zipItAndShipIt , 'zipFunctions' , mockZipFunctions )
633630
634631 await new Fixture ( './fixtures/functions_config_json' ) . withFlags ( { mode : 'buildbot' } ) . runWithBuild ( )
635632 stub . restore ( )
636633
637634 t . is ( mockZipFunctions . callCount , runCount )
638635
639- const { args : call1Args } = mockZipFunctions . getCall ( 0 )
636+ const call1Args = mockZipFunctions . calls [ 0 ]
640637
641638 t . deepEqual ( call1Args [ 2 ] . configFileDirectories , [
642639 join ( FIXTURES_DIR , 'functions_config_json/.netlify/functions-internal' ) ,
643640 ] )
644641} )
645642
646643test . serial ( 'functions can have a config with different parameters passed to zip-it-and-ship-it' , async ( t ) => {
647- const zipItAndShipItSpy = sinon . spy ( zipItAndShipIt , 'zipFunctions' )
644+ const zipItAndShipItSpy = spyOn ( zipItAndShipIt , 'zipFunctions' )
648645 const output = await new Fixture ( './fixtures/functions_config_json' )
649646 . withFlags ( {
650647 mode : 'buildbot' ,
@@ -653,7 +650,7 @@ test.serial('functions can have a config with different parameters passed to zip
653650
654651 zipItAndShipItSpy . restore ( )
655652
656- const { args : call1Args } = zipItAndShipItSpy . getCall ( 0 )
653+ const call1Args = zipItAndShipItSpy . calls [ 0 ]
657654 const { functions : functions } = await importJsonFile ( call1Args [ 2 ] . manifest )
658655
659656 t . is ( functions [ 0 ] . displayName , 'Function One' )
@@ -664,11 +661,11 @@ test.serial('functions can have a config with different parameters passed to zip
664661} )
665662
666663test . serial ( 'internalSrcFolder is passed to zip-it-and-ship-it and helps prefill the generator field' , async ( t ) => {
667- const zipItAndShipItSpy = sinon . spy ( zipItAndShipIt , 'zipFunctions' )
664+ const zipItAndShipItSpy = spyOn ( zipItAndShipIt , 'zipFunctions' )
668665
669666 await new Fixture ( './fixtures/functions_internal_src_folder' ) . withFlags ( { mode : 'buildbot' } ) . runWithBuild ( )
670667 zipItAndShipItSpy . restore ( )
671- const { args : call1Args } = zipItAndShipItSpy . getCall ( 0 )
668+ const call1Args = zipItAndShipItSpy . calls [ 0 ]
672669
673670 const [ paths , , options ] = call1Args
674671
0 commit comments