@fluidframework/test-utils 2.0.0-rc.4.0.5 → 2.0.0-rc.5.0.0

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 (111) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/api-extractor/api-extractor-lint-bundle.json +5 -0
  3. package/api-extractor/api-extractor-lint-legacy.cjs.json +5 -0
  4. package/api-extractor/api-extractor-lint-legacy.esm.json +5 -0
  5. package/api-extractor/api-extractor-lint-public.cjs.json +5 -0
  6. package/api-extractor/api-extractor-lint-public.esm.json +5 -0
  7. package/api-extractor.json +1 -1
  8. package/api-report/test-utils.alpha.api.md +108 -0
  9. package/api-report/test-utils.beta.api.md +61 -0
  10. package/api-report/test-utils.public.api.md +61 -0
  11. package/biome.jsonc +4 -0
  12. package/dist/DriverWrappers.d.ts +1 -1
  13. package/dist/DriverWrappers.d.ts.map +1 -1
  14. package/dist/DriverWrappers.js.map +1 -1
  15. package/dist/TestSummaryUtils.d.ts +1 -1
  16. package/dist/TestSummaryUtils.d.ts.map +1 -1
  17. package/dist/TestSummaryUtils.js +1 -4
  18. package/dist/TestSummaryUtils.js.map +1 -1
  19. package/dist/containerUtils.js.map +1 -1
  20. package/dist/index.d.ts +1 -1
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js.map +1 -1
  23. package/dist/interfaces.d.ts +1 -1
  24. package/dist/interfaces.d.ts.map +1 -1
  25. package/dist/interfaces.js.map +1 -1
  26. package/dist/loaderContainerTracker.d.ts.map +1 -1
  27. package/dist/loaderContainerTracker.js +9 -12
  28. package/dist/loaderContainerTracker.js.map +1 -1
  29. package/dist/localCodeLoader.d.ts.map +1 -1
  30. package/dist/localCodeLoader.js +1 -3
  31. package/dist/localCodeLoader.js.map +1 -1
  32. package/dist/localLoader.d.ts.map +1 -1
  33. package/dist/localLoader.js.map +1 -1
  34. package/dist/packageVersion.d.ts +1 -1
  35. package/dist/packageVersion.js +1 -1
  36. package/dist/packageVersion.js.map +1 -1
  37. package/dist/retry.d.ts.map +1 -1
  38. package/dist/retry.js.map +1 -1
  39. package/dist/testContainerRuntimeFactory.d.ts.map +1 -1
  40. package/dist/testContainerRuntimeFactory.js.map +1 -1
  41. package/dist/testContainerRuntimeFactoryWithDefaultDataStore.d.ts +3 -3
  42. package/dist/testContainerRuntimeFactoryWithDefaultDataStore.d.ts.map +1 -1
  43. package/dist/testContainerRuntimeFactoryWithDefaultDataStore.js.map +1 -1
  44. package/dist/testFluidObject.d.ts +1 -1
  45. package/dist/testFluidObject.d.ts.map +1 -1
  46. package/dist/testFluidObject.js.map +1 -1
  47. package/dist/testObjectProvider.d.ts +1 -1
  48. package/dist/testObjectProvider.d.ts.map +1 -1
  49. package/dist/testObjectProvider.js +7 -7
  50. package/dist/testObjectProvider.js.map +1 -1
  51. package/dist/timeoutUtils.js +1 -3
  52. package/dist/timeoutUtils.js.map +1 -1
  53. package/lib/DriverWrappers.d.ts +1 -1
  54. package/lib/DriverWrappers.d.ts.map +1 -1
  55. package/lib/DriverWrappers.js.map +1 -1
  56. package/lib/TestSummaryUtils.d.ts +1 -1
  57. package/lib/TestSummaryUtils.d.ts.map +1 -1
  58. package/lib/TestSummaryUtils.js +1 -4
  59. package/lib/TestSummaryUtils.js.map +1 -1
  60. package/lib/containerUtils.js.map +1 -1
  61. package/lib/index.d.ts +1 -1
  62. package/lib/index.d.ts.map +1 -1
  63. package/lib/index.js +1 -1
  64. package/lib/index.js.map +1 -1
  65. package/lib/interfaces.d.ts +1 -1
  66. package/lib/interfaces.d.ts.map +1 -1
  67. package/lib/interfaces.js.map +1 -1
  68. package/lib/loaderContainerTracker.d.ts.map +1 -1
  69. package/lib/loaderContainerTracker.js +3 -6
  70. package/lib/loaderContainerTracker.js.map +1 -1
  71. package/lib/localCodeLoader.d.ts.map +1 -1
  72. package/lib/localCodeLoader.js +1 -3
  73. package/lib/localCodeLoader.js.map +1 -1
  74. package/lib/localLoader.d.ts.map +1 -1
  75. package/lib/localLoader.js.map +1 -1
  76. package/lib/packageVersion.d.ts +1 -1
  77. package/lib/packageVersion.js +1 -1
  78. package/lib/packageVersion.js.map +1 -1
  79. package/lib/retry.d.ts.map +1 -1
  80. package/lib/retry.js.map +1 -1
  81. package/lib/testContainerRuntimeFactory.d.ts.map +1 -1
  82. package/lib/testContainerRuntimeFactory.js.map +1 -1
  83. package/lib/testContainerRuntimeFactoryWithDefaultDataStore.d.ts +3 -3
  84. package/lib/testContainerRuntimeFactoryWithDefaultDataStore.d.ts.map +1 -1
  85. package/lib/testContainerRuntimeFactoryWithDefaultDataStore.js.map +1 -1
  86. package/lib/testFluidObject.d.ts +1 -1
  87. package/lib/testFluidObject.d.ts.map +1 -1
  88. package/lib/testFluidObject.js.map +1 -1
  89. package/lib/testObjectProvider.d.ts +1 -1
  90. package/lib/testObjectProvider.d.ts.map +1 -1
  91. package/lib/testObjectProvider.js +2 -2
  92. package/lib/testObjectProvider.js.map +1 -1
  93. package/lib/timeoutUtils.js +1 -3
  94. package/lib/timeoutUtils.js.map +1 -1
  95. package/lib/tsdoc-metadata.json +1 -1
  96. package/package.json +47 -31
  97. package/src/DriverWrappers.ts +7 -3
  98. package/src/TestSummaryUtils.ts +1 -4
  99. package/src/index.ts +5 -1
  100. package/src/interfaces.ts +1 -1
  101. package/src/loaderContainerTracker.ts +7 -14
  102. package/src/localCodeLoader.ts +1 -3
  103. package/src/localLoader.ts +4 -1
  104. package/src/packageVersion.ts +1 -1
  105. package/src/testContainerRuntimeFactory.ts +4 -14
  106. package/src/testFluidObject.ts +8 -10
  107. package/src/testObjectProvider.ts +9 -3
  108. package/src/timeoutUtils.ts +1 -3
  109. package/tsconfig.json +2 -0
  110. package/tsdoc.json +4 -0
  111. package/api-report/test-utils.api.md +0 -434
