Skip to main content
Version: v1

@fluidframework/test-utils Package

Interfaces​

InterfaceDescription
IOpProcessingController
IProvideTestFluidObject
ITestContainerConfig
ITestFluidObject
ITestObjectProvider
TimeoutWithError
TimeoutWithValue

Classes​

ClassDescription
EventAndErrorTrackingLoggerThis class tracks events. It allows specifying expected events, which will be looked for in order. It also tracks all unexpected errors. At any point you call reportAndClearTrackedEvents which will provide all unexpected errors, and any expected events that have not occurred.
LoaderContainerTracker
LocalCodeLoaderA simple code loader that caches a mapping of package name to a Fluid entry point. On load, it retrieves the entry point matching the package name in the given code details.
TestFluidObjectA test Fluid object that will create a shared object for each key-value pair in the factoryEntries passed to load. The shared objects can be retrieved by passing the key of the entry to getSharedObject. It exposes the IFluidDataStoreContext and IFluidDataStoreRuntime.
TestFluidObjectFactory

Creates a factory for a TestFluidObject with the given object factory entries. It creates a data store runtime with the object factories in the entry list. All the entries with an id other than undefined are passed to the Fluid object so that it can create a shared object for each.

For example, the following will create a Fluid object that creates and loads a SharedString and SharedDirectory. It will add SparseMatrix to the data store's factory so that it can be created later. new TestFluidObjectFactory([ [ "sharedString", SharedString.getFactory() ], [ "sharedDirectory", SharedDirectory.getFactory() ], [ undefined, SparseMatrix.getFactory() ], ]);

The SharedString and SharedDirectory can be retrieved via getSharedObject() on the TestFluidObject as follows: sharedString = testFluidObject.getSharedObject("sharedString"); sharedDir = testFluidObject.getSharedObject("sharedDirectory");

TestObjectProviderShared base class for test object provider. Contain code for loader and container creation and loading

Enumerations​

EnumDescription
DataObjectFactoryType

Types​

TypeAliasDescription
ChannelFactoryRegistry
fluidEntryPoint
SupportedExportInterfaces

Functions​

FunctionReturn TypeDescription
createAndAttachContainer(source, loader, attachRequest)Promise<IContainer>Creates a detached Container and attaches it.
createLoader(packageEntries, documentServiceFactory, urlResolver, logger, options)IHostLoaderCreates a loader with the given package entries and driver.
createSummarizer(provider, container, summaryVersion, gcOptions)Promise<ISummarizer>
createSummarizerFromFactory(provider, container, dataStoreFactory, summaryVersion, containerRuntimeFactoryType)Promise<ISummarizer>
getUnexpectedLogErrorException(logger, prefix)Error | undefined
summarizeNow(summarizer, reason)Promise<{ summaryTree: import("@fluidframework/protocol-definitions").ISummaryTree; summaryVersion: string; }>
timeoutAwait(promise, timeoutOptions)Promise<T>
timeoutPromise(executor, timeoutOptions)Promise<T>
waitForContainerConnection(container)Promise<void>
wrapDocumentService(innerDocService, uploadSummaryCb)IDocumentServiceWraps the given IDocumentService to override the connectToStorage method. The intent is to plumb the uploadSummaryCb to the IDocumentStorageService so that it is called whenever a summary is uploaded by the client. The document storage service that is created in connectToStorage is wrapped by calling wrapDocumentStorageService to pass in the uploadSummaryCb.
wrapDocumentServiceFactory(innerDocServiceFactory, uploadSummaryCb)IDocumentServiceFactoryWraps the given IDocumentServiceFactory to override the createDocumentService method. The intent is to plumb the uploadSummaryCb all the way to the IDocumentStorageService so that it is called whenever a summary is uploaded by the client. The document service that is created in createDocumentService is wrapped by calling wrapDocumentService to pass in the uploadSummaryCb.
wrapDocumentStorageService(innerDocStorageService, uploadSummaryCb)IDocumentStorageServiceWraps the given IDocumentStorageService to override the uploadSummaryWithContext method. It calls the uploadSummaryCb whenever a summary is uploaded by the client. The summary context can be updated in the callback before it is uploaded to the server.

Variables​

