@fluidframework/test-utils 2.0.0-internal.3.0.5 → 2.0.0-internal.3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/.eslintrc.js +8 -10
  2. package/README.md +41 -11
  3. package/api-extractor.json +2 -2
  4. package/dist/DriverWrappers.d.ts.map +1 -1
  5. package/dist/DriverWrappers.js.map +1 -1
  6. package/dist/TestConfigs.d.ts.map +1 -1
  7. package/dist/TestConfigs.js +3 -2
  8. package/dist/TestConfigs.js.map +1 -1
  9. package/dist/TestSummaryUtils.d.ts +1 -1
  10. package/dist/TestSummaryUtils.d.ts.map +1 -1
  11. package/dist/TestSummaryUtils.js +8 -6
  12. package/dist/TestSummaryUtils.js.map +1 -1
  13. package/dist/containerUtils.d.ts.map +1 -1
  14. package/dist/containerUtils.js +3 -1
  15. package/dist/containerUtils.js.map +1 -1
  16. package/dist/index.d.ts +3 -3
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js.map +1 -1
  19. package/dist/interfaces.d.ts.map +1 -1
  20. package/dist/interfaces.js.map +1 -1
  21. package/dist/loaderContainerTracker.d.ts.map +1 -1
  22. package/dist/loaderContainerTracker.js +37 -27
  23. package/dist/loaderContainerTracker.js.map +1 -1
  24. package/dist/localCodeLoader.d.ts.map +1 -1
  25. package/dist/localCodeLoader.js.map +1 -1
  26. package/dist/localLoader.d.ts.map +1 -1
  27. package/dist/localLoader.js.map +1 -1
  28. package/dist/packageVersion.d.ts +1 -1
  29. package/dist/packageVersion.js +1 -1
  30. package/dist/packageVersion.js.map +1 -1
  31. package/dist/retry.d.ts.map +1 -1
  32. package/dist/retry.js.map +1 -1
  33. package/dist/testContainerRuntimeFactory.d.ts.map +1 -1
  34. package/dist/testContainerRuntimeFactory.js +2 -1
  35. package/dist/testContainerRuntimeFactory.js.map +1 -1
  36. package/dist/testFluidObject.d.ts.map +1 -1
  37. package/dist/testFluidObject.js +7 -3
  38. package/dist/testFluidObject.js.map +1 -1
  39. package/dist/testObjectProvider.d.ts +4 -1
  40. package/dist/testObjectProvider.d.ts.map +1 -1
  41. package/dist/testObjectProvider.js +28 -11
  42. package/dist/testObjectProvider.js.map +1 -1
  43. package/dist/timeoutUtils.d.ts.map +1 -1
  44. package/dist/timeoutUtils.js +4 -3
  45. package/dist/timeoutUtils.js.map +1 -1
  46. package/package.json +121 -119
  47. package/prettier.config.cjs +1 -1
  48. package/src/DriverWrappers.ts +40 -37
  49. package/src/TestConfigs.ts +9 -7
  50. package/src/TestSummaryUtils.ts +120 -115
  51. package/src/containerUtils.ts +18 -16
  52. package/src/index.ts +27 -23
  53. package/src/interfaces.ts +10 -7
  54. package/src/loaderContainerTracker.ts +627 -565
  55. package/src/localCodeLoader.ts +85 -77
  56. package/src/localLoader.ts +24 -24
  57. package/src/packageVersion.ts +1 -1
  58. package/src/retry.ts +31 -25
  59. package/src/testContainerRuntimeFactory.ts +59 -56
  60. package/src/testFluidObject.ts +168 -152
  61. package/src/testObjectProvider.ts +445 -384
  62. package/src/timeoutUtils.ts +174 -154
  63. package/tsconfig.json +9 -16
@@ -5,19 +5,23 @@
5
5
 
6
6
  import { defaultFluidObjectRequestHandler } from "@fluidframework/aqueduct";
7
7
  import {
8
- IRequest,
9
- IResponse,
10
- IFluidHandle,
11
- IFluidRouter,
12
- FluidObject,
13
- IProvideFluidRouter,
8
+ IRequest,
9
+ IResponse,
10
+ IFluidHandle,
11
+ IFluidRouter,
12
+ FluidObject,
13
+ IProvideFluidRouter,
14
14
  } from "@fluidframework/core-interfaces";