@@ -1 +1 @@
1
- {"version":3,"file":"timeoutUtils.js","sourceRoot":"","sources":["../src/timeoutUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,QAA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,CAAC;AACJ,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, Deferred } from \"@fluidframework/core-utils/internal\";\nimport type * as Mocha from \"mocha\";\n\n// @deprecated this value is no longer used\n/**\n * @internal\n */\nexport const defaultTimeoutDurationMs = 250;\n\nconst timeBuffer = 15; // leave 15 ms leeway for finish processing\n\n// TestTimeout class that manages tracking of test timeout. It creates a timer when timeout is in effect,\n// and provides a promise that will be rejected some time (as defined by `timeBuffer`) before the test timeout happens.\n// This will ensure that async awaits in tests do not end up timing out the tests but resolve / reject\n// before that happens.\n// Once rejected, a new TestTimeout object will be create for the timeout.\nclass TestTimeout {\n\tprivate timeout: number = 0;\n\tprivate timer: NodeJS.Timeout | undefined;\n\tprivate readonly deferred: Deferred<void>;\n\tprivate rejected = false;\n\n\tprivate static instance: TestTimeout = new TestTimeout();\n\tpublic static reset(runnable: Mocha.Runnable) {\n\t\tTestTimeout.clear();\n\t\tTestTimeout.instance.resetTimer(runnable);\n\t}\n\n\tpublic static clear() {\n\t\tif (TestTimeout.instance.rejected) {\n\t\t\tTestTimeout.instance = new TestTimeout();\n\t\t} else {\n\t\t\tTestTimeout.instance.clearTimer();\n\t\t}\n\t}\n\n\tpublic static getInstance() {\n\t\treturn TestTimeout.instance;\n\t}\n\n\tpublic async getPromise() {\n\t\treturn this.deferred.promise;\n\t}\n\n\tpublic getTimeout() {\n\t\treturn this.timeout;\n\t}\n\n\tprivate constructor() {\n\t\tthis.deferred = new Deferred();\n\t\t// Ignore rejection for timeout promise if no one is waiting for it.\n\t\tthis.deferred.promise.catch(() => {});\n\t}\n\n\tprivate resetTimer(runnable: Mocha.Runnable) {\n\t\tassert(!this.timer, \"clearTimer should have been called before reset\");\n\t\tassert(!this.deferred.isCompleted, \"can't reset a completed TestTimeout\");\n\n\t\t// Check the test timeout setting\n\t\tconst timeout = runnable.timeout();\n\t\tif (!(Number.isFinite(timeout) && timeout > 0)) {\n\t\t\treturn;\n\t\t}\n\n\t\t// subtract a buffer\n\t\tthis.timeout = Math.max(timeout - timeBuffer, 1);\n\n\t\t// Set up timer to reject near the test timeout.\n\t\tthis.timer = setTimeout(() => {\n\t\t\tthis.deferred.reject(this);\n\t\t\tthis.rejected = true;\n\t\t}, this.timeout);\n\t}\n\tprivate clearTimer() {\n\t\tif (this.timer) {\n\t\t\tclearTimeout(this.timer);\n\t\t\tthis.timer = undefined;\n\t\t}\n\t}\n}\n\n// only register if we are running with mocha-test-setup loaded\nif (globalThis.getMochaModule !== undefined) {\n\t// patching resetTimeout and clearTimeout on the runnable object\n\t// so we can track when test timeout are enforced\n\tconst mochaModule = globalThis.getMochaModule() as typeof Mocha;\n\tconst runnablePrototype = mochaModule.Runnable.prototype;\n\t// eslint-disable-next-line @typescript-eslint/unbound-method\n\tconst oldResetTimeoutFunc = runnablePrototype.resetTimeout;\n\trunnablePrototype.resetTimeout = function (this: Mocha.Runnable) {\n\t\toldResetTimeoutFunc.call(this);\n\t\tTestTimeout.reset(this);\n\t};\n\t// eslint-disable-next-line @typescript-eslint/unbound-method\n\tconst oldClearTimeoutFunc = runnablePrototype.clearTimeout;\n\trunnablePrototype.clearTimeout = function (this: Mocha.Runnable) {\n\t\tTestTimeout.clear();\n\t\toldClearTimeoutFunc.call(this);\n\t};\n}\n\n/**\n * @internal\n */\nexport interface TimeoutWithError {\n\t/**\n\t * Timeout duration in milliseconds, if it is great than 0 and not Infinity\n\t * If it is undefined, then it will use test timeout if we are in side the test function\n\t * Otherwise, there is no timeout\n\t */\n\tdurationMs?: number;\n\treject?: true;\n\terrorMsg?: string;\n}\n/**\n * @internal\n */\nexport interface TimeoutWithValue<T = void> {\n\t/**\n\t * Timeout duration in milliseconds, if it is great than 0 and not Infinity\n\t * If it is undefined, then it will use test timeout if we are in side the test function\n\t * Otherwise, there is no timeout\n\t */\n\tdurationMs?: number;\n\treject: false;\n\tvalue: T;\n}\n\nexport type PromiseExecutor<T = void> = (\n\tresolve: (value: T | PromiseLike<T>) => void,\n\treject: (reason?: any) => void,\n) => void;\n\n/**\n * Wraps the given promise around with promise that will complete after a specific timeout if the original promise does\n * not resolve by then. By default, it uses the mocha test timeout and complete the promise just before that so that\n * tests don't time out because of unpredictable awaits.\n * The timeout can be overridden via timeoutOptions but it's recommended to use the default value.\n * @param promise - The promise to be awaited.\n * @param timeoutOptions - Options that can be used to override the timeout and / or define the behavior\n * when the promise is not fulfilled. For example, instead of rejecting the promise, resolve with a\n * specific value.\n * @returns A new promise that will complete when the given promise resolves or the timeout expires.\n * @internal\n */\nexport async function timeoutAwait<T = void>(\n\tpromise: PromiseLike<T>,\n\ttimeoutOptions: TimeoutWithError | TimeoutWithValue<T> = {},\n): Promise<T> {\n\treturn Promise.race([promise, timeoutPromise<T>(() => {}, timeoutOptions)]);\n}\n\n/**\n * Creates a promise from the given executor that will complete after a specific timeout. By default, it uses the mocha\n * test timeout and complete the promise just before that so that tests don't time out because of unpredictable awaits.\n * The timeout can be overridden via timeoutOptions but it's recommended to use the default value.\n * @param executor - The executor for the promise.\n * @param timeoutOptions - Options that can be used to override the timeout and / or define the behavior when\n * the promise is not fulfilled. For example, instead of rejecting the promise, resolve with a specific value.\n * @returns A new promise that will complete when the given executor resolves or the timeout expires.\n * @internal\n */\nexport async function timeoutPromise<T = void>(\n\texecutor: (\n\t\tresolve: (value: T | PromiseLike<T>) => void,\n\t\treject: (reason?: any) => void,\n\t) => void,\n\ttimeoutOptions: TimeoutWithError | TimeoutWithValue<T> = {},\n): Promise<T> {\n\t// create the timeout error outside the async task, so its callstack includes\n\t// the original call site, this makes it easier to debug\n\tconst err =\n\t\ttimeoutOptions.reject === false\n\t\t\t? undefined\n\t\t\t: new Error(timeoutOptions.errorMsg ?? \"Timed out\");\n\tconst executorPromise = getTimeoutPromise(executor, timeoutOptions, err);\n\n\tconst currentTestTimeout = TestTimeout.getInstance();\n\tif (currentTestTimeout === undefined) {\n\t\treturn executorPromise;\n\t}\n\n\treturn Promise.race([executorPromise, currentTestTimeout.getPromise()]).catch((e) => {\n\t\tif (e === currentTestTimeout) {\n\t\t\tif (timeoutOptions.reject !== false) {\n\t\t\t\t// If the rejection is because of the timeout then\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tconst errorObject = err!;\n\t\t\t\terrorObject.message = `${\n\t\t\t\t\ttimeoutOptions.errorMsg ?? \"Test timed out\"\n\t\t\t\t} (${currentTestTimeout.getTimeout()}ms)`;\n\t\t\t\tthrow errorObject;\n\t\t\t}\n\t\t\treturn timeoutOptions.value;\n\t\t}\n\t\tthrow e;\n\t}) as Promise<T>;\n}\n\n// Create a promise based on the timeout options\nasync function getTimeoutPromise<T = void>(\n\texecutor: (\n\t\tresolve: (value: T | PromiseLike<T>) => void,\n\t\treject: (reason?: any) => void,\n\t) => void,\n\ttimeoutOptions: TimeoutWithError | TimeoutWithValue<T>,\n\terr: Error | undefined,\n) {\n\tconst timeout = timeoutOptions.durationMs ?? 0;\n\tif (timeout <= 0 || !Number.isFinite(timeout)) {\n\t\treturn new Promise(executor);\n\t}\n\n\treturn new Promise<T>((resolve, reject) => {\n\t\tconst timeoutRejections = () => {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tconst errorObject = err!;\n\t\t\terrorObject.message = `${errorObject.message} (${timeout}ms)`;\n\t\t\treject(err);\n\t\t};\n\t\tconst timer = setTimeout(\n\t\t\t() =>\n\t\t\t\ttimeoutOptions.reject === false\n\t\t\t\t\t? resolve(timeoutOptions.value)\n\t\t\t\t\t: timeoutRejections(),\n\t\t\ttimeout,\n\t\t);\n\n\t\texecutor(\n\t\t\t(value) => {\n\t\t\t\tclearTimeout(timer);\n\t\t\t\tresolve(value);\n\t\t\t},\n\t\t\t(reason) => {\n\t\t\t\tclearTimeout(timer);\n\t\t\t\treject(reason);\n\t\t\t},\n\t\t);\n\t});\n}\n"]}
1
+ {"version":3,"file":"timeoutUtils.js","sourceRoot":"","sources":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;YACpB,OAAO,CAAC,KAAK,CAAC,CAAC;QAChB,CAAC,EACD,CAAC,MAAM,EAAE,EAAE;YACV,YAAY,CAAC,KAAK,CAAC,CAAC;YACpB,MAAM,CAAC,MAAM,CAAC,CAAC;QAChB,CAAC,CACD,CAAC;IACH,CAAC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, Deferred } from \"@fluidframework/core-utils/internal\";\nimport type * as Mocha from \"mocha\";\n\n// @deprecated this value is no longer used\n/**\n * @internal\n */\nexport const defaultTimeoutDurationMs = 250;\n\nconst timeBuffer = 15; // leave 15 ms leeway for finish processing\n\n// TestTimeout class that manages tracking of test timeout. It creates a timer when timeout is in effect,\n// and provides a promise that will be rejected some time (as defined by `timeBuffer`) before the test timeout happens.\n// This will ensure that async awaits in tests do not end up timing out the tests but resolve / reject\n// before that happens.\n// Once rejected, a new TestTimeout object will be create for the timeout.\nclass TestTimeout {\n\tprivate timeout: number = 0;\n\tprivate timer: NodeJS.Timeout | undefined;\n\tprivate readonly deferred: Deferred<void>;\n\tprivate rejected = false;\n\n\tprivate static instance: TestTimeout = new TestTimeout();\n\tpublic static reset(runnable: Mocha.Runnable) {\n\t\tTestTimeout.clear();\n\t\tTestTimeout.instance.resetTimer(runnable);\n\t}\n\n\tpublic static clear() {\n\t\tif (TestTimeout.instance.rejected) {\n\t\t\tTestTimeout.instance = new TestTimeout();\n\t\t} else {\n\t\t\tTestTimeout.instance.clearTimer();\n\t\t}\n\t}\n\n\tpublic static getInstance() {\n\t\treturn TestTimeout.instance;\n\t}\n\n\tpublic async getPromise() {\n\t\treturn this.deferred.promise;\n\t}\n\n\tpublic getTimeout() {\n\t\treturn this.timeout;\n\t}\n\n\tprivate constructor() {\n\t\tthis.deferred = new Deferred();\n\t\t// Ignore rejection for timeout promise if no one is waiting for it.\n\t\tthis.deferred.promise.catch(() => {});\n\t}\n\n\tprivate resetTimer(runnable: Mocha.Runnable) {\n\t\tassert(!this.timer, \"clearTimer should have been called before reset\");\n\t\tassert(!this.deferred.isCompleted, \"can't reset a completed TestTimeout\");\n\n\t\t// Check the test timeout setting\n\t\tconst timeout = runnable.timeout();\n\t\tif (!(Number.isFinite(timeout) && timeout > 0)) {\n\t\t\treturn;\n\t\t}\n\n\t\t// subtract a buffer\n\t\tthis.timeout = Math.max(timeout - timeBuffer, 1);\n\n\t\t// Set up timer to reject near the test timeout.\n\t\tthis.timer = setTimeout(() => {\n\t\t\tthis.deferred.reject(this);\n\t\t\tthis.rejected = true;\n\t\t}, this.timeout);\n\t}\n\tprivate clearTimer() {\n\t\tif (this.timer) {\n\t\t\tclearTimeout(this.timer);\n\t\t\tthis.timer = undefined;\n\t\t}\n\t}\n}\n\n// only register if we are running with mocha-test-setup loaded\nif (globalThis.getMochaModule !== undefined) {\n\t// patching resetTimeout and clearTimeout on the runnable object\n\t// so we can track when test timeout are enforced\n\tconst mochaModule = globalThis.getMochaModule() as typeof Mocha;\n\tconst runnablePrototype = mochaModule.Runnable.prototype;\n\t// eslint-disable-next-line @typescript-eslint/unbound-method\n\tconst oldResetTimeoutFunc = runnablePrototype.resetTimeout;\n\trunnablePrototype.resetTimeout = function (this: Mocha.Runnable) {\n\t\toldResetTimeoutFunc.call(this);\n\t\tTestTimeout.reset(this);\n\t};\n\t// eslint-disable-next-line @typescript-eslint/unbound-method\n\tconst oldClearTimeoutFunc = runnablePrototype.clearTimeout;\n\trunnablePrototype.clearTimeout = function (this: Mocha.Runnable) {\n\t\tTestTimeout.clear();\n\t\toldClearTimeoutFunc.call(this);\n\t};\n}\n\n/**\n * @internal\n */\nexport interface TimeoutWithError {\n\t/**\n\t * Timeout duration in milliseconds, if it is great than 0 and not Infinity\n\t * If it is undefined, then it will use test timeout if we are in side the test function\n\t * Otherwise, there is no timeout\n\t */\n\tdurationMs?: number;\n\treject?: true;\n\terrorMsg?: string;\n}\n/**\n * @internal\n */\nexport interface TimeoutWithValue<T = void> {\n\t/**\n\t * Timeout duration in milliseconds, if it is great than 0 and not Infinity\n\t * If it is undefined, then it will use test timeout if we are in side the test function\n\t * Otherwise, there is no timeout\n\t */\n\tdurationMs?: number;\n\treject: false;\n\tvalue: T;\n}\n\nexport type PromiseExecutor<T = void> = (\n\tresolve: (value: T | PromiseLike<T>) => void,\n\treject: (reason?: any) => void,\n) => void;\n\n/**\n * Wraps the given promise around with promise that will complete after a specific timeout if the original promise does\n * not resolve by then. By default, it uses the mocha test timeout and complete the promise just before that so that\n * tests don't time out because of unpredictable awaits.\n * The timeout can be overridden via timeoutOptions but it's recommended to use the default value.\n * @param promise - The promise to be awaited.\n * @param timeoutOptions - Options that can be used to override the timeout and / or define the behavior\n * when the promise is not fulfilled. For example, instead of rejecting the promise, resolve with a\n * specific value.\n * @returns A new promise that will complete when the given promise resolves or the timeout expires.\n * @internal\n */\nexport async function timeoutAwait<T = void>(\n\tpromise: PromiseLike<T>,\n\ttimeoutOptions: TimeoutWithError | TimeoutWithValue<T> = {},\n): Promise<T> {\n\treturn Promise.race([promise, timeoutPromise<T>(() => {}, timeoutOptions)]);\n}\n\n/**\n * Creates a promise from the given executor that will complete after a specific timeout. By default, it uses the mocha\n * test timeout and complete the promise just before that so that tests don't time out because of unpredictable awaits.\n * The timeout can be overridden via timeoutOptions but it's recommended to use the default value.\n * @param executor - The executor for the promise.\n * @param timeoutOptions - Options that can be used to override the timeout and / or define the behavior when\n * the promise is not fulfilled. For example, instead of rejecting the promise, resolve with a specific value.\n * @returns A new promise that will complete when the given executor resolves or the timeout expires.\n * @internal\n */\nexport async function timeoutPromise<T = void>(\n\texecutor: (\n\t\tresolve: (value: T | PromiseLike<T>) => void,\n\t\treject: (reason?: any) => void,\n\t) => void,\n\ttimeoutOptions: TimeoutWithError | TimeoutWithValue<T> = {},\n): Promise<T> {\n\t// create the timeout error outside the async task, so its callstack includes\n\t// the original call site, this makes it easier to debug\n\tconst err =\n\t\ttimeoutOptions.reject === false\n\t\t\t? undefined\n\t\t\t: new Error(timeoutOptions.errorMsg ?? \"Timed out\");\n\tconst executorPromise = getTimeoutPromise(executor, timeoutOptions, err);\n\n\tconst currentTestTimeout = TestTimeout.getInstance();\n\tif (currentTestTimeout === undefined) {\n\t\treturn executorPromise;\n\t}\n\n\treturn Promise.race([executorPromise, currentTestTimeout.getPromise()]).catch((e) => {\n\t\tif (e === currentTestTimeout) {\n\t\t\tif (timeoutOptions.reject !== false) {\n\t\t\t\t// If the rejection is because of the timeout then\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tconst errorObject = err!;\n\t\t\t\terrorObject.message = `${\n\t\t\t\t\ttimeoutOptions.errorMsg ?? \"Test timed out\"\n\t\t\t\t} (${currentTestTimeout.getTimeout()}ms)`;\n\t\t\t\tthrow errorObject;\n\t\t\t}\n\t\t\treturn timeoutOptions.value;\n\t\t}\n\t\tthrow e;\n\t}) as Promise<T>;\n}\n\n// Create a promise based on the timeout options\nasync function getTimeoutPromise<T = void>(\n\texecutor: (\n\t\tresolve: (value: T | PromiseLike<T>) => void,\n\t\treject: (reason?: any) => void,\n\t) => void,\n\ttimeoutOptions: TimeoutWithError | TimeoutWithValue<T>,\n\terr: Error | undefined,\n) {\n\tconst timeout = timeoutOptions.durationMs ?? 0;\n\tif (timeout <= 0 || !Number.isFinite(timeout)) {\n\t\treturn new Promise(executor);\n\t}\n\n\treturn new Promise<T>((resolve, reject) => {\n\t\tconst timeoutRejections = () => {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tconst errorObject = err!;\n\t\t\terrorObject.message = `${errorObject.message} (${timeout}ms)`;\n\t\t\treject(err);\n\t\t};\n\t\tconst timer = setTimeout(\n\t\t\t() =>\n\t\t\t\ttimeoutOptions.reject === false ? resolve(timeoutOptions.value) : timeoutRejections(),\n\t\t\ttimeout,\n\t\t);\n\n\t\texecutor(\n\t\t\t(value) => {\n\t\t\t\tclearTimeout(timer);\n\t\t\t\tresolve(value);\n\t\t\t},\n\t\t\t(reason) => {\n\t\t\t\tclearTimeout(timer);\n\t\t\t\treject(reason);\n\t\t\t},\n\t\t);\n\t});\n}\n"]}
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.43.1"
8
+ "packageVersion": "7.45.1"
9
9
  }