VariableTypeDescription
createDocumentId() => string
createTestContainerRuntimeFactory(containerRuntimeCtor: typeof ContainerRuntime) => { new (type: string, dataStoreFactory: IFluidDataStoreFactory, runtimeOptions?: IContainerRuntimeOptions, requestHandlers?: RuntimeRequestHandler[]): { type: string; dataStoreFactory: IFluidDataStoreFactory; runtimeOptions: IContainerRuntimeOptions; requestHandlers: RuntimeRequestHandler[]; instantiateFirstTime(runtime: ContainerRuntime): Promise<void>; instantiateFromExisting(runtime: ContainerRuntime): Promise<void>; preInitialize(context: IContainerContext, existing: boolean): Promise<IRuntime & IContainerRuntime>; readonly IRuntimeFactory: any; instantiateRuntime(context: IContainerContext, existing?: boolean | undefined): Promise<IRuntime>; hasInitialized(_runtime: IContainerRuntime): Promise<void>; }; }Create a container runtime factory class that allows you to set runtime options
defaultTimeoutDurationMs
mockConfigProvider(settings?: Record<string, ConfigTypes>) => IConfigProviderBase
retryWithEventualValue<T>(callback: () => Promise<T>, check: (value: T) => boolean, defaultValue: T, maxTries?: number, backOffMs?: number) => Promise<T>Simple retry mechanism with linear back off to call a function which may eventually return an accepted value.
TestContainerRuntimeFactory{ new (type: string, dataStoreFactory: IFluidDataStoreFactory, runtimeOptions?: IContainerRuntimeOptions, requestHandlers?: RuntimeRequestHandler[]): { type: string; dataStoreFactory: IFluidDataStoreFactory; runtimeOptions: IContainerRuntimeOptions; requestHandlers: RuntimeRequestHandler[]; instantiateFirstTime(runtime: ContainerRuntime): Promise<void>; instantiateFromExisting(runtime: ContainerRuntime): Promise<void>; preInitialize(context: IContainerContext, existing: boolean): Promise<IRuntime & IContainerRuntime>; readonly IRuntimeFactory: any; instantiateRuntime(context: IContainerContext, existing?: boolean | undefined): Promise<IRuntime>; hasInitialized(_runtime: IContainerRuntime): Promise<void>; }; }A container runtime factory that allows you to set runtime options

Function Details​

createAndAttachContainer​

Creates a detached Container and attaches it.

Signature​

export declare function createAndAttachContainer(source: IFluidCodeDetails, loader: IHostLoader, attachRequest: IRequest): Promise<IContainer>;

Parameters​

ParameterTypeDescription
sourceIFluidCodeDetailsThe code details used to create the Container.
loaderIHostLoaderThe loader to use to initialize the container.
attachRequestIRequestThe request to create new from.

Returns​

Return type: Promise<IContainer>

createLoader​

Creates a loader with the given package entries and driver.

Signature​

export declare function createLoader(packageEntries: Iterable<[IFluidCodeDetails, fluidEntryPoint]>, documentServiceFactory: IDocumentServiceFactory, urlResolver: IUrlResolver, logger?: ITelemetryBaseLogger, options?: ILoaderOptions): IHostLoader;

Parameters​

ParameterModifiersTypeDescription
packageEntriesIterable<[IFluidCodeDetails, fluidEntryPoint]>A list of code details to Fluid entry points.
documentServiceFactoryIDocumentServiceFactorythe driver factory to use
urlResolverIUrlResolverthe url resolver to use
loggeroptionalITelemetryBaseLogger
optionsoptionalILoaderOptionsloader options

Returns​

Return type: IHostLoader

createSummarizer​

Signature​

export declare function createSummarizer(provider: ITestObjectProvider, container: IContainer, summaryVersion?: string, gcOptions?: IGCRuntimeOptions): Promise<ISummarizer>;

Parameters​

ParameterModifiersTypeDescription
providerITestObjectProvider
containerIContainer
summaryVersionoptionalstring
gcOptionsoptionalIGCRuntimeOptions

Returns​

Return type: Promise<ISummarizer>

createSummarizerFromFactory​

Signature​

export declare function createSummarizerFromFactory(provider: ITestObjectProvider, container: IContainer, dataStoreFactory: IFluidDataStoreFactory, summaryVersion?: string, containerRuntimeFactoryType?: typeof ContainerRuntimeFactoryWithDefaultDataStore): Promise<ISummarizer>;

Parameters​

ParameterModifiersTypeDescription
providerITestObjectProvider
containerIContainer
dataStoreFactoryIFluidDataStoreFactory
summaryVersionoptionalstring
containerRuntimeFactoryTypeoptionaltypeof ContainerRuntimeFactoryWithDefaultDataStore

Returns​

Return type: Promise<ISummarizer>

getUnexpectedLogErrorException​