15
- import { FluidObjectHandle, FluidDataStoreRuntime, mixinRequestHandler } from "@fluidframework/datastore";
15
+ import {
16
+ FluidObjectHandle,
17
+ FluidDataStoreRuntime,
18
+ mixinRequestHandler,
19
+ } from "@fluidframework/datastore";
16
20
  import { SharedMap, ISharedMap } from "@fluidframework/map";
17
21
  import {
18
- IFluidDataStoreContext,
19
- IFluidDataStoreFactory,
20
- IFluidDataStoreChannel,
22
+ IFluidDataStoreContext,
23
+ IFluidDataStoreFactory,
24
+ IFluidDataStoreChannel,
21
25
  } from "@fluidframework/runtime-definitions";
22
26
  import { IFluidDataStoreRuntime, IChannelFactory } from "@fluidframework/datastore-definitions";
23
27
  import { assert } from "@fluidframework/common-utils";
@@ -29,89 +33,91 @@ import { ITestFluidObject } from "./interfaces";
29
33
  * It exposes the IFluidDataStoreContext and IFluidDataStoreRuntime.
30
34
  */
31
35
  export class TestFluidObject implements ITestFluidObject, IFluidRouter {
32
- public static async load(
33
- runtime: IFluidDataStoreRuntime,
34
- channel: IFluidDataStoreChannel,
35
- context: IFluidDataStoreContext,
36
- factoryEntries: Map<string, IChannelFactory>,
37
- existing: boolean,
38
- ) {
39
- const fluidObject = new TestFluidObject(runtime, channel, context, factoryEntries);
40
- await fluidObject.initialize(existing);
41
-
42
- return fluidObject;
43
- }
44
-
45
- public get ITestFluidObject() {
46
- return this;
47
- }
48
-
49
- public get IFluidLoadable() {
50
- return this;
51
- }
52
-
53
- public get IFluidRouter() {
54
- return this;
55
- }
56
-
57
- public get handle(): IFluidHandle<this> { return this.innerHandle; }
58
-
59
- public root!: ISharedMap;
60
- private readonly innerHandle: IFluidHandle<this>;
61
-
62
- /**
63
- * Creates a new TestFluidObject.
64
- * @param runtime - The data store runtime.
65
- * @param context - The data store context.
66
- * @param factoryEntries - A list of id to IChannelFactory mapping. For each item in the list,
67
- * a shared object is created which can be retrieved by calling getSharedObject() with the id;
68
- */
69
- constructor(
70
- public readonly runtime: IFluidDataStoreRuntime,
71
- public readonly channel: IFluidDataStoreChannel,
72
- public readonly context: IFluidDataStoreContext,
73
- private readonly factoryEntriesMap: Map<string, IChannelFactory>,
74
- ) {
75
- this.innerHandle = new FluidObjectHandle(this, "", runtime.objectsRoutingContext);
76
- }
77
-
78
- /**
79
- * Retrieves a shared object with the given id.
80
- * @param id - The id of the shared object to retrieve.
81
- */
82
- public async getSharedObject<T = any>(id: string): Promise<T> {
83
- if (this.factoryEntriesMap === undefined) {
84
- throw new Error("Shared objects were not provided during creation.");
85
- }
86
-
87
- for (const key of this.factoryEntriesMap.keys()) {
88
- if (key === id) {
89
- const handle = this.root.get<IFluidHandle>(id);
90
- return handle?.get() as unknown as T;
91
- }
92
- }
93
-
94
- throw new Error(`Shared object with id ${id} not found.`);
95
- }
96
-
97
- public async request(request: IRequest): Promise<IResponse> {
98
- return defaultFluidObjectRequestHandler(this, request);
99
- }
100
-
101
- private async initialize(existing: boolean) {
102
- if (!existing) {
103
- this.root = SharedMap.create(this.runtime, "root");
104
-
105
- this.factoryEntriesMap.forEach((sharedObjectFactory: IChannelFactory, key: string) => {
106
- const sharedObject = this.runtime.createChannel(key, sharedObjectFactory.type);
107
- this.root.set(key, sharedObject.handle);
108
- });
109
-
110
- this.root.bindToContext();
111
- }
112
-
113
- this.root = await this.runtime.getChannel("root") as ISharedMap;
114
- }
36
+ public static async load(
37
+ runtime: IFluidDataStoreRuntime,
38
+ channel: IFluidDataStoreChannel,
39
+ context: IFluidDataStoreContext,
40
+ factoryEntries: Map<string, IChannelFactory>,
41
+ existing: boolean,
42
+ ) {
43
+ const fluidObject = new TestFluidObject(runtime, channel, context, factoryEntries);
44
+ await fluidObject.initialize(existing);
45
+
46
+ return fluidObject;
47
+ }
48
+
49
+ public get ITestFluidObject() {
50
+ return this;
51
+ }
52
+
53
+ public get IFluidLoadable() {
54
+ return this;
55
+ }
56
+
57
+ public get IFluidRouter() {
58
+ return this;
59
+ }
60
+
61
+ public get handle(): IFluidHandle<this> {
62
+ return this.innerHandle;
63
+ }
64
+
65
+ public root!: ISharedMap;
66
+ private readonly innerHandle: IFluidHandle<this>;
67
+
68
+ /**
69
+ * Creates a new TestFluidObject.
70
+ * @param runtime - The data store runtime.
71
+ * @param context - The data store context.
72
+ * @param factoryEntries - A list of id to IChannelFactory mapping. For each item in the list,
73
+ * a shared object is created which can be retrieved by calling getSharedObject() with the id;
74
+ */
75
+ constructor(
76
+ public readonly runtime: IFluidDataStoreRuntime,
77
+ public readonly channel: IFluidDataStoreChannel,
78
+ public readonly context: IFluidDataStoreContext,
79
+ private readonly factoryEntriesMap: Map<string, IChannelFactory>,
80
+ ) {
81
+ this.innerHandle = new FluidObjectHandle(this, "", runtime.objectsRoutingContext);
82
+ }
83
+
84
+ /**
85
+ * Retrieves a shared object with the given id.
86
+ * @param id - The id of the shared object to retrieve.
87
+ */
88
+ public async getSharedObject<T = any>(id: string): Promise<T> {
89
+ if (this.factoryEntriesMap === undefined) {
90
+ throw new Error("Shared objects were not provided during creation.");
91
+ }
92
+
93
+ for (const key of this.factoryEntriesMap.keys()) {
94
+ if (key === id) {
95
+ const handle = this.root.get<IFluidHandle>(id);
96
+ return handle?.get() as unknown as T;
97
+ }
98
+ }
99
+
100
+ throw new Error(`Shared object with id ${id} not found.`);
101
+ }
102
+
103
+ public async request(request: IRequest): Promise<IResponse> {
104
+ return defaultFluidObjectRequestHandler(this, request);
105
+ }
106
+
107
+ private async initialize(existing: boolean) {
108
+ if (!existing) {
109
+ this.root = SharedMap.create(this.runtime, "root");
110
+
111
+ this.factoryEntriesMap.forEach((sharedObjectFactory: IChannelFactory, key: string) => {
112
+ const sharedObject = this.runtime.createChannel(key, sharedObjectFactory.type);
113
+ this.root.set(key, sharedObject.handle);
114
+ });
115
+
116
+ this.root.bindToContext();
117
+ }
118
+
119
+ this.root = (await this.runtime.getChannel("root")) as ISharedMap;
120
+ }
115
121
  }