10
10
  ]
11
11
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluidframework/test-utils",
3
- "version": "2.0.0-rc.4.0.5",
3
+ "version": "2.0.0-rc.5.0.0",
4
4
  "description": "Utilities for Fluid tests",
5
5
  "homepage": "https://fluidframework.com",
6
6
  "repository": {
@@ -67,26 +67,25 @@
67
67
  "temp-directory": "nyc/.nyc_output"
68
68
  },
69
69
  "dependencies": {
70
- "@fluid-internal/test-driver-definitions": ">=2.0.0-rc.4.0.5 <2.0.0-rc.4.1.0",
71
- "@fluidframework/aqueduct": ">=2.0.0-rc.4.0.5 <2.0.0-rc.4.1.0",
72
- "@fluidframework/container-definitions": ">=2.0.0-rc.4.0.5 <2.0.0-rc.4.1.0",
73
- "@fluidframework/container-loader": ">=2.0.0-rc.4.0.5 <2.0.0-rc.4.1.0",
74
- "@fluidframework/container-runtime": ">=2.0.0-rc.4.0.5 <2.0.0-rc.4.1.0",
75
- "@fluidframework/container-runtime-definitions": ">=2.0.0-rc.4.0.5 <2.0.0-rc.4.1.0",
76
- "@fluidframework/core-interfaces": ">=2.0.0-rc.4.0.5 <2.0.0-rc.4.1.0",
77
- "@fluidframework/core-utils": ">=2.0.0-rc.4.0.5 <2.0.0-rc.4.1.0",
78
- "@fluidframework/datastore": ">=2.0.0-rc.4.0.5 <2.0.0-rc.4.1.0",
79
- "@fluidframework/datastore-definitions": ">=2.0.0-rc.4.0.5 <2.0.0-rc.4.1.0",
80
- "@fluidframework/driver-definitions": ">=2.0.0-rc.4.0.5 <2.0.0-rc.4.1.0",
81
- "@fluidframework/driver-utils": ">=2.0.0-rc.4.0.5 <2.0.0-rc.4.1.0",
82
- "@fluidframework/local-driver": ">=2.0.0-rc.4.0.5 <2.0.0-rc.4.1.0",
83
- "@fluidframework/map": ">=2.0.0-rc.4.0.5 <2.0.0-rc.4.1.0",
84
- "@fluidframework/protocol-definitions": "^3.2.0",
85
- "@fluidframework/request-handler": ">=2.0.0-rc.4.0.5 <2.0.0-rc.4.1.0",
86
- "@fluidframework/routerlicious-driver": ">=2.0.0-rc.4.0.5 <2.0.0-rc.4.1.0",
87
- "@fluidframework/runtime-definitions": ">=2.0.0-rc.4.0.5 <2.0.0-rc.4.1.0",
88
- "@fluidframework/runtime-utils": ">=2.0.0-rc.4.0.5 <2.0.0-rc.4.1.0",
89
- "@fluidframework/telemetry-utils": ">=2.0.0-rc.4.0.5 <2.0.0-rc.4.1.0",
70
+ "@fluid-internal/test-driver-definitions": ">=2.0.0-rc.5.0.0 <2.0.0-rc.5.1.0",
71
+ "@fluidframework/aqueduct": ">=2.0.0-rc.5.0.0 <2.0.0-rc.5.1.0",
72
+ "@fluidframework/container-definitions": ">=2.0.0-rc.5.0.0 <2.0.0-rc.5.1.0",
73
+ "@fluidframework/container-loader": ">=2.0.0-rc.5.0.0 <2.0.0-rc.5.1.0",
74
+ "@fluidframework/container-runtime": ">=2.0.0-rc.5.0.0 <2.0.0-rc.5.1.0",
75
+ "@fluidframework/container-runtime-definitions": ">=2.0.0-rc.5.0.0 <2.0.0-rc.5.1.0",
76
+ "@fluidframework/core-interfaces": ">=2.0.0-rc.5.0.0 <2.0.0-rc.5.1.0",
77
+ "@fluidframework/core-utils": ">=2.0.0-rc.5.0.0 <2.0.0-rc.5.1.0",
78
+ "@fluidframework/datastore": ">=2.0.0-rc.5.0.0 <2.0.0-rc.5.1.0",
79
+ "@fluidframework/datastore-definitions": ">=2.0.0-rc.5.0.0 <2.0.0-rc.5.1.0",
80
+ "@fluidframework/driver-definitions": ">=2.0.0-rc.5.0.0 <2.0.0-rc.5.1.0",
81
+ "@fluidframework/driver-utils": ">=2.0.0-rc.5.0.0 <2.0.0-rc.5.1.0",
82
+ "@fluidframework/local-driver": ">=2.0.0-rc.5.0.0 <2.0.0-rc.5.1.0",
83
+ "@fluidframework/map": ">=2.0.0-rc.5.0.0 <2.0.0-rc.5.1.0",
84
+ "@fluidframework/request-handler": ">=2.0.0-rc.5.0.0 <2.0.0-rc.5.1.0",
85
+ "@fluidframework/routerlicious-driver": ">=2.0.0-rc.5.0.0 <2.0.0-rc.5.1.0",
86
+ "@fluidframework/runtime-definitions": ">=2.0.0-rc.5.0.0 <2.0.0-rc.5.1.0",
87
+ "@fluidframework/runtime-utils": ">=2.0.0-rc.5.0.0 <2.0.0-rc.5.1.0",
88
+ "@fluidframework/telemetry-utils": ">=2.0.0-rc.5.0.0 <2.0.0-rc.5.1.0",
90
89
  "best-random": "^1.0.0",
91
90
  "debug": "^4.3.4",
92
91
  "mocha": "^10.2.0",
@@ -94,20 +93,21 @@
94
93
  },
