import { IContainerContext , IRuntime } from "@fluidframework/container-definitions" ; import { IContainerRuntime } from "@fluidframework/container-runtime-definitions" ; import Sinon from "sinon" ; import { RuntimeFactoryHelper } from "../runtimeFactoryHelper" ; class TestRuntimeFactoryHelper extends RuntimeFactoryHelper { constructor ( private readonly runtime ) { super ( ) ; } public async preInitialize ( _context , _existing ) { return this . runtime ; } } describe ( "RuntimeFactoryHelper" , ( ) => { const sandbox = Sinon . createSandbox ( ) ; const context = { } ; const runtime = { } ; let helper ; let unit ; beforeEach ( ( ) => { helper = new TestRuntimeFactoryHelper ( runtime as IRuntime & IContainerRuntime ) ; unit = sandbox . mock ( helper ) ; unit . expects ( "preInitialize" ) . once ( ) ; unit . expects ( "hasInitialized" ) . once ( ) ; } ) ; afterEach ( ( ) => { sandbox . restore ( ) ; } ) ; it ( "Instantiate when existing flag is `true`" , async ( ) => { unit . expects ( "instantiateFirstTime" ) . never ( ) ; unit . expects ( "instantiateFromExisting" ) . once ( ) ; await helper . instantiateRuntime ( context as IContainerContext , true ) ; unit . verify ( ) ; } ) ; it ( "Instantiate when existing flag is `false`" , async ( ) => { unit . expects ( "instantiateFirstTime" ) . once ( ) ; unit . expects ( "instantiateFromExisting" ) . never ( ) ; await helper . instantiateRuntime ( context as IContainerContext , false ) ; unit . verify ( ) ; } ) ; it ( "Instantiate when existing flag is unset" , async ( ) => { unit . expects ( "instantiateFirstTime" ) . once ( ) ; unit . expects ( "instantiateFromExisting" ) . never ( ) ; await helper . instantiateRuntime ( context as IContainerContext ) ; unit . verify ( ) ; } ) ; it ( "Instantiate when existing flag is unset and context is existing" , async ( ) => { const existingContext = { existing : true } ; unit . expects ( "instantiateFirstTime" ) . never ( ) ; unit . expects ( "instantiateFromExisting" ) . once ( ) ; await helper . instantiateRuntime ( existingContext as IContainerContext ) ; unit . verify ( ) ; } ) ; it ( "Instantiate when existing flag takes precedence over context" , async ( ) => { const existingContext = { existing : true } ; unit . expects ( "instantiateFirstTime" ) . once ( ) ; unit . expects ( "instantiateFromExisting" ) . never ( ) ; await helper . instantiateRuntime ( existingContext as IContainerContext , false ) ; unit . verify ( ) ; } ) ; } ) ;