Signature​

export declare function getUnexpectedLogErrorException(logger: EventAndErrorTrackingLogger | undefined, prefix?: string): Error | undefined;

Parameters​

ParameterModifiersTypeDescription
loggerEventAndErrorTrackingLogger | undefined
prefixoptionalstring

Returns​

Return type: Error | undefined

summarizeNow​

Signature​

export declare function summarizeNow(summarizer: ISummarizer, reason?: string): Promise<{
summaryTree: import("@fluidframework/protocol-definitions").ISummaryTree;
summaryVersion: string;
}>;

Parameters​

ParameterModifiersTypeDescription
summarizerISummarizer
reasonoptionalstring

Returns​

Return type: Promise<{ summaryTree: import("@fluidframework/protocol-definitions").ISummaryTree; summaryVersion: string; }>

timeoutAwait​

Signature​

export declare function timeoutAwait<T = void>(promise: PromiseLike<T>, timeoutOptions?: TimeoutWithError | TimeoutWithValue<T>): Promise<T>;
Type Parameters​
ParameterDefaultDescription
Tvoid

Parameters​

ParameterModifiersTypeDescription
promisePromiseLike<T>
timeoutOptionsoptionalTimeoutWithError | TimeoutWithValue<T>

Returns​

Return type: Promise<T>

timeoutPromise​

Signature​

export declare function timeoutPromise<T = void>(executor: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void, timeoutOptions?: TimeoutWithError | TimeoutWithValue<T>): Promise<T>;
Type Parameters​
ParameterDefaultDescription
Tvoid

Parameters​