116
122
 
117
123
  export type ChannelFactoryRegistry = Iterable<[string | undefined, IChannelFactory]>;
@@ -141,63 +147,73 @@ export type ChannelFactoryRegistry = Iterable<[string | undefined, IChannelFacto
141
147
  * ```
142
148
  */
143
149
  export class TestFluidObjectFactory implements IFluidDataStoreFactory {
144
- public get IFluidDataStoreFactory() { return this; }
145
-
146
- /**
147
- * Creates a new TestFluidObjectFactory.
148
- * @param factoryEntries - A list of id to IChannelFactory mapping. It creates a data store runtime with each
149
- * IChannelFactory. Entries with string ids are passed to the Fluid object so that it can create a shared object
150
- * for it.
151
- */
152
- constructor(private readonly factoryEntries: ChannelFactoryRegistry,
153
- public readonly type = "TestFluidObjectFactory") { }
154
-
155
- public async instantiateDataStore(
156
- context: IFluidDataStoreContext,
157
- existing: boolean,
158
- ): Promise<FluidDataStoreRuntime> {
159
- const dataTypes = new Map<string, IChannelFactory>();
160
-
161
- // Add SharedMap's factory which will be used to create the root map.
162
- const sharedMapFactory = SharedMap.getFactory();
163
- dataTypes.set(sharedMapFactory.type, sharedMapFactory);
164
-
165
- // Add the object factories to the list to be sent to data store runtime.
166
- for (const entry of this.factoryEntries) {
167
- const factory = entry[1];
168
- dataTypes.set(factory.type, factory);
169
- }
170
-
171
- // Create a map from the factory entries with entries that don't have the id as undefined. This will be
172
- // passed to the Fluid object.
173
- const factoryEntriesMapForObject = new Map<string, IChannelFactory>();
174
- for (const entry of this.factoryEntries) {
175
- const id = entry[0];
176
- if (id !== undefined) {
177
- factoryEntriesMapForObject.set(id, entry[1]);
178
- }
179
- }
180
-
181
- const runtimeClass = mixinRequestHandler(
182
- async (request: IRequest, rt: FluidDataStoreRuntime) => {
183
- const maybeRouter: FluidObject<IProvideFluidRouter> | undefined
184
- = await rt.entryPoint?.get();
185
- assert(maybeRouter?.IFluidRouter !== undefined, "entryPoint should have been initialized by now");
186
- return maybeRouter.IFluidRouter.request(request);
187
- });
188
-
189
- return new runtimeClass(
190
- context,
191
- dataTypes,
192
- existing,
193
- async (dataStoreRuntime: IFluidDataStoreRuntime) => TestFluidObject.load(
194
- dataStoreRuntime,
195
- // This works because 'runtime' is an instance of runtimeClass (which is a FluidDataStoreRuntime and
196
- // thus implements IFluidDataStoreChannel) which passes itself as the parameter to this function.
197
- dataStoreRuntime as FluidDataStoreRuntime,
198
- context,
199
- factoryEntriesMapForObject,
200
- existing,
201
- ));
202
- }
150
+ public get IFluidDataStoreFactory() {
151
+ return this;
152
+ }
153
+
154
+ /**
155
+ * Creates a new TestFluidObjectFactory.
156
+ * @param factoryEntries - A list of id to IChannelFactory mapping. It creates a data store runtime with each
157
+ * IChannelFactory. Entries with string ids are passed to the Fluid object so that it can create a shared object
158
+ * for it.
159
+ */
160
+ constructor(
161
+ private readonly factoryEntries: ChannelFactoryRegistry,
162
+ public readonly type = "TestFluidObjectFactory",
163
+ ) {}
164
+
165
+ public async instantiateDataStore(
166
+ context: IFluidDataStoreContext,
167
+ existing: boolean,
168
+ ): Promise<FluidDataStoreRuntime> {
169
+ const dataTypes = new Map<string, IChannelFactory>();
170
+
171
+ // Add SharedMap's factory which will be used to create the root map.
172
+ const sharedMapFactory = SharedMap.getFactory();
173
+ dataTypes.set(sharedMapFactory.type, sharedMapFactory);
174
+
175
+ // Add the object factories to the list to be sent to data store runtime.
176
+ for (const entry of this.factoryEntries) {
177
+ const factory = entry[1];
178
+ dataTypes.set(factory.type, factory);
179
+ }
180
+
181
+ // Create a map from the factory entries with entries that don't have the id as undefined. This will be
182
+ // passed to the Fluid object.
183
+ const factoryEntriesMapForObject = new Map<string, IChannelFactory>();
184
+ for (const entry of this.factoryEntries) {
185
+ const id = entry[0];
186
+ if (id !== undefined) {
187
+ factoryEntriesMapForObject.set(id, entry[1]);
188
+ }
189
+ }
190
+
191
+ const runtimeClass = mixinRequestHandler(
192
+ async (request: IRequest, rt: FluidDataStoreRuntime) => {
193
+ const maybeRouter: FluidObject<IProvideFluidRouter> | undefined =
194
+ await rt.entryPoint?.get();
195
+ assert(
196
+ maybeRouter?.IFluidRouter !== undefined,
197
+ "entryPoint should have been initialized by now",
198
+ );
199
+ return maybeRouter.IFluidRouter.request(request);
200
+ },
201
+ );
202
+
203
+ return new runtimeClass(
204
+ context,
205
+ dataTypes,
206
+ existing,
207
+ async (dataStoreRuntime: IFluidDataStoreRuntime) =>
208
+ TestFluidObject.load(
209
+ dataStoreRuntime,
210
+ // This works because 'runtime' is an instance of runtimeClass (which is a FluidDataStoreRuntime and
211
+ // thus implements IFluidDataStoreChannel) which passes itself as the parameter to this function.
212
+ dataStoreRuntime as FluidDataStoreRuntime,
213
+ context,
214
+ factoryEntriesMapForObject,
215
+ existing,
216
+ ),
217
+ );
218
+ }
203
219
  }