import { strict as assert } from "assert" ; import { SummaryType } from "@fluidframework/protocol-definitions" ; import { IContainerRuntimeBase , IGarbageCollectionData , IFluidDataStoreContext , } from "@fluidframework/runtime-definitions" ; import { MockFluidDataStoreContext } from "@fluidframework/test-runtime-utils" ; import { FluidDataStoreRuntime , ISharedObjectRegistry } from "../dataStoreRuntime" ; describe ( "FluidDataStoreRuntime Tests" , ( ) => { let dataStoreContext ; let sharedObjectRegistry ; const loadRuntime = ( context , registry ) => FluidDataStoreRuntime . load ( context , registry , false ) ; beforeEach ( ( ) => { dataStoreContext = new MockFluidDataStoreContext ( ) ; dataStoreContext . containerRuntime = { } as unknown as IContainerRuntimeBase ; sharedObjectRegistry = { get ( name ) { throw new Error ( "Not implemented" ) ; } } ; } ) ; it ( "can create a data store runtime" , ( ) => { let failed = false ; let dataStoreRuntime ; try { dataStoreRuntime = loadRuntime ( dataStoreContext , sharedObjectRegistry ) ; } catch ( error ) { failed = true ; } assert . strictEqual ( failed , false , "Data store runtime creation failed" ) ; assert . strictEqual ( dataStoreRuntime ?. id , dataStoreContext . id , "Data store runtime's id in incorrect" ) ; } ) ; it ( "can summarize an empty data store runtime" , async ( ) => { const dataStoreRuntime = loadRuntime ( dataStoreContext , sharedObjectRegistry ) ; const summarizeResult = await dataStoreRuntime . summarize ( true , false ) ; assert ( summarizeResult . summary . type === SummaryType . Tree , "Data store runtime did not return a summary tree" ) ; assert ( Object . keys ( summarizeResult . summary . tree ) . length === 0 , "The summary should be empty" ) ; } ) ; it ( "can get GC data of an empty data store runtime" , async ( ) => { const expectedGCData = { gcNodes : { "/" : [ ] } } ; const dataStoreRuntime = loadRuntime ( dataStoreContext , sharedObjectRegistry ) ; const gcData = await dataStoreRuntime . getGCData ( ) ; assert . deepStrictEqual ( gcData , expectedGCData , "The GC data is incorrect" ) ; } ) ; } ) ;