ParameterModifiersTypeDescription
executor(resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void
timeoutOptionsoptionalTimeoutWithError | TimeoutWithValue<T>

Returns​

Return type: Promise<T>

waitForContainerConnection​

Signature​

export declare function waitForContainerConnection(container: IContainer): Promise<void>;

Parameters​

ParameterTypeDescription
containerIContainer

Returns​

Return type: Promise<void>

wrapDocumentService​

Wraps the given IDocumentService to override the connectToStorage method. The intent is to plumb the uploadSummaryCb to the IDocumentStorageService so that it is called whenever a summary is uploaded by the client. The document storage service that is created in connectToStorage is wrapped by calling wrapDocumentStorageService to pass in the uploadSummaryCb.

Signature​

export declare function wrapDocumentService(innerDocService: IDocumentService, uploadSummaryCb: (summaryTree: ISummaryTree, context: ISummaryContext) => ISummaryContext): IDocumentService;

Parameters​

ParameterTypeDescription
innerDocServiceIDocumentService
uploadSummaryCb(summaryTree: ISummaryTree, context: ISummaryContext) => ISummaryContext

Returns​

Return type: IDocumentService

wrapDocumentServiceFactory​

Wraps the given IDocumentServiceFactory to override the createDocumentService method. The intent is to plumb the uploadSummaryCb all the way to the IDocumentStorageService so that it is called whenever a summary is uploaded by the client. The document service that is created in createDocumentService is wrapped by calling wrapDocumentService to pass in the uploadSummaryCb.

Signature​

export declare function wrapDocumentServiceFactory(innerDocServiceFactory: IDocumentServiceFactory, uploadSummaryCb: (summaryTree: ISummaryTree, context: ISummaryContext) => ISummaryContext): IDocumentServiceFactory;

Parameters​

ParameterTypeDescription
innerDocServiceFactoryIDocumentServiceFactory
uploadSummaryCb(summaryTree: ISummaryTree, context: ISummaryContext) => ISummaryContext

Returns​

Return type: IDocumentServiceFactory

wrapDocumentStorageService​

Wraps the given IDocumentStorageService to override the uploadSummaryWithContext method. It calls the uploadSummaryCb whenever a summary is uploaded by the client. The summary context can be updated in the callback before it is uploaded to the server.

Signature​

export declare function wrapDocumentStorageService(innerDocStorageService: IDocumentStorageService, uploadSummaryCb: (summaryTree: ISummaryTree, context: ISummaryContext) => ISummaryContext): IDocumentStorageService;

Parameters​

ParameterTypeDescription
innerDocStorageServiceIDocumentStorageService
uploadSummaryCb(summaryTree: ISummaryTree, context: ISummaryContext) => ISummaryContext

Returns​

Return type: IDocumentStorageService

Variable Details​

createDocumentId​

Signature​

createDocumentId: () => string

Type: () => string

createTestContainerRuntimeFactory​

Create a container runtime factory class that allows you to set runtime options

Signature​

createTestContainerRuntimeFactory: (containerRuntimeCtor: typeof ContainerRuntime) => {
new (type: string, dataStoreFactory: IFluidDataStoreFactory, runtimeOptions?: IContainerRuntimeOptions, requestHandlers?: RuntimeRequestHandler[]): {
type: string;
dataStoreFactory: IFluidDataStoreFactory;
runtimeOptions: IContainerRuntimeOptions;
requestHandlers: RuntimeRequestHandler[];
instantiateFirstTime(runtime: ContainerRuntime): Promise<void>;
instantiateFromExisting(runtime: ContainerRuntime): Promise<void>;
preInitialize(context: IContainerContext, existing: boolean): Promise<IRuntime & IContainerRuntime>;
readonly IRuntimeFactory: any;
instantiateRuntime(context: IContainerContext, existing?: boolean | undefined): Promise<IRuntime>;
hasInitialized(_runtime: IContainerRuntime): Promise<void>;
};
}

Type: (containerRuntimeCtor: typeof ContainerRuntime) => { new (type: string, dataStoreFactory: IFluidDataStoreFactory, runtimeOptions?: IContainerRuntimeOptions, requestHandlers?: RuntimeRequestHandler[]): { type: string; dataStoreFactory: IFluidDataStoreFactory; runtimeOptions: IContainerRuntimeOptions; requestHandlers: RuntimeRequestHandler[]; instantiateFirstTime(runtime: ContainerRuntime): Promise<void>; instantiateFromExisting(runtime: ContainerRuntime): Promise<void>; preInitialize(context: IContainerContext, existing: boolean): Promise<IRuntime & IContainerRuntime>; readonly IRuntimeFactory: any; instantiateRuntime(context: IContainerContext, existing?: boolean | undefined): Promise<IRuntime>; hasInitialized(_runtime: IContainerRuntime): Promise<void>; }; }

defaultTimeoutDurationMs​

Signature​

defaultTimeoutDurationMs = 250

mockConfigProvider​

Signature​

mockConfigProvider: (settings?: Record<string, ConfigTypes>) => IConfigProviderBase

Type: (settings?: Record<string, ConfigTypes>) => IConfigProviderBase

retryWithEventualValue​

Simple retry mechanism with linear back off to call a function which may eventually return an accepted value.

Signature​

retryWithEventualValue: <T>(callback: () => Promise<T>, check: (value: T) => boolean, defaultValue: T, maxTries?: number, backOffMs?: number) => Promise<T>

Type: <T>(callback: () => Promise<T>, check: (value: T) => boolean, defaultValue: T, maxTries?: number, backOffMs?: number) => Promise<T>

TestContainerRuntimeFactory​

A container runtime factory that allows you to set runtime options

Signature​

TestContainerRuntimeFactory: {
new (type: string, dataStoreFactory: IFluidDataStoreFactory, runtimeOptions?: IContainerRuntimeOptions, requestHandlers?: RuntimeRequestHandler[]): {
type: string;
dataStoreFactory: IFluidDataStoreFactory;
runtimeOptions: IContainerRuntimeOptions;
requestHandlers: RuntimeRequestHandler[];
instantiateFirstTime(runtime: ContainerRuntime): Promise<void>;
instantiateFromExisting(runtime: ContainerRuntime): Promise<void>;
preInitialize(context: IContainerContext, existing: boolean): Promise<IRuntime & IContainerRuntime>;
readonly IRuntimeFactory: any;
instantiateRuntime(context: IContainerContext, existing?: boolean | undefined): Promise<IRuntime>;
hasInitialized(_runtime: IContainerRuntime): Promise<void>;
};
}

Type: { new (type: string, dataStoreFactory: IFluidDataStoreFactory, runtimeOptions?: IContainerRuntimeOptions, requestHandlers?: RuntimeRequestHandler[]): { type: string; dataStoreFactory: IFluidDataStoreFactory; runtimeOptions: IContainerRuntimeOptions; requestHandlers: RuntimeRequestHandler[]; instantiateFirstTime(runtime: ContainerRuntime): Promise<void>; instantiateFromExisting(runtime: ContainerRuntime): Promise<void>; preInitialize(context: IContainerContext, existing: boolean): Promise<IRuntime & IContainerRuntime>; readonly IRuntimeFactory: any; instantiateRuntime(context: IContainerContext, existing?: boolean | undefined): Promise<IRuntime>; hasInitialized(_runtime: IContainerRuntime): Promise<void>; }; }