import test from "ava" ; import * as faast from "../index" ; import * as functions from "./fixtures/functions" ; import { defaultGcWorker } from "../src/local/local-faast" ; import { existsSync } from "fs-extra" ; test ( "local garbage collector works for functions that are called" , async ( t ) => { const mod = await faast . faastLocal ( functions , { description : t . title } ) ; try { await mod . functions . hello ( "gc-test" ) ; await mod . cleanup ( { deleteResources : false } ) ; const mod2 = await faast . faastLocal ( functions , { gc : "force" , _gcWorker : async ( dir ) => { if ( dir === mod . state . tempDir ) { await defaultGcWorker ( dir ) ; } } , retentionInDays : 0 , description : t . title } ) ; await mod2 . cleanup ( ) ; t . false ( existsSync ( mod . state . tempDir ) ) ; } finally { await mod . cleanup ( ) ; } } ) ; test ( "local garbage collector works for functions that are never called" , async ( t ) => { const mod = await faast . faastLocal ( functions , { description : t . title } ) ; try { await mod . cleanup ( { deleteResources : false } ) ; const mod2 = await faast . faastLocal ( functions , { gc : "force" , _gcWorker : async ( dir ) => { if ( dir === mod . state . tempDir ) { await defaultGcWorker ( dir ) ; } } , retentionInDays : 0 , description : t . title } ) ; await mod2 . cleanup ( ) ; t . false ( existsSync ( mod . state . tempDir ) ) ; } finally { await mod . cleanup ( ) ; } } ) ;