95
94
  "devDependencies": {
96
95
  "@arethetypeswrong/cli": "^0.15.2",
97
- "@biomejs/biome": "^1.6.2",
98
- "@fluid-internal/mocha-test-setup": ">=2.0.0-rc.4.0.5 <2.0.0-rc.4.1.0",
99
- "@fluid-tools/build-cli": "^0.38.0",
96
+ "@biomejs/biome": "^1.7.3",
97
+ "@fluid-internal/mocha-test-setup": ">=2.0.0-rc.5.0.0 <2.0.0-rc.5.1.0",
98
+ "@fluid-tools/build-cli": "^0.39.0",
100
99
  "@fluidframework/build-common": "^2.0.3",
101
- "@fluidframework/build-tools": "^0.38.0",
102
- "@fluidframework/eslint-config-fluid": "^5.1.0",
103
- "@fluidframework/test-utils-previous": "npm:@fluidframework/test-utils@2.0.0-rc.3.0.0",
104
- "@microsoft/api-extractor": "^7.43.1",
100
+ "@fluidframework/build-tools": "^0.39.0",
101
+ "@fluidframework/eslint-config-fluid": "^5.3.0",
102
+ "@fluidframework/test-utils-previous": "npm:@fluidframework/test-utils@2.0.0-rc.4.0.0",
103
+ "@microsoft/api-extractor": "^7.45.1",
105
104
  "@types/debug": "^4.1.5",
106
105
  "@types/diff": "^3.5.1",
107
106
  "@types/mocha": "^9.1.1",
108
107
  "@types/node": "^18.19.0",
109
108
  "@types/uuid": "^9.0.2",
110
109
  "c8": "^8.0.1",
110
+ "concurrently": "^8.2.1",
111
111
  "copyfiles": "^2.4.1",
112
112
  "cross-env": "^7.0.3",
113
113
  "diff": "^3.5.0",
@@ -117,10 +117,18 @@
117
117
  "moment": "^2.21.0",
118
118
  "prettier": "~3.0.3",
119
119
  "rimraf": "^4.4.0",
120
- "typescript": "~5.1.6"
120
+ "typescript": "~5.4.5"
121
121
  },
122
122
  "typeValidation": {
123
123
  "broken": {
124
+ "InterfaceDeclaration_IProvideTestFluidObject": {
125
+ "forwardCompat": false,
126
+ "backCompat": false
127
+ },
128
+ "InterfaceDeclaration_ITestFluidObject": {
129
+ "forwardCompat": false,
130
+ "backCompat": false
131
+ },
124
132
  "ClassDeclaration_TestFluidObject": {
125
133
  "forwardCompat": false,
126
134
  "backCompat": false
@@ -141,13 +149,21 @@
141
149
  "build:test:cjs": "fluid-tsc commonjs --project ./src/test/tsconfig.cjs.json",
142
150
  "build:test:esm": "tsc --project ./src/test/tsconfig.json",
143
151
  "check:are-the-types-wrong": "attw --pack .",
152
+ "check:biome": "biome check . --formatter-enabled=true",
153
+ "check:exports": "concurrently \"npm:check:exports:*\"",
154
+ "check:exports:bundle-release-tags": "api-extractor run --config api-extractor/api-extractor-lint-bundle.json",
155
+ "check:exports:cjs:legacy": "api-extractor run --config api-extractor/api-extractor-lint-legacy.cjs.json",
156
+ "check:exports:cjs:public": "api-extractor run --config api-extractor/api-extractor-lint-public.cjs.json",
157
+ "check:exports:esm:legacy": "api-extractor run --config api-extractor/api-extractor-lint-legacy.esm.json",
158
+ "check:exports:esm:public": "api-extractor run --config api-extractor/api-extractor-lint-public.esm.json",
159
+ "check:format": "npm run check:biome",
144
160
  "check:prettier": "prettier --check . --cache --ignore-path ../../../.prettierignore",
145
- "check:release-tags": "api-extractor run --local --config ./api-extractor-lint.json",
146
161
  "ci:build:docs": "api-extractor run",
147
162
  "clean": "rimraf --glob dist lib \"*.d.ts\" \"**/*.tsbuildinfo\" \"**/*.build.log\" _api-extractor-temp nyc",
148
163
  "eslint": "eslint --format stylish src",
149
164
  "eslint:fix": "eslint --format stylish src --fix --fix-type problem,suggestion,layout",
150
- "format": "fluid-build --task format .",
165
+ "format": "npm run format:biome",
166
+ "format:biome": "biome check . --formatter-enabled=true --apply",
151
167
  "format:prettier": "prettier --write . --cache --ignore-path ../../../.prettierignore",
152
168
  "lint": "fluid-build . --task lint",
153
169
  "lint:fix": "fluid-build . --task eslint:fix --task format",
@@ -4,6 +4,7 @@
4
4
  */
5
5
 
6
6
  import { ITelemetryBaseLogger } from "@fluidframework/core-interfaces";
7
+ import { ISummaryTree } from "@fluidframework/driver-definitions";
7
8
  import {
8
9
  IDocumentService,
9
10
  IDocumentServiceFactory,
@@ -11,7 +12,6 @@ import {
11
12
  IResolvedUrl,
12
13
  ISummaryContext,
13
14
  } from "@fluidframework/driver-definitions/internal";
14
- import { ISummaryTree } from "@fluidframework/protocol-definitions";
15
15
 
16
16
  /**
17
17
  * @deprecated - unused
@@ -24,7 +24,9 @@ export function wrapDocumentStorageService(
24
24
  innerDocStorageService: IDocumentStorageService,
25
25
  uploadSummaryCb: (summaryTree: ISummaryTree, context: ISummaryContext) => ISummaryContext,
26
26
  ) {
27
- const outerDocStorageService = Object.create(innerDocStorageService) as IDocumentStorageService;
27
+ const outerDocStorageService = Object.create(
28
+ innerDocStorageService,
29
+ ) as IDocumentStorageService;
28
30
  outerDocStorageService.uploadSummaryWithContext = async (
29
31
  summary: ISummaryTree,
30
32
  context: ISummaryContext,
@@ -69,7 +71,9 @@ export function wrapDocumentServiceFactory(
69
71
  innerDocServiceFactory: IDocumentServiceFactory,
70
72
  uploadSummaryCb: (summaryTree: ISummaryTree, context: ISummaryContext) => ISummaryContext,
71
73
  ) {
72
- const outerDocServiceFactory = Object.create(innerDocServiceFactory) as IDocumentServiceFactory;
74
+ const outerDocServiceFactory = Object.create(
75
+ innerDocServiceFactory,
76
+ ) as IDocumentServiceFactory;
73
77
  outerDocServiceFactory.createDocumentService = async (
74
78
  resolvedUrl: IResolvedUrl,
75
79
  logger?: ITelemetryBaseLogger,
@@ -21,8 +21,8 @@ import {
21
21
  ITelemetryBaseLogger,
22
22
  } from "@fluidframework/core-interfaces";
23
23
  import { assert } from "@fluidframework/core-utils/internal";
24
+ import { ISummaryTree } from "@fluidframework/driver-definitions";
24
25
  import { DriverHeader } from "@fluidframework/driver-definitions/internal";
25
- import { ISummaryTree } from "@fluidframework/protocol-definitions";
26
26
  import {
27
27
  IFluidDataStoreFactory,
28
28
  NamedFluidDataStoreRegistryEntries,
@@ -189,9 +189,6 @@ export async function summarizeNow(
189
189
 
190
190
  const submitResult = await timeoutAwait(result.summarySubmitted);
191
191
  if (!submitResult.success) {
192
- if (typeof submitResult.error !== "string") {
193
- submitResult.error.data = submitResult.data;
194
- }
195
192
  throw submitResult.error;
196
193
  }
197
194
  assert(
package/src/index.ts CHANGED
@@ -10,7 +10,11 @@ export {
10
10
  } from "./DriverWrappers.js";
11
11
  export { IProvideTestFluidObject, ITestFluidObject } from "./interfaces.js";
12
12
  export { LoaderContainerTracker } from "./loaderContainerTracker.js";
13
- export { fluidEntryPoint, LocalCodeLoader, SupportedExportInterfaces } from "./localCodeLoader.js";
13
+ export {
14
+ fluidEntryPoint,
15
+ LocalCodeLoader,
16
+ SupportedExportInterfaces,
17
+ } from "./localCodeLoader.js";
14
18
  export { createAndAttachContainer, createLoader } from "./localLoader.js";
15
19
  export { retryWithEventualValue } from "./retry.js";
16
20
  export { createTestConfigProvider, ITestConfigProvider } from "./TestConfigs.js";
package/src/interfaces.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  */
5
5
 
6
6
  import { IFluidLoadable } from "@fluidframework/core-interfaces";
7
- import { IFluidDataStoreRuntime } from "@fluidframework/datastore-definitions";
7
+ import { IFluidDataStoreRuntime } from "@fluidframework/datastore-definitions/internal";
8
8
  import { ISharedMap } from "@fluidframework/map/internal";
9
9
  import {
10
10
  IFluidDataStoreChannel,
@@ -15,12 +15,12 @@ import {
15
15
  // eslint-disable-next-line import/no-internal-modules
16
16
  } from "@fluidframework/container-loader/internal/test/container";
17
17
  import { assert } from "@fluidframework/core-utils/internal";
18
- import { canBeCoalescedByService } from "@fluidframework/driver-utils/internal";
19
18
  import {
20
19
  IDocumentMessage,
21
- ISequencedDocumentMessage,
22
20
  MessageType,
23
- } from "@fluidframework/protocol-definitions";
21
+ ISequencedDocumentMessage,
22
+ } from "@fluidframework/driver-definitions/internal";
23
+ import { canBeCoalescedByService } from "@fluidframework/driver-utils/internal";
24
24
 
25
25
  import { waitForContainerConnection } from "./containerUtils.js";
26
26
  import { debug } from "./debug.js";
@@ -312,10 +312,7 @@ export class LoaderContainerTracker implements IOpProcessingController {
312
312
  const quorum = container.getQuorum();
313
313
  quorum.getMembers().forEach((client, clientId) => {
314
314
  // ignore summarizer
315
- if (
316
- !client.client.details.capabilities.interactive &&
317
- !this.syncSummarizerClients
318
- ) {
315
+ if (!client.client.details.capabilities.interactive && !this.syncSummarizerClients) {
319
316
  return;
320
317
  }
321
318
  if (!openedClientId.includes(clientId)) {
@@ -439,9 +436,7 @@ export class LoaderContainerTracker implements IOpProcessingController {
439
436
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
440
437
  const index = this.containers.get(container)!.index;
441
438
  debugWait(
442
- `${index}: Waiting for pending clients ${Array.from(
443
- pendingClientId.keys(),
444
- )}`,
439
+ `${index}: Waiting for pending clients ${Array.from(pendingClientId.keys())}`,
445
440
  );
446
441
  unconnectedClients.forEach((c) => c.on("connected", handler));
447
442
  container.getQuorum().on("removeMember", handler);
@@ -552,7 +547,7 @@ export class LoaderContainerTracker implements IOpProcessingController {
552
547
  const maybeContainer = container as Partial<IContainer>;
553
548
  const codeProposal = maybeContainer.getLoadedCodeDetails
554
549
  ? // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
555
- container.getLoadedCodeDetails()!
550
+ container.getLoadedCodeDetails()!
556
551
  : (container as any).chaincodePackage;
557
552
 
558
553
  proposalP = container.proposeCodeDetails(codeProposal);
@@ -748,9 +743,7 @@ export class LoaderContainerTracker implements IOpProcessingController {
748
743
  : " ";
749
744
  debugOp(
750
745
  `${index}: ${type}: seq: ${msg.sequenceNumber.toString().padStart(3)} ` +
751
- `${clientSeq} min: ${msg.minimumSequenceNumber
752
- .toString()
753
- .padStart(3)} ` +
746
+ `${clientSeq} min: ${msg.minimumSequenceNumber.toString().padStart(3)} ` +
754
747
  `${msg.type} ${getContentsString(msg.type, msg.contents)}`,
755
748
  );
756
749
  };
@@ -75,9 +75,7 @@ export class LocalCodeLoader implements ICodeDetailsLoader {
75
75
  ...maybeExport,
76
76
  IRuntimeFactory: new ContainerRuntimeFactoryWithDefaultDataStore({
77
77
  defaultFactory,
78
- registryEntries: [
79
- [defaultFactory.type, Promise.resolve(defaultFactory)],
80
- ],
78
+ registryEntries: [[defaultFactory.type, Promise.resolve(defaultFactory)]],
81
79
  runtimeOptions,
82
80
  }),
83
81
  },
@@ -12,7 +12,10 @@ import {
12
12
  } from "@fluidframework/container-definitions/internal";
13
13
  import { Loader } from "@fluidframework/container-loader/internal";
14
14
  import { IRequest, ITelemetryBaseLogger } from "@fluidframework/core-interfaces";
15
- import { IDocumentServiceFactory, IUrlResolver } from "@fluidframework/driver-definitions/internal";
15
+ import {
16
+ IDocumentServiceFactory,
17
+ IUrlResolver,
18
+ } from "@fluidframework/driver-definitions/internal";
16
19
 
17
20
  import { LocalCodeLoader, fluidEntryPoint } from "./localCodeLoader.js";
18
21
 
@@ -6,4 +6,4 @@
6
6
  */
7
7
 
8
8
  export const pkgName = "@fluidframework/test-utils";
9
- export const pkgVersion = "2.0.0-rc.4.0.5";
9
+ export const pkgVersion = "2.0.0-rc.5.0.0";
@@ -10,12 +10,8 @@ import {
10
10
  IContainerRuntimeOptions,
11
11
  } from "@fluidframework/container-runtime/internal";
12
12
  import { IContainerRuntime } from "@fluidframework/container-runtime-definitions/internal";
13
- import {
14
- FluidObject,
15
- IFluidHandleContext,
16
- IRequest,
17
- IResponse,
18
- } from "@fluidframework/core-interfaces";
13
+ import { FluidObject, IRequest, IResponse } from "@fluidframework/core-interfaces";
14
+ import { IFluidHandleContext } from "@fluidframework/core-interfaces/internal";
19
15
  import { assert } from "@fluidframework/core-utils/internal";
20
16
  import {
21
17
  // eslint-disable-next-line import/no-deprecated
@@ -114,10 +110,7 @@ export const createTestContainerRuntimeFactory = (
114
110
  await (runtime.getAliasedDataStoreEntryPoint?.("default") ??
115
111
  (
116
112
  runtime as any as {
117
- getRootDataStore(
118
- id: string,
119
- wait?: boolean,
120
- ): Promise<backCompat_IFluidRouter>;
113
+ getRootDataStore(id: string, wait?: boolean): Promise<backCompat_IFluidRouter>;
121
114
  }
122
115
  ).getRootDataStore("default"));
123
116
  }
@@ -170,10 +163,7 @@ export const createTestContainerRuntimeFactory = (
170
163
  [this.type, Promise.resolve(this.dataStoreFactory)],
171
164
  ],
172
165
  // eslint-disable-next-line import/no-deprecated
173
- requestHandler: buildRuntimeRequestHandler(
174
- getDefaultObject,
175
- ...this.requestHandlers,
176
- ),
166
+ requestHandler: buildRuntimeRequestHandler(getDefaultObject, ...this.requestHandlers),
177
167
  provideEntryPoint,
178
168
  // ! This prop is needed for back-compat. Can be removed in 2.0.0-internal.8.0.0
179
169
  initializeEntryPoint: provideEntryPoint,
@@ -10,7 +10,10 @@ import {
10
10
  FluidObjectHandle,
11
11
  mixinRequestHandler,
12
12
  } from "@fluidframework/datastore/internal";
13
- import { IChannelFactory, IFluidDataStoreRuntime } from "@fluidframework/datastore-definitions";
13
+ import {
14
+ IChannelFactory,
15
+ IFluidDataStoreRuntime,
16
+ } from "@fluidframework/datastore-definitions/internal";
14
17
  import { ISharedMap, SharedMap } from "@fluidframework/map/internal";
15
18
  import {
16
19
  IFluidDataStoreChannel,
@@ -90,15 +93,10 @@ export class TestFluidObject implements ITestFluidObject {
90
93
  if (!existing) {
91
94
  this.root = SharedMap.create(this.runtime, "root");
92
95
 
93
- this.factoryEntriesMap.forEach(
94
- (sharedObjectFactory: IChannelFactory, key: string) => {
95
- const sharedObject = this.runtime.createChannel(
96
- key,
97
- sharedObjectFactory.type,
98
- );
99
- this.root.set(key, sharedObject.handle);
100
- },
101
- );
96
+ this.factoryEntriesMap.forEach((sharedObjectFactory: IChannelFactory, key: string) => {
97
+ const sharedObject = this.runtime.createChannel(key, sharedObjectFactory.type);
98
+ this.root.set(key, sharedObject.handle);
99
+ });
102
100
 
103
101
  this.root.bindToContext();
104
102
  }
@@ -3,7 +3,6 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- import { assert } from "@fluidframework/core-utils/internal";
7
6
  import { ITestDriver, TestDriverTypes } from "@fluid-internal/test-driver-definitions";
8
7
  import {
9
8
  IContainer,
@@ -22,6 +21,7 @@ import {
22
21
  ITelemetryBaseEvent,
23
22
  ITelemetryBaseLogger,
24
23
  } from "@fluidframework/core-interfaces";
24
+ import { assert } from "@fluidframework/core-utils/internal";
25
25
  import {
26
26
  IDocumentServiceFactory,
27
27
  IResolvedUrl,
@@ -531,7 +531,10 @@ export class TestObjectProvider implements ITestObjectProvider {
531
531
  /**
532
532
  * {@inheritDoc ITestObjectProvider.createContainer}
533
533
  */
534
- public async createContainer(entryPoint: fluidEntryPoint, loaderProps?: Partial<ILoaderProps>) {
534
+ public async createContainer(
535
+ entryPoint: fluidEntryPoint,
536
+ loaderProps?: Partial<ILoaderProps>,
537
+ ) {
535
538
  if (this._documentCreated) {
536
539
  throw new Error(
537
540
  "Only one container/document can be created. To load the container/document use loadContainer",
@@ -895,7 +898,10 @@ export class TestObjectProviderWithVersionedLoad implements ITestObjectProvider
895
898
  /**
896
899
  * {@inheritDoc ITestObjectProvider.createContainer}
897
900
  */
898
- public async createContainer(entryPoint: fluidEntryPoint, loaderProps?: Partial<ILoaderProps>) {
901
+ public async createContainer(
902
+ entryPoint: fluidEntryPoint,
903
+ loaderProps?: Partial<ILoaderProps>,
904
+ ) {
899
905
  if (this._documentCreated) {
900
906
  throw new Error(
901
907
  "Only one container/document can be created. To load the container/document use loadContainer",
@@ -225,9 +225,7 @@ async function getTimeoutPromise<T = void>(
225
225
  };
226
226
  const timer = setTimeout(
227
227
  () =>
228
- timeoutOptions.reject === false
229
- ? resolve(timeoutOptions.value)
230
- : timeoutRejections(),
228
+ timeoutOptions.reject === false ? resolve(timeoutOptions.value) : timeoutRejections(),
231
229
  timeout,
232
230
  );
233
231
 
package/tsconfig.json CHANGED
@@ -5,6 +5,8 @@
5
5
  "rootDir": "./src",
6
6
  "outDir": "./lib",
7
7
  "types": ["node"],
8
+ "noUncheckedIndexedAccess": false,
9
+ "exactOptionalPropertyTypes": false,
8
10
  },
9
11
  "include": ["src/**/*"],
10
12
  }
package/tsdoc.json ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "$schema": "https://developer.microsoft.com/json-schemas/tsdoc/v0/tsdoc.schema.json",
3
+ "extends": ["../../../common/build/build-common/tsdoc-base.json"]
4
+ }