@fluidframework/test-utils 2.1.0-276985 → 2.1.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.
- package/CHANGELOG.md +4 -0
- package/api-extractor/api-extractor.current.json +5 -0
- package/api-extractor/api-extractor.legacy.json +1 -1
- package/api-extractor.json +1 -1
- package/api-report/test-utils.legacy.public.api.md +9 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/legacy.d.ts +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.d.ts.map +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/public.d.ts +1 -1
- package/dist/timeoutUtils.d.ts +26 -19
- package/dist/timeoutUtils.d.ts.map +1 -1
- package/dist/timeoutUtils.js +27 -18
- package/dist/timeoutUtils.js.map +1 -1
- package/internal.d.ts +1 -1
- package/legacy.d.ts +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/legacy.d.ts +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.d.ts.map +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/public.d.ts +1 -1
- package/lib/timeoutUtils.d.ts +26 -19
- package/lib/timeoutUtils.d.ts.map +1 -1
- package/lib/timeoutUtils.js +27 -18
- package/lib/timeoutUtils.js.map +1 -1
- package/package.json +35 -33
- package/src/index.ts +3 -2
- package/src/packageVersion.ts +1 -1
- package/src/timeoutUtils.ts +39 -26
package/CHANGELOG.md
CHANGED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
|
|
3
|
+
"extends": "<projectFolder>/../../../common/build/build-common/api-extractor-report.esm.current.json",
|
|
4
|
+
"mainEntryPointFilePath": "<projectFolder>/lib/public.d.ts"
|
|
5
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
|
|
3
|
-
"extends": "<projectFolder>/../../../common/build/build-common/api-extractor-
|
|
3
|
+
"extends": "<projectFolder>/../../../common/build/build-common/api-extractor-report.esm.legacy.json"
|
|
4
4
|
}
|
package/api-extractor.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
|
|
3
|
-
"extends": "../../../common/build/build-common/api-extractor-
|
|
3
|
+
"extends": "../../../common/build/build-common/api-extractor-model.esm.json"
|
|
4
4
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export { createTestContainerRuntimeFactory, TestContainerRuntimeFactory, } from
|
|
|
13
13
|
export { ChannelFactoryRegistry, TestFluidObject, TestFluidObjectFactory, } from "./testFluidObject.js";
|
|
14
14
|
export { createDocumentId, DataObjectFactoryType, EventAndErrorTrackingLogger, type IEventAndErrorTrackingLogger, getUnexpectedLogErrorException, IDocumentIdStrategy, IOpProcessingController, ITestContainerConfig, ITestObjectProvider, TestObjectProvider, TestObjectProviderWithVersionedLoad, } from "./testObjectProvider.js";
|
|
15
15
|
export { createSummarizer, createSummarizerCore, createSummarizerFromFactory, summarizeNow, SummaryInfo, } from "./TestSummaryUtils.js";
|
|
16
|
-
export { defaultTimeoutDurationMs, timeoutAwait, timeoutPromise, TimeoutWithError, TimeoutWithValue, } from "./timeoutUtils.js";
|
|
16
|
+
export { defaultTimeoutDurationMs, timeoutAwait, timeoutPromise, type TimeoutDurationOption, type TimeoutWithError, type TimeoutWithValue, } from "./timeoutUtils.js";
|
|
17
17
|
export { waitForContainerConnection, getContainerEntryPointBackCompat, getDataStoreEntryPointBackCompat, } from "./containerUtils.js";
|
|
18
18
|
export { createContainerRuntimeFactoryWithDefaultDataStore } from "./testContainerRuntimeFactoryWithDefaultDataStore.js";
|
|
19
19
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,mBAAmB,EACnB,0BAA0B,EAC1B,0BAA0B,GAC1B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAC5E,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EACN,eAAe,EACf,eAAe,EACf,yBAAyB,GACzB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,wBAAwB,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAC1E,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,EAAE,wBAAwB,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACjF,OAAO,EACN,iCAAiC,EACjC,2BAA2B,GAC3B,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACN,sBAAsB,EACtB,eAAe,EACf,sBAAsB,GACtB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACN,gBAAgB,EAChB,qBAAqB,EACrB,2BAA2B,EAC3B,KAAK,4BAA4B,EACjC,8BAA8B,EAC9B,mBAAmB,EACnB,uBAAuB,EACvB,oBAAoB,EACpB,mBAAmB,EACnB,kBAAkB,EAClB,mCAAmC,GACnC,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACN,gBAAgB,EAChB,oBAAoB,EACpB,2BAA2B,EAC3B,YAAY,EACZ,WAAW,GACX,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACN,wBAAwB,EACxB,YAAY,EACZ,cAAc,EACd,gBAAgB,
|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B,OAAO,EAAE,iDAAiD,EAAE,MAAM,sDAAsD,CAAC"}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,yDAI6B;AAH5B,wHAAA,mBAAmB,OAAA;AACnB,+HAAA,0BAA0B,OAAA;AAC1B,+HAAA,0BAA0B,OAAA;AAG3B,yEAAqE;AAA5D,mIAAA,sBAAsB,OAAA;AAC/B,2DAI8B;AAF7B,qHAAA,eAAe,OAAA;AAGhB,mDAA0E;AAAjE,0HAAA,wBAAwB,OAAA;AAAE,8GAAA,YAAY,OAAA;AAC/C,uCAAoD;AAA3C,kHAAA,sBAAsB,OAAA;AAC/B,mDAAiF;AAAxE,0HAAA,wBAAwB,OAAA;AACjC,mFAG0C;AAFzC,mJAAA,iCAAiC,OAAA;AACjC,6IAAA,2BAA2B,OAAA;AAE5B,2DAI8B;AAF7B,qHAAA,eAAe,OAAA;AACf,4HAAA,sBAAsB,OAAA;AAEvB,iEAYiC;AAXhC,yHAAA,gBAAgB,OAAA;AAChB,8HAAA,qBAAqB,OAAA;AACrB,oIAAA,2BAA2B,OAAA;AAE3B,uIAAA,8BAA8B,OAAA;AAK9B,2HAAA,kBAAkB,OAAA;AAClB,4IAAA,mCAAmC,OAAA;AAEpC,6DAM+B;AAL9B,uHAAA,gBAAgB,OAAA;AAChB,2HAAA,oBAAoB,OAAA;AACpB,kIAAA,2BAA2B,OAAA;AAC3B,mHAAA,YAAY,OAAA;AAGb,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,yDAI6B;AAH5B,wHAAA,mBAAmB,OAAA;AACnB,+HAAA,0BAA0B,OAAA;AAC1B,+HAAA,0BAA0B,OAAA;AAG3B,yEAAqE;AAA5D,mIAAA,sBAAsB,OAAA;AAC/B,2DAI8B;AAF7B,qHAAA,eAAe,OAAA;AAGhB,mDAA0E;AAAjE,0HAAA,wBAAwB,OAAA;AAAE,8GAAA,YAAY,OAAA;AAC/C,uCAAoD;AAA3C,kHAAA,sBAAsB,OAAA;AAC/B,mDAAiF;AAAxE,0HAAA,wBAAwB,OAAA;AACjC,mFAG0C;AAFzC,mJAAA,iCAAiC,OAAA;AACjC,6IAAA,2BAA2B,OAAA;AAE5B,2DAI8B;AAF7B,qHAAA,eAAe,OAAA;AACf,4HAAA,sBAAsB,OAAA;AAEvB,iEAYiC;AAXhC,yHAAA,gBAAgB,OAAA;AAChB,8HAAA,qBAAqB,OAAA;AACrB,oIAAA,2BAA2B,OAAA;AAE3B,uIAAA,8BAA8B,OAAA;AAK9B,2HAAA,kBAAkB,OAAA;AAClB,4IAAA,mCAAmC,OAAA;AAEpC,6DAM+B;AAL9B,uHAAA,gBAAgB,OAAA;AAChB,2HAAA,oBAAoB,OAAA;AACpB,kIAAA,2BAA2B,OAAA;AAC3B,mHAAA,YAAY,OAAA;AAGb,qDAO2B;AAN1B,2HAAA,wBAAwB,OAAA;AACxB,+GAAA,YAAY,OAAA;AACZ,iHAAA,cAAc,OAAA;AAKf,yDAI6B;AAH5B,+HAAA,0BAA0B,OAAA;AAC1B,qIAAA,gCAAgC,OAAA;AAChC,qIAAA,gCAAgC,OAAA;AAEjC,2HAAyH;AAAhH,uLAAA,iDAAiD,OAAA","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport {\n\twrapDocumentService,\n\twrapDocumentServiceFactory,\n\twrapDocumentStorageService,\n} from \"./DriverWrappers.js\";\nexport { IProvideTestFluidObject, ITestFluidObject } from \"./interfaces.js\";\nexport { LoaderContainerTracker } from \"./loaderContainerTracker.js\";\nexport {\n\tfluidEntryPoint,\n\tLocalCodeLoader,\n\tSupportedExportInterfaces,\n} from \"./localCodeLoader.js\";\nexport { createAndAttachContainer, createLoader } from \"./localLoader.js\";\nexport { retryWithEventualValue } from \"./retry.js\";\nexport { createTestConfigProvider, ITestConfigProvider } from \"./TestConfigs.js\";\nexport {\n\tcreateTestContainerRuntimeFactory,\n\tTestContainerRuntimeFactory,\n} from \"./testContainerRuntimeFactory.js\";\nexport {\n\tChannelFactoryRegistry,\n\tTestFluidObject,\n\tTestFluidObjectFactory,\n} from \"./testFluidObject.js\";\nexport {\n\tcreateDocumentId,\n\tDataObjectFactoryType,\n\tEventAndErrorTrackingLogger,\n\ttype IEventAndErrorTrackingLogger,\n\tgetUnexpectedLogErrorException,\n\tIDocumentIdStrategy,\n\tIOpProcessingController,\n\tITestContainerConfig,\n\tITestObjectProvider,\n\tTestObjectProvider,\n\tTestObjectProviderWithVersionedLoad,\n} from \"./testObjectProvider.js\";\nexport {\n\tcreateSummarizer,\n\tcreateSummarizerCore,\n\tcreateSummarizerFromFactory,\n\tsummarizeNow,\n\tSummaryInfo,\n} from \"./TestSummaryUtils.js\";\nexport {\n\tdefaultTimeoutDurationMs,\n\ttimeoutAwait,\n\ttimeoutPromise,\n\ttype TimeoutDurationOption,\n\ttype TimeoutWithError,\n\ttype TimeoutWithValue,\n} from \"./timeoutUtils.js\";\nexport {\n\twaitForContainerConnection,\n\tgetContainerEntryPointBackCompat,\n\tgetDataStoreEntryPointBackCompat,\n} from \"./containerUtils.js\";\nexport { createContainerRuntimeFactoryWithDefaultDataStore } from \"./testContainerRuntimeFactoryWithDefaultDataStore.js\";\n"]}
|
package/dist/legacy.d.ts
CHANGED
package/dist/packageVersion.d.ts
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
|
|
6
6
|
*/
|
|
7
7
|
export declare const pkgName = "@fluidframework/test-utils";
|
|
8
|
-
export declare const pkgVersion = "2.1.0
|
|
8
|
+
export declare const pkgVersion = "2.1.0";
|
|
9
9
|
//# sourceMappingURL=packageVersion.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,+BAA+B,CAAC;AACpD,eAAO,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,+BAA+B,CAAC;AACpD,eAAO,MAAM,UAAU,UAAU,CAAC"}
|
package/dist/packageVersion.js
CHANGED
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.pkgVersion = exports.pkgName = void 0;
|
|
10
10
|
exports.pkgName = "@fluidframework/test-utils";
|
|
11
|
-
exports.pkgVersion = "2.1.0
|
|
11
|
+
exports.pkgVersion = "2.1.0";
|
|
12
12
|
//# sourceMappingURL=packageVersion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,4BAA4B,CAAC;AACvC,QAAA,UAAU,GAAG,
|
|
1
|
+
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,4BAA4B,CAAC;AACvC,QAAA,UAAU,GAAG,OAAO,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/test-utils\";\nexport const pkgVersion = \"2.1.0\";\n"]}
|
package/dist/public.d.ts
CHANGED
package/dist/timeoutUtils.d.ts
CHANGED
|
@@ -9,47 +9,54 @@ export declare const defaultTimeoutDurationMs = 250;
|
|
|
9
9
|
/**
|
|
10
10
|
* @internal
|
|
11
11
|
*/
|
|
12
|
-
export interface
|
|
12
|
+
export interface TimeoutDurationOption {
|
|
13
13
|
/**
|
|
14
14
|
* Timeout duration in milliseconds, if it is great than 0 and not Infinity
|
|
15
15
|
* If it is undefined, then it will use test timeout if we are in side the test function
|
|
16
16
|
* Otherwise, there is no timeout
|
|
17
17
|
*/
|
|
18
18
|
durationMs?: number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
export interface TimeoutWithError extends TimeoutDurationOption {
|
|
19
24
|
reject?: true;
|
|
20
25
|
errorMsg?: string;
|
|
26
|
+
value?: never;
|
|
21
27
|
}
|
|
22
28
|
/**
|
|
23
29
|
* @internal
|
|
24
30
|
*/
|
|
25
|
-
export interface TimeoutWithValue<T = void> {
|
|
26
|
-
/**
|
|
27
|
-
* Timeout duration in milliseconds, if it is great than 0 and not Infinity
|
|
28
|
-
* If it is undefined, then it will use test timeout if we are in side the test function
|
|
29
|
-
* Otherwise, there is no timeout
|
|
30
|
-
*/
|
|
31
|
-
durationMs?: number;
|
|
31
|
+
export interface TimeoutWithValue<T = void> extends TimeoutDurationOption {
|
|
32
32
|
reject: false;
|
|
33
33
|
value: T;
|
|
34
34
|
}
|
|
35
35
|
export type PromiseExecutor<T = void> = (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void;
|
|
36
36
|
/**
|
|
37
|
-
* Wraps the given promise
|
|
38
|
-
* not resolve by then.
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
37
|
+
* Wraps the given promise with another one that will complete after a specific timeout if the original promise does
|
|
38
|
+
* not resolve by then.
|
|
39
|
+
*
|
|
40
|
+
* @remarks
|
|
41
|
+
* If used inside a mocha test, it uses the test timeout by default and completes the returned promise just before
|
|
42
|
+
* the test timeout hits, so that tests don't time out because of unpredictable awaits.
|
|
43
|
+
* In that scenario the timeout can still be overridden via `timeoutOptions` but it's recommended to use the default value.
|
|
44
|
+
*
|
|
45
|
+
* @param promise - The promise to be wrapped.
|
|
46
|
+
* @param timeoutOptions - Options that can be used to override the timeout and / or define the behavior when
|
|
47
|
+
* the promise is not fulfilled. For example, instead of rejecting the promise, resolve with a specific value.
|
|
45
48
|
* @returns A new promise that will complete when the given promise resolves or the timeout expires.
|
|
46
49
|
* @internal
|
|
47
50
|
*/
|
|
48
51
|
export declare function timeoutAwait<T = void>(promise: PromiseLike<T>, timeoutOptions?: TimeoutWithError | TimeoutWithValue<T>): Promise<T>;
|
|
49
52
|
/**
|
|
50
|
-
* Creates a promise from the given executor that will complete after a specific timeout.
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
+
* Creates a promise from the given executor that will complete after a specific timeout.
|
|
54
|
+
*
|
|
55
|
+
* @remarks
|
|
56
|
+
* If used inside a mocha test, it uses the test timeout by default and completes the returned promise just before
|
|
57
|
+
* the test timeout hits, so that tests don't time out because of unpredictable awaits.
|
|
58
|
+
* In that scenario the timeout can still be overridden via `timeoutOptions` but it's recommended to use the default value.
|
|
59
|
+
*
|
|
53
60
|
* @param executor - The executor for the promise.
|
|
54
61
|
* @param timeoutOptions - Options that can be used to override the timeout and / or define the behavior when
|
|
55
62
|
* the promise is not fulfilled. For example, instead of rejecting the promise, resolve with a specific value.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timeoutUtils.d.ts","sourceRoot":"","sources":["../src/timeoutUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH;;GAEG;AACH,eAAO,MAAM,wBAAwB,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"timeoutUtils.d.ts","sourceRoot":"","sources":["../src/timeoutUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH;;GAEG;AACH,eAAO,MAAM,wBAAwB,MAAM,CAAC;AAgG5C;;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eout {
|
|
|
50
50
|
(0, internal_1.assert)(!this.timer, "clearTimer should have been called before reset");
|
|
51
51
|
(0, internal_1.assert)(!this.deferred.isCompleted, "can't reset a completed TestTimeout");
|
|
52
52
|
// Check the test timeout setting
|
|
53
|
-
const
|
|
54
|
-
if (!(Number.isFinite(
|
|
53
|
+
const timeoutFromMochaTest = runnable.timeout();
|
|
54
|
+
if (!(Number.isFinite(timeoutFromMochaTest) && timeoutFromMochaTest > 0)) {
|
|
55
55
|
return;
|
|
56
56
|
}
|
|
57
57
|
// subtract a buffer
|
|
58
|
-
this.timeout = Math.max(
|
|
58
|
+
this.timeout = Math.max(timeoutFromMochaTest - timeBuffer, 1);
|
|
59
59
|
// Set up timer to reject near the test timeout.
|
|
60
60
|
this.timer = setTimeout(() => {
|
|
61
61
|
this.deferred.reject(this);
|
|
@@ -70,10 +70,12 @@ class TestTimeout {
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
TestTimeout.instance = new TestTimeout();
|
|
73
|
-
//
|
|
73
|
+
// Only register if we are running with mocha-test-setup loaded (that package is what sets globalThis.getMochaModule).
|
|
74
74
|
if (globalThis.getMochaModule !== undefined) {
|
|
75
|
-
//
|
|
76
|
-
//
|
|
75
|
+
// Patch the private methods resetTimeout and clearTimeout on Mocha's runnable objects so we can do the appropriate
|
|
76
|
+
// calls in TestTimeout above when the Mocha methods are called.
|
|
77
|
+
// These are not part of the public API so if Mocha changes how it works, this could break.
|
|
78
|
+
// See https://github.com/mochajs/mocha/blob/8d0ca3ed77ba8a704b2aa8b58267a084a475a51b/lib/runnable.js#L234.
|
|
77
79
|
const mochaModule = globalThis.getMochaModule();
|
|
78
80
|
const runnablePrototype = mochaModule.Runnable.prototype;
|
|
79
81
|
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
@@ -90,14 +92,17 @@ if (globalThis.getMochaModule !== undefined) {
|
|
|
90
92
|
};
|
|
91
93
|
}
|
|
92
94
|
/**
|
|
93
|
-
* Wraps the given promise
|
|
94
|
-
* not resolve by then.
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
95
|
+
* Wraps the given promise with another one that will complete after a specific timeout if the original promise does
|
|
96
|
+
* not resolve by then.
|
|
97
|
+
*
|
|
98
|
+
* @remarks
|
|
99
|
+
* If used inside a mocha test, it uses the test timeout by default and completes the returned promise just before
|
|
100
|
+
* the test timeout hits, so that tests don't time out because of unpredictable awaits.
|
|
101
|
+
* In that scenario the timeout can still be overridden via `timeoutOptions` but it's recommended to use the default value.
|
|
102
|
+
*
|
|
103
|
+
* @param promise - The promise to be wrapped.
|
|
104
|
+
* @param timeoutOptions - Options that can be used to override the timeout and / or define the behavior when
|
|
105
|
+
* the promise is not fulfilled. For example, instead of rejecting the promise, resolve with a specific value.
|
|
101
106
|
* @returns A new promise that will complete when the given promise resolves or the timeout expires.
|
|
102
107
|
* @internal
|
|
103
108
|
*/
|
|
@@ -106,9 +111,13 @@ async function timeoutAwait(promise, timeoutOptions = {}) {
|
|
|
106
111
|
}
|
|
107
112
|
exports.timeoutAwait = timeoutAwait;
|
|
108
113
|
/**
|
|
109
|
-
* Creates a promise from the given executor that will complete after a specific timeout.
|
|
110
|
-
*
|
|
111
|
-
*
|
|
114
|
+
* Creates a promise from the given executor that will complete after a specific timeout.
|
|
115
|
+
*
|
|
116
|
+
* @remarks
|
|
117
|
+
* If used inside a mocha test, it uses the test timeout by default and completes the returned promise just before
|
|
118
|
+
* the test timeout hits, so that tests don't time out because of unpredictable awaits.
|
|
119
|
+
* In that scenario the timeout can still be overridden via `timeoutOptions` but it's recommended to use the default value.
|
|
120
|
+
*
|
|
112
121
|
* @param executor - The executor for the promise.
|
|
113
122
|
* @param timeoutOptions - Options that can be used to override the timeout and / or define the behavior when
|
|
114
123
|
* the promise is not fulfilled. For example, instead of rejecting the promise, resolve with a specific value.
|
|
@@ -132,7 +141,7 @@ async function timeoutPromise(executor, timeoutOptions = {}) {
|
|
|
132
141
|
// If the rejection is because of the timeout then
|
|
133
142
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
134
143
|
const errorObject = err;
|
|
135
|
-
errorObject.message = `${timeoutOptions.errorMsg ?? "
|
|
144
|
+
errorObject.message = `${timeoutOptions.errorMsg ?? "Forcing timeout before test does"} (${currentTestTimeout.getTimeout()}ms)`;
|
|
136
145
|
throw errorObject;
|
|
137
146
|
}
|
|
138
147
|
return timeoutOptions.value;
|
package/dist/timeoutUtils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timeoutUtils.js","sourceRoot":"","sources":["../src/timeoutUtils.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAAuE;AAGvE,2CAA2C;AAC3C;;GAEG;AACU,QAAA,wBAAwB,GAAG,GAAG,CAAC;AAE5C,MAAM,UAAU,GAAG,EAAE,CAAC,CAAC,2CAA2C;AAElE,yGAAyG;AACzG,uHAAuH;AACvH,sGAAsG;AACtG,uBAAuB;AACvB,0EAA0E;AAC1E,MAAM,WAAW;IAOT,MAAM,CAAC,KAAK,CAAC,QAAwB;QAC3C,WAAW,CAAC,KAAK,EAAE,CAAC;QACpB,WAAW,CAAC,QAAQ,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;IAC3C,CAAC;IAEM,MAAM,CAAC,KAAK;QAClB,IAAI,WAAW,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC;YACnC,WAAW,CAAC,QAAQ,GAAG,IAAI,WAAW,EAAE,CAAC;QAC1C,CAAC;aAAM,CAAC;YACP,WAAW,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC;QACnC,CAAC;IACF,CAAC;IAEM,MAAM,CAAC,WAAW;QACxB,OAAO,WAAW,CAAC,QAAQ,CAAC;IAC7B,CAAC;IAEM,KAAK,CAAC,UAAU;QACtB,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC;IAC9B,CAAC;IAEM,UAAU;Q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W,CAAC,OAAO,KAAK,OAAO,KAAK,CAAC;YAC9D,MAAM,CAAC,GAAG,CAAC,CAAC;QACb,CAAC,CAAC;QACF,MAAM,KAAK,GAAG,UAAU,CACvB,GAAG,EAAE,CACJ,cAAc,CAAC,MAAM,KAAK,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,iBAAiB,EAAE,EACtF,OAAO,CACP,CAAC;QAEF,QAAQ,CACP,CAAC,KAAK,EAAE,EAAE;YACT,YAAY,CAAC,KAAK,CAAC,CAAC;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"]}
|
|
1
|
+
{"version":3,"file":"timeoutUtils.js","sourceRoot":"","sources":["../src/timeoutUtils.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAAuE;AAGvE,2CAA2C;AAC3C;;GAEG;AACU,QAAA,wBAAwB,GAAG,GAAG,CAAC;AAE5C,MAAM,UAAU,GAAG,EAAE,CAAC,CAAC,2CAA2C;AAElE,yGAAyG;AACzG,uHAAuH;AACvH,sGAAsG;AACtG,uBAAuB;AACvB,0EAA0E;AAC1E,MAAM,WAAW;IAOT,MAAM,CAAC,KAAK,CAAC,QAAwB;QAC3C,WAAW,CAAC,KAAK,EAAE,CAAC;QACpB,WAAW,CAAC,QAAQ,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;IAC3C,CAAC;IAEM,MAAM,CAAC,KAAK;QAClB,IAAI,WAAW,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC;YACnC,WAAW,CAAC,QAAQ,GAAG,IAAI,WAAW,EAAE,CAAC;QAC1C,CAAC;aAAM,CAAC;YACP,WAAW,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC;QACnC,CAAC;IACF,CAAC;IAEM,MAAM,CAAC,WAAW;QACxB,OAAO,WAAW,CAAC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OAAO,CAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACzC,MAAM,iBAAiB,GAAG,GAAG,EAAE;YAC9B,oEAAoE;YACpE,MAAM,WAAW,GAAG,GAAI,CAAC;YACzB,WAAW,CAAC,OAAO,GAAG,GAAG,WAAW,CAAC,OAAO,KAAK,OAAO,KAAK,CAAC;YAC9D,MAAM,CAAC,GAAG,CAAC,CAAC;QACb,CAAC,CAAC;QACF,MAAM,KAAK,GAAG,UAAU,CACvB,GAAG,EAAE,CACJ,cAAc,CAAC,MAAM,KAAK,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,iBAAiB,EAAE,EACtF,OAAO,CACP,CAAC;QAEF,QAAQ,CACP,CAAC,KAAK,EAAE,EAAE;YACT,YAAY,CAAC,KAAK,CAAC,CAAC;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 timeoutFromMochaTest = runnable.timeout();\n\t\tif (!(Number.isFinite(timeoutFromMochaTest) && timeoutFromMochaTest > 0)) {\n\t\t\treturn;\n\t\t}\n\n\t\t// subtract a buffer\n\t\tthis.timeout = Math.max(timeoutFromMochaTest - 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 (that package is what sets globalThis.getMochaModule).\nif (globalThis.getMochaModule !== undefined) {\n\t// Patch the private methods resetTimeout and clearTimeout on Mocha's runnable objects so we can do the appropriate\n\t// calls in TestTimeout above when the Mocha methods are called.\n\t// These are not part of the public API so if Mocha changes how it works, this could break.\n\t// See https://github.com/mochajs/mocha/blob/8d0ca3ed77ba8a704b2aa8b58267a084a475a51b/lib/runnable.js#L234.\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 TimeoutDurationOption {\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}\n\n/**\n * @internal\n */\nexport interface TimeoutWithError extends TimeoutDurationOption {\n\treject?: true;\n\terrorMsg?: string;\n\t// Since there are no required properties, this type explicitly\n\t// rejects `value` to avoid confusion with TimeoutWithValue.\n\tvalue?: never;\n}\n\n/**\n * @internal\n */\nexport interface TimeoutWithValue<T = void> extends TimeoutDurationOption {\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 with another one that will complete after a specific timeout if the original promise does\n * not resolve by then.\n *\n * @remarks\n * If used inside a mocha test, it uses the test timeout by default and completes the returned promise just before\n * the test timeout hits, so that tests don't time out because of unpredictable awaits.\n * In that scenario the timeout can still be overridden via `timeoutOptions` but it's recommended to use the default value.\n *\n * @param promise - The promise to be wrapped.\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 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.\n *\n * @remarks\n * If used inside a mocha test, it uses the test timeout by default and completes the returned promise just before\n * the test timeout hits, so that tests don't time out because of unpredictable awaits.\n * In that scenario the timeout can still be overridden via `timeoutOptions` but it's recommended to use the default value.\n *\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 ?? \"Forcing timeout before test does\"\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"]}
|
package/internal.d.ts
CHANGED
package/legacy.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
/*
|
|
7
7
|
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
|
8
|
-
* Generated by "flub generate entrypoints" in @
|
|
8
|
+
* Generated by "flub generate entrypoints" in @fluid-tools/build-cli.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
export * from "./lib/legacy.js";
|
package/lib/index.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export { createTestContainerRuntimeFactory, TestContainerRuntimeFactory, } from
|
|
|
13
13
|
export { ChannelFactoryRegistry, TestFluidObject, TestFluidObjectFactory, } from "./testFluidObject.js";
|
|
14
14
|
export { createDocumentId, DataObjectFactoryType, EventAndErrorTrackingLogger, type IEventAndErrorTrackingLogger, getUnexpectedLogErrorException, IDocumentIdStrategy, IOpProcessingController, ITestContainerConfig, ITestObjectProvider, TestObjectProvider, TestObjectProviderWithVersionedLoad, } from "./testObjectProvider.js";
|
|
15
15
|
export { createSummarizer, createSummarizerCore, createSummarizerFromFactory, summarizeNow, SummaryInfo, } from "./TestSummaryUtils.js";
|
|
16
|
-
export { defaultTimeoutDurationMs, timeoutAwait, timeoutPromise, TimeoutWithError, TimeoutWithValue, } from "./timeoutUtils.js";
|
|
16
|
+
export { defaultTimeoutDurationMs, timeoutAwait, timeoutPromise, type TimeoutDurationOption, type TimeoutWithError, type TimeoutWithValue, } from "./timeoutUtils.js";
|
|
17
17
|
export { waitForContainerConnection, getContainerEntryPointBackCompat, getDataStoreEntryPointBackCompat, } from "./containerUtils.js";
|
|
18
18
|
export { createContainerRuntimeFactoryWithDefaultDataStore } from "./testContainerRuntimeFactoryWithDefaultDataStore.js";
|
|
19
19
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,mBAAmB,EACnB,0BAA0B,EAC1B,0BAA0B,GAC1B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAC5E,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE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B,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,EAAE,wBAAwB,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACjF,OAAO,EACN,iCAAiC,EACjC,2BAA2B,GAC3B,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACN,sBAAsB,EACtB,eAAe,EACf,sBAAsB,GACtB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACN,gBAAgB,EAChB,qBAAqB,EACrB,2BAA2B,EAC3B,KAAK,4BAA4B,EACjC,8BAA8B,EAC9B,mBAAmB,EACnB,uBAAuB,EACvB,oBAAoB,EACpB,mBAAmB,EACnB,kBAAkB,EAClB,mCAAmC,GACnC,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACN,gBAAgB,EAChB,oBAAoB,EACpB,2BAA2B,EAC3B,YAAY,EACZ,WAAW,GACX,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACN,wBAAwB,EACxB,YAAY,EACZ,cAAc,EACd,KAAK,qBAAqB,EAC1B,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,GACrB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACN,0BAA0B,EAC1B,gCAAgC,EAChC,gCAAgC,GAChC,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,iDAAiD,EAAE,MAAM,sDAAsD,CAAC"}
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,mBAAmB,EACnB,0BAA0B,EAC1B,0BAA0B,GAC1B,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAEN,eAAe,GAEf,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,wBAAwB,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAC1E,OAAO,EAAE,sBAAs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pB,2BAA2B,EAC3B,YAAY,GAEZ,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACN,wBAAwB,EACxB,YAAY,EACZ,cAAc,GAId,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACN,0BAA0B,EAC1B,gCAAgC,EAChC,gCAAgC,GAChC,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,iDAAiD,EAAE,MAAM,sDAAsD,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport {\n\twrapDocumentService,\n\twrapDocumentServiceFactory,\n\twrapDocumentStorageService,\n} from \"./DriverWrappers.js\";\nexport { IProvideTestFluidObject, ITestFluidObject } from \"./interfaces.js\";\nexport { LoaderContainerTracker } from \"./loaderContainerTracker.js\";\nexport {\n\tfluidEntryPoint,\n\tLocalCodeLoader,\n\tSupportedExportInterfaces,\n} from \"./localCodeLoader.js\";\nexport { createAndAttachContainer, createLoader } from \"./localLoader.js\";\nexport { retryWithEventualValue } from \"./retry.js\";\nexport { createTestConfigProvider, ITestConfigProvider } from \"./TestConfigs.js\";\nexport {\n\tcreateTestContainerRuntimeFactory,\n\tTestContainerRuntimeFactory,\n} from \"./testContainerRuntimeFactory.js\";\nexport {\n\tChannelFactoryRegistry,\n\tTestFluidObject,\n\tTestFluidObjectFactory,\n} from \"./testFluidObject.js\";\nexport {\n\tcreateDocumentId,\n\tDataObjectFactoryType,\n\tEventAndErrorTrackingLogger,\n\ttype IEventAndErrorTrackingLogger,\n\tgetUnexpectedLogErrorException,\n\tIDocumentIdStrategy,\n\tIOpProcessingController,\n\tITestContainerConfig,\n\tITestObjectProvider,\n\tTestObjectProvider,\n\tTestObjectProviderWithVersionedLoad,\n} from \"./testObjectProvider.js\";\nexport {\n\tcreateSummarizer,\n\tcreateSummarizerCore,\n\tcreateSummarizerFromFactory,\n\tsummarizeNow,\n\tSummaryInfo,\n} from \"./TestSummaryUtils.js\";\nexport {\n\tdefaultTimeoutDurationMs,\n\ttimeoutAwait,\n\ttimeoutPromise,\n\ttype TimeoutDurationOption,\n\ttype TimeoutWithError,\n\ttype TimeoutWithValue,\n} from \"./timeoutUtils.js\";\nexport {\n\twaitForContainerConnection,\n\tgetContainerEntryPointBackCompat,\n\tgetDataStoreEntryPointBackCompat,\n} from \"./containerUtils.js\";\nexport { createContainerRuntimeFactoryWithDefaultDataStore } from \"./testContainerRuntimeFactoryWithDefaultDataStore.js\";\n"]}
|
package/lib/legacy.d.ts
CHANGED
package/lib/packageVersion.d.ts
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
|
|
6
6
|
*/
|
|
7
7
|
export declare const pkgName = "@fluidframework/test-utils";
|
|
8
|
-
export declare const pkgVersion = "2.1.0
|
|
8
|
+
export declare const pkgVersion = "2.1.0";
|
|
9
9
|
//# sourceMappingURL=packageVersion.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,+BAA+B,CAAC;AACpD,eAAO,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,+BAA+B,CAAC;AACpD,eAAO,MAAM,UAAU,UAAU,CAAC"}
|
package/lib/packageVersion.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,4BAA4B,CAAC;AACpD,MAAM,CAAC,MAAM,UAAU,GAAG,
|
|
1
|
+
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,4BAA4B,CAAC;AACpD,MAAM,CAAC,MAAM,UAAU,GAAG,OAAO,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/test-utils\";\nexport const pkgVersion = \"2.1.0\";\n"]}
|
package/lib/public.d.ts
CHANGED
package/lib/timeoutUtils.d.ts
CHANGED
|
@@ -9,47 +9,54 @@ export declare const defaultTimeoutDurationMs = 250;
|
|
|
9
9
|
/**
|
|
10
10
|
* @internal
|
|
11
11
|
*/
|
|
12
|
-
export interface
|
|
12
|
+
export interface TimeoutDurationOption {
|
|
13
13
|
/**
|
|
14
14
|
* Timeout duration in milliseconds, if it is great than 0 and not Infinity
|
|
15
15
|
* If it is undefined, then it will use test timeout if we are in side the test function
|
|
16
16
|
* Otherwise, there is no timeout
|
|
17
17
|
*/
|
|
18
18
|
durationMs?: number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
export interface TimeoutWithError extends TimeoutDurationOption {
|
|
19
24
|
reject?: true;
|
|
20
25
|
errorMsg?: string;
|
|
26
|
+
value?: never;
|
|
21
27
|
}
|
|
22
28
|
/**
|
|
23
29
|
* @internal
|
|
24
30
|
*/
|
|
25
|
-
export interface TimeoutWithValue<T = void> {
|
|
26
|
-
/**
|
|
27
|
-
* Timeout duration in milliseconds, if it is great than 0 and not Infinity
|
|
28
|
-
* If it is undefined, then it will use test timeout if we are in side the test function
|
|
29
|
-
* Otherwise, there is no timeout
|
|
30
|
-
*/
|
|
31
|
-
durationMs?: number;
|
|
31
|
+
export interface TimeoutWithValue<T = void> extends TimeoutDurationOption {
|
|
32
32
|
reject: false;
|
|
33
33
|
value: T;
|
|
34
34
|
}
|
|
35
35
|
export type PromiseExecutor<T = void> = (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void;
|
|
36
36
|
/**
|
|
37
|
-
* Wraps the given promise
|
|
38
|
-
* not resolve by then.
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
37
|
+
* Wraps the given promise with another one that will complete after a specific timeout if the original promise does
|
|
38
|
+
* not resolve by then.
|
|
39
|
+
*
|
|
40
|
+
* @remarks
|
|
41
|
+
* If used inside a mocha test, it uses the test timeout by default and completes the returned promise just before
|
|
42
|
+
* the test timeout hits, so that tests don't time out because of unpredictable awaits.
|
|
43
|
+
* In that scenario the timeout can still be overridden via `timeoutOptions` but it's recommended to use the default value.
|
|
44
|
+
*
|
|
45
|
+
* @param promise - The promise to be wrapped.
|
|
46
|
+
* @param timeoutOptions - Options that can be used to override the timeout and / or define the behavior when
|
|
47
|
+
* the promise is not fulfilled. For example, instead of rejecting the promise, resolve with a specific value.
|
|
45
48
|
* @returns A new promise that will complete when the given promise resolves or the timeout expires.
|
|
46
49
|
* @internal
|
|
47
50
|
*/
|
|
48
51
|
export declare function timeoutAwait<T = void>(promise: PromiseLike<T>, timeoutOptions?: TimeoutWithError | TimeoutWithValue<T>): Promise<T>;
|
|
49
52
|
/**
|
|
50
|
-
* Creates a promise from the given executor that will complete after a specific timeout.
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
+
* Creates a promise from the given executor that will complete after a specific timeout.
|
|
54
|
+
*
|
|
55
|
+
* @remarks
|
|
56
|
+
* If used inside a mocha test, it uses the test timeout by default and completes the returned promise just before
|
|
57
|
+
* the test timeout hits, so that tests don't time out because of unpredictable awaits.
|
|
58
|
+
* In that scenario the timeout can still be overridden via `timeoutOptions` but it's recommended to use the default value.
|
|
59
|
+
*
|
|
53
60
|
* @param executor - The executor for the promise.
|
|
54
61
|
* @param timeoutOptions - Options that can be used to override the timeout and / or define the behavior when
|
|
55
62
|
* the promise is not fulfilled. For example, instead of rejecting the promise, resolve with a specific value.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timeoutUtils.d.ts","sourceRoot":"","sources":["../src/timeoutUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH;;GAEG;AACH,eAAO,MAAM,wBAAwB,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"timeoutUtils.d.ts","sourceRoot":"","sources":["../src/timeoutUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH;;GAEG;AACH,eAAO,MAAM,wBAAwB,MAAM,CAAC;AAgG5C;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACrC;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAiB,SAAQ,qBAAqB;IAC9D,MAAM,CAAC,EAAE,IAAI,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAGlB,KAAK,CAAC,EAAE,KAAK,CAAC;CACd;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB,CAAC,CAAC,GAAG,IAAI,CAAE,SAAQ,qBAAqB;IACxE,MAAM,EAAE,KAAK,CAAC;IACd,KAAK,EAAE,CAAC,CAAC;CACT;AAED,MAAM,MAAM,eAAe,CAAC,CAAC,GAAG,IAAI,IAAI,CACvC,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,KAAK,IAAI,EAC5C,MAAM,EAAE,CAAC,MAAM,CAAC,EAAE,GAAG,KAAK,IAAI,KAC1B,IAAI,CAAC;AAEV;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,YAAY,CAAC,CAAC,GAAG,IAAI,EAC1C,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC,EACvB,cAAc,GAAE,gBAAgB,GAAG,gBAAgB,CAAC,CAAC,CAAM,GACzD,OAAO,CAAC,CAAC,CAAC,CAEZ;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,cAAc,CAAC,CAAC,GAAG,IAAI,EAC5C,QAAQ,EAAE,CACT,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,KAAK,IAAI,EAC5C,MAAM,EAAE,CAAC,MAAM,CAAC,EAAE,GAAG,KAAK,IAAI,KAC1B,IAAI,EACT,cAAc,GAAE,gBAAgB,GAAG,gBAAgB,CAAC,CAAC,CAAM,GACzD,OAAO,CAAC,CAAC,CAAC,CA6BZ"}
|
package/lib/timeoutUtils.js
CHANGED
|
@@ -47,12 +47,12 @@ class TestTimeout {
|
|
|
47
47
|
assert(!this.timer, "clearTimer should have been called before reset");
|
|
48
48
|
assert(!this.deferred.isCompleted, "can't reset a completed TestTimeout");
|
|
49
49
|
// Check the test timeout setting
|
|
50
|
-
const
|
|
51
|
-
if (!(Number.isFinite(
|
|
50
|
+
const timeoutFromMochaTest = runnable.timeout();
|
|
51
|
+
if (!(Number.isFinite(timeoutFromMochaTest) && timeoutFromMochaTest > 0)) {
|
|
52
52
|
return;
|
|
53
53
|
}
|
|
54
54
|
// subtract a buffer
|
|
55
|
-
this.timeout = Math.max(
|
|
55
|
+
this.timeout = Math.max(timeoutFromMochaTest - timeBuffer, 1);
|
|
56
56
|
// Set up timer to reject near the test timeout.
|
|
57
57
|
this.timer = setTimeout(() => {
|
|
58
58
|
this.deferred.reject(this);
|
|
@@ -67,10 +67,12 @@ class TestTimeout {
|
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
TestTimeout.instance = new TestTimeout();
|
|
70
|
-
//
|
|
70
|
+
// Only register if we are running with mocha-test-setup loaded (that package is what sets globalThis.getMochaModule).
|
|
71
71
|
if (globalThis.getMochaModule !== undefined) {
|
|
72
|
-
//
|
|
73
|
-
//
|
|
72
|
+
// Patch the private methods resetTimeout and clearTimeout on Mocha's runnable objects so we can do the appropriate
|
|
73
|
+
// calls in TestTimeout above when the Mocha methods are called.
|
|
74
|
+
// These are not part of the public API so if Mocha changes how it works, this could break.
|
|
75
|
+
// See https://github.com/mochajs/mocha/blob/8d0ca3ed77ba8a704b2aa8b58267a084a475a51b/lib/runnable.js#L234.
|
|
74
76
|
const mochaModule = globalThis.getMochaModule();
|
|
75
77
|
const runnablePrototype = mochaModule.Runnable.prototype;
|
|
76
78
|
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
@@ -87,14 +89,17 @@ if (globalThis.getMochaModule !== undefined) {
|
|
|
87
89
|
};
|
|
88
90
|
}
|
|
89
91
|
/**
|
|
90
|
-
* Wraps the given promise
|
|
91
|
-
* not resolve by then.
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
92
|
+
* Wraps the given promise with another one that will complete after a specific timeout if the original promise does
|
|
93
|
+
* not resolve by then.
|
|
94
|
+
*
|
|
95
|
+
* @remarks
|
|
96
|
+
* If used inside a mocha test, it uses the test timeout by default and completes the returned promise just before
|
|
97
|
+
* the test timeout hits, so that tests don't time out because of unpredictable awaits.
|
|
98
|
+
* In that scenario the timeout can still be overridden via `timeoutOptions` but it's recommended to use the default value.
|
|
99
|
+
*
|
|
100
|
+
* @param promise - The promise to be wrapped.
|
|
101
|
+
* @param timeoutOptions - Options that can be used to override the timeout and / or define the behavior when
|
|
102
|
+
* the promise is not fulfilled. For example, instead of rejecting the promise, resolve with a specific value.
|
|
98
103
|
* @returns A new promise that will complete when the given promise resolves or the timeout expires.
|
|
99
104
|
* @internal
|
|
100
105
|
*/
|
|
@@ -102,9 +107,13 @@ export async function timeoutAwait(promise, timeoutOptions = {}) {
|
|
|
102
107
|
return Promise.race([promise, timeoutPromise(() => { }, timeoutOptions)]);
|
|
103
108
|
}
|
|
104
109
|
/**
|
|
105
|
-
* Creates a promise from the given executor that will complete after a specific timeout.
|
|
106
|
-
*
|
|
107
|
-
*
|
|
110
|
+
* Creates a promise from the given executor that will complete after a specific timeout.
|
|
111
|
+
*
|
|
112
|
+
* @remarks
|
|
113
|
+
* If used inside a mocha test, it uses the test timeout by default and completes the returned promise just before
|
|
114
|
+
* the test timeout hits, so that tests don't time out because of unpredictable awaits.
|
|
115
|
+
* In that scenario the timeout can still be overridden via `timeoutOptions` but it's recommended to use the default value.
|
|
116
|
+
*
|
|
108
117
|
* @param executor - The executor for the promise.
|
|
109
118
|
* @param timeoutOptions - Options that can be used to override the timeout and / or define the behavior when
|
|
110
119
|
* the promise is not fulfilled. For example, instead of rejecting the promise, resolve with a specific value.
|
|
@@ -128,7 +137,7 @@ export async function timeoutPromise(executor, timeoutOptions = {}) {
|
|
|
128
137
|
// If the rejection is because of the timeout then
|
|
129
138
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
130
139
|
const errorObject = err;
|
|
131
|
-
errorObject.message = `${timeoutOptions.errorMsg ?? "
|
|
140
|
+
errorObject.message = `${timeoutOptions.errorMsg ?? "Forcing timeout before test does"} (${currentTestTimeout.getTimeout()}ms)`;
|
|
132
141
|
throw errorObject;
|
|
133
142
|
}
|
|
134
143
|
return timeoutOptions.value;
|
package/lib/timeoutUtils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timeoutUtils.js","sourceRoot":"","sources":["../src/timeoutUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,qCAAqC,CAAC;AAGvE,2CAA2C;AAC3C;;GAEG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,GAAG,CAAC;AAE5C,MAAM,UAAU,GAAG,EAAE,CAAC,CAAC,2CAA2C;AAElE,yGAAyG;AACzG,uHAAuH;AACvH,sGAAsG;AACtG,uBAAuB;AACvB,0EAA0E;AAC1E,MAAM,WAAW;IAOT,MAAM,CAAC,KAAK,CAAC,QAAwB;QAC3C,WAAW,CAAC,KAAK,EAAE,CAAC;QACpB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BAAiB,CAC/B,QAGS,EACT,cAAsD,EACtD,GAAsB;IAEtB,MAAM,OAAO,GAAG,cAAc,CAAC,UAAU,IAAI,CAAC,CAAC;IAC/C,IAAI,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;QAC/C,OAAO,IAAI,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC9B,CAAC;IAED,OAAO,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACzC,MAAM,iBAAiB,GAAG,GAAG,EAAE;YAC9B,oEAAoE;YACpE,MAAM,WAAW,GAAG,GAAI,CAAC;YACzB,WAAW,CAAC,OAAO,GAAG,GAAG,WAAW,CAAC,OAAO,KAAK,OAAO,KAAK,CAAC;YAC9D,MAAM,CAAC,GAAG,CAAC,CAAC;QACb,CAAC,CAAC;QACF,MAAM,KAAK,GAAG,UAAU,CACvB,GAAG,EAAE,CACJ,cAAc,CAAC,MAAM,KAAK,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,iBAAiB,EAAE,EACtF,OAAO,CACP,CAAC;QAEF,QAAQ,CACP,CAAC,KAAK,EAAE,EAAE;YACT,YAAY,CAAC,KAAK,CAAC,CAAC;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"]}
|
|
1
|
+
{"version":3,"file":"timeoutUtils.js","sourceRoot":"","sources":["../src/timeoutUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,qCAAqC,CAAC;AAGvE,2CAA2C;AAC3C;;GAEG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,GAAG,CAAC;AAE5C,MAAM,UAAU,GAAG,EAAE,CAAC,CAAC,2CAA2C;AAEl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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 timeoutFromMochaTest = runnable.timeout();\n\t\tif (!(Number.isFinite(timeoutFromMochaTest) && timeoutFromMochaTest > 0)) {\n\t\t\treturn;\n\t\t}\n\n\t\t// subtract a buffer\n\t\tthis.timeout = Math.max(timeoutFromMochaTest - 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 (that package is what sets globalThis.getMochaModule).\nif (globalThis.getMochaModule !== undefined) {\n\t// Patch the private methods resetTimeout and clearTimeout on Mocha's runnable objects so we can do the appropriate\n\t// calls in TestTimeout above when the Mocha methods are called.\n\t// These are not part of the public API so if Mocha changes how it works, this could break.\n\t// See https://github.com/mochajs/mocha/blob/8d0ca3ed77ba8a704b2aa8b58267a084a475a51b/lib/runnable.js#L234.\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 TimeoutDurationOption {\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}\n\n/**\n * @internal\n */\nexport interface TimeoutWithError extends TimeoutDurationOption {\n\treject?: true;\n\terrorMsg?: string;\n\t// Since there are no required properties, this type explicitly\n\t// rejects `value` to avoid confusion with TimeoutWithValue.\n\tvalue?: never;\n}\n\n/**\n * @internal\n */\nexport interface TimeoutWithValue<T = void> extends TimeoutDurationOption {\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 with another one that will complete after a specific timeout if the original promise does\n * not resolve by then.\n *\n * @remarks\n * If used inside a mocha test, it uses the test timeout by default and completes the returned promise just before\n * the test timeout hits, so that tests don't time out because of unpredictable awaits.\n * In that scenario the timeout can still be overridden via `timeoutOptions` but it's recommended to use the default value.\n *\n * @param promise - The promise to be wrapped.\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 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.\n *\n * @remarks\n * If used inside a mocha test, it uses the test timeout by default and completes the returned promise just before\n * the test timeout hits, so that tests don't time out because of unpredictable awaits.\n * In that scenario the timeout can still be overridden via `timeoutOptions` but it's recommended to use the default value.\n *\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 ?? \"Forcing timeout before test does\"\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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluidframework/test-utils",
|
|
3
|
-
"version": "2.1.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Utilities for Fluid tests",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": {
|
|
@@ -67,25 +67,25 @@
|
|
|
67
67
|
"temp-directory": "nyc/.nyc_output"
|
|
68
68
|
},
|
|
69
69
|
"dependencies": {
|
|
70
|
-
"@fluid-internal/test-driver-definitions": "2.1.0
|
|
71
|
-
"@fluidframework/aqueduct": "2.1.0
|
|
72
|
-
"@fluidframework/container-definitions": "2.1.0
|
|
73
|
-
"@fluidframework/container-loader": "2.1.0
|
|
74
|
-
"@fluidframework/container-runtime": "2.1.0
|
|
75
|
-
"@fluidframework/container-runtime-definitions": "2.1.0
|
|
76
|
-
"@fluidframework/core-interfaces": "2.1.0
|
|
77
|
-
"@fluidframework/core-utils": "2.1.0
|
|
78
|
-
"@fluidframework/datastore": "2.1.0
|
|
79
|
-
"@fluidframework/datastore-definitions": "2.1.0
|
|
80
|
-
"@fluidframework/driver-definitions": "2.1.0
|
|
81
|
-
"@fluidframework/driver-utils": "2.1.0
|
|
82
|
-
"@fluidframework/local-driver": "2.1.0
|
|
83
|
-
"@fluidframework/map": "2.1.0
|
|
84
|
-
"@fluidframework/request-handler": "2.1.0
|
|
85
|
-
"@fluidframework/routerlicious-driver": "2.1.0
|
|
86
|
-
"@fluidframework/runtime-definitions": "2.1.0
|
|
87
|
-
"@fluidframework/runtime-utils": "2.1.0
|
|
88
|
-
"@fluidframework/telemetry-utils": "2.1.0
|
|
70
|
+
"@fluid-internal/test-driver-definitions": "~2.1.0",
|
|
71
|
+
"@fluidframework/aqueduct": "~2.1.0",
|
|
72
|
+
"@fluidframework/container-definitions": "~2.1.0",
|
|
73
|
+
"@fluidframework/container-loader": "~2.1.0",
|
|
74
|
+
"@fluidframework/container-runtime": "~2.1.0",
|
|
75
|
+
"@fluidframework/container-runtime-definitions": "~2.1.0",
|
|
76
|
+
"@fluidframework/core-interfaces": "~2.1.0",
|
|
77
|
+
"@fluidframework/core-utils": "~2.1.0",
|
|
78
|
+
"@fluidframework/datastore": "~2.1.0",
|
|
79
|
+
"@fluidframework/datastore-definitions": "~2.1.0",
|
|
80
|
+
"@fluidframework/driver-definitions": "~2.1.0",
|
|
81
|
+
"@fluidframework/driver-utils": "~2.1.0",
|
|
82
|
+
"@fluidframework/local-driver": "~2.1.0",
|
|
83
|
+
"@fluidframework/map": "~2.1.0",
|
|
84
|
+
"@fluidframework/request-handler": "~2.1.0",
|
|
85
|
+
"@fluidframework/routerlicious-driver": "~2.1.0",
|
|
86
|
+
"@fluidframework/runtime-definitions": "~2.1.0",
|
|
87
|
+
"@fluidframework/runtime-utils": "~2.1.0",
|
|
88
|
+
"@fluidframework/telemetry-utils": "~2.1.0",
|
|
89
89
|
"best-random": "^1.0.0",
|
|
90
90
|
"debug": "^4.3.4",
|
|
91
91
|
"mocha": "^10.2.0",
|
|
@@ -93,13 +93,13 @@
|
|
|
93
93
|
},
|
|
94
94
|
"devDependencies": {
|
|
95
95
|
"@arethetypeswrong/cli": "^0.15.2",
|
|
96
|
-
"@biomejs/biome": "
|
|
97
|
-
"@fluid-internal/mocha-test-setup": "2.1.0
|
|
98
|
-
"@fluid-tools/build-cli": "^0.
|
|
96
|
+
"@biomejs/biome": "~1.8.3",
|
|
97
|
+
"@fluid-internal/mocha-test-setup": "~2.1.0",
|
|
98
|
+
"@fluid-tools/build-cli": "^0.41.0",
|
|
99
99
|
"@fluidframework/build-common": "^2.0.3",
|
|
100
|
-
"@fluidframework/build-tools": "^0.
|
|
100
|
+
"@fluidframework/build-tools": "^0.41.0",
|
|
101
101
|
"@fluidframework/eslint-config-fluid": "^5.3.0",
|
|
102
|
-
"@fluidframework/test-utils-previous": "npm:@fluidframework/test-utils@2.0.0
|
|
102
|
+
"@fluidframework/test-utils-previous": "npm:@fluidframework/test-utils@2.0.0",
|
|
103
103
|
"@microsoft/api-extractor": "^7.45.1",
|
|
104
104
|
"@types/debug": "^4.1.5",
|
|
105
105
|
"@types/diff": "^3.5.1",
|
|
@@ -127,18 +127,19 @@
|
|
|
127
127
|
"api-extractor:commonjs": "flub generate entrypoints --outDir ./dist",
|
|
128
128
|
"api-extractor:esnext": "flub generate entrypoints --outDir ./lib --node10TypeCompat",
|
|
129
129
|
"build": "fluid-build . --task build",
|
|
130
|
+
"build:api-reports": "concurrently \"npm:build:api-reports:*\"",
|
|
131
|
+
"build:api-reports:current": "api-extractor run --local --config api-extractor/api-extractor.current.json",
|
|
132
|
+
"build:api-reports:legacy": "api-extractor run --local --config api-extractor/api-extractor.legacy.json",
|
|
130
133
|
"build:compile": "fluid-build . --task compile",
|
|
131
134
|
"build:compile:min": "npm run build:compile",
|
|
132
|
-
"build:docs": "
|
|
133
|
-
"build:docs:current": "api-extractor run --local",
|
|
134
|
-
"build:docs:legacy": "api-extractor run --local --config api-extractor/api-extractor.legacy.json",
|
|
135
|
+
"build:docs": "api-extractor run --local",
|
|
135
136
|
"build:esnext": "tsc --project ./tsconfig.json",
|
|
136
137
|
"build:genver": "gen-version",
|
|
137
138
|
"build:test": "npm run build:test:esm && npm run build:test:cjs",
|
|
138
139
|
"build:test:cjs": "fluid-tsc commonjs --project ./src/test/tsconfig.cjs.json",
|
|
139
140
|
"build:test:esm": "tsc --project ./src/test/tsconfig.json",
|
|
140
141
|
"check:are-the-types-wrong": "attw --pack .",
|
|
141
|
-
"check:biome": "biome check .
|
|
142
|
+
"check:biome": "biome check .",
|
|
142
143
|
"check:exports": "concurrently \"npm:check:exports:*\"",
|
|
143
144
|
"check:exports:bundle-release-tags": "api-extractor run --config api-extractor/api-extractor-lint-bundle.json",
|
|
144
145
|
"check:exports:cjs:legacy": "api-extractor run --config api-extractor/api-extractor-lint-legacy.cjs.json",
|
|
@@ -147,14 +148,15 @@
|
|
|
147
148
|
"check:exports:esm:public": "api-extractor run --config api-extractor/api-extractor-lint-public.esm.json",
|
|
148
149
|
"check:format": "npm run check:biome",
|
|
149
150
|
"check:prettier": "prettier --check . --cache --ignore-path ../../../.prettierignore",
|
|
150
|
-
"ci:build:
|
|
151
|
-
"ci:build:
|
|
152
|
-
"ci:build:
|
|
151
|
+
"ci:build:api-reports": "concurrently \"npm:ci:build:api-reports:*\"",
|
|
152
|
+
"ci:build:api-reports:current": "api-extractor run --config api-extractor/api-extractor.current.json",
|
|
153
|
+
"ci:build:api-reports:legacy": "api-extractor run --config api-extractor/api-extractor.legacy.json",
|
|
154
|
+
"ci:build:docs": "api-extractor run",
|
|
153
155
|
"clean": "rimraf --glob dist lib \"*.d.ts\" \"**/*.tsbuildinfo\" \"**/*.build.log\" _api-extractor-temp nyc",
|
|
154
156
|
"eslint": "eslint --format stylish src",
|
|
155
157
|
"eslint:fix": "eslint --format stylish src --fix --fix-type problem,suggestion,layout",
|
|
156
158
|
"format": "npm run format:biome",
|
|
157
|
-
"format:biome": "biome check . --
|
|
159
|
+
"format:biome": "biome check . --write",
|
|
158
160
|
"format:prettier": "prettier --write . --cache --ignore-path ../../../.prettierignore",
|
|
159
161
|
"lint": "fluid-build . --task lint",
|
|
160
162
|
"lint:fix": "fluid-build . --task eslint:fix --task format",
|
package/src/index.ts
CHANGED
|
@@ -51,8 +51,9 @@ export {
|
|
|
51
51
|
defaultTimeoutDurationMs,
|
|
52
52
|
timeoutAwait,
|
|
53
53
|
timeoutPromise,
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
type TimeoutDurationOption,
|
|
55
|
+
type TimeoutWithError,
|
|
56
|
+
type TimeoutWithValue,
|
|
56
57
|
} from "./timeoutUtils.js";
|
|
57
58
|
export {
|
|
58
59
|
waitForContainerConnection,
|
package/src/packageVersion.ts
CHANGED
package/src/timeoutUtils.ts
CHANGED
|
@@ -62,13 +62,13 @@ class TestTimeout {
|
|
|
62
62
|
assert(!this.deferred.isCompleted, "can't reset a completed TestTimeout");
|
|
63
63
|
|
|
64
64
|
// Check the test timeout setting
|
|
65
|
-
const
|
|
66
|
-
if (!(Number.isFinite(
|
|
65
|
+
const timeoutFromMochaTest = runnable.timeout();
|
|
66
|
+
if (!(Number.isFinite(timeoutFromMochaTest) && timeoutFromMochaTest > 0)) {
|
|
67
67
|
return;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
// subtract a buffer
|
|
71
|
-
this.timeout = Math.max(
|
|
71
|
+
this.timeout = Math.max(timeoutFromMochaTest - timeBuffer, 1);
|
|
72
72
|
|
|
73
73
|
// Set up timer to reject near the test timeout.
|
|
74
74
|
this.timer = setTimeout(() => {
|
|
@@ -84,10 +84,12 @@ class TestTimeout {
|
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
//
|
|
87
|
+
// Only register if we are running with mocha-test-setup loaded (that package is what sets globalThis.getMochaModule).
|
|
88
88
|
if (globalThis.getMochaModule !== undefined) {
|
|
89
|
-
//
|
|
90
|
-
//
|
|
89
|
+
// Patch the private methods resetTimeout and clearTimeout on Mocha's runnable objects so we can do the appropriate
|
|
90
|
+
// calls in TestTimeout above when the Mocha methods are called.
|
|
91
|
+
// These are not part of the public API so if Mocha changes how it works, this could break.
|
|
92
|
+
// See https://github.com/mochajs/mocha/blob/8d0ca3ed77ba8a704b2aa8b58267a084a475a51b/lib/runnable.js#L234.
|
|
91
93
|
const mochaModule = globalThis.getMochaModule() as typeof Mocha;
|
|
92
94
|
const runnablePrototype = mochaModule.Runnable.prototype;
|
|
93
95
|
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
@@ -107,26 +109,30 @@ if (globalThis.getMochaModule !== undefined) {
|
|
|
107
109
|
/**
|
|
108
110
|
* @internal
|
|
109
111
|
*/
|
|
110
|
-
export interface
|
|
112
|
+
export interface TimeoutDurationOption {
|
|
111
113
|
/**
|
|
112
114
|
* Timeout duration in milliseconds, if it is great than 0 and not Infinity
|
|
113
115
|
* If it is undefined, then it will use test timeout if we are in side the test function
|
|
114
116
|
* Otherwise, there is no timeout
|
|
115
117
|
*/
|
|
116
118
|
durationMs?: number;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* @internal
|
|
123
|
+
*/
|
|
124
|
+
export interface TimeoutWithError extends TimeoutDurationOption {
|
|
117
125
|
reject?: true;
|
|
118
126
|
errorMsg?: string;
|
|
127
|
+
// Since there are no required properties, this type explicitly
|
|
128
|
+
// rejects `value` to avoid confusion with TimeoutWithValue.
|
|
129
|
+
value?: never;
|
|
119
130
|
}
|
|
131
|
+
|
|
120
132
|
/**
|
|
121
133
|
* @internal
|
|
122
134
|
*/
|
|
123
|
-
export interface TimeoutWithValue<T = void> {
|
|
124
|
-
/**
|
|
125
|
-
* Timeout duration in milliseconds, if it is great than 0 and not Infinity
|
|
126
|
-
* If it is undefined, then it will use test timeout if we are in side the test function
|
|
127
|
-
* Otherwise, there is no timeout
|
|
128
|
-
*/
|
|
129
|
-
durationMs?: number;
|
|
135
|
+
export interface TimeoutWithValue<T = void> extends TimeoutDurationOption {
|
|
130
136
|
reject: false;
|
|
131
137
|
value: T;
|
|
132
138
|
}
|
|
@@ -137,14 +143,17 @@ export type PromiseExecutor<T = void> = (
|
|
|
137
143
|
) => void;
|
|
138
144
|
|
|
139
145
|
/**
|
|
140
|
-
* Wraps the given promise
|
|
141
|
-
* not resolve by then.
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
146
|
+
* Wraps the given promise with another one that will complete after a specific timeout if the original promise does
|
|
147
|
+
* not resolve by then.
|
|
148
|
+
*
|
|
149
|
+
* @remarks
|
|
150
|
+
* If used inside a mocha test, it uses the test timeout by default and completes the returned promise just before
|
|
151
|
+
* the test timeout hits, so that tests don't time out because of unpredictable awaits.
|
|
152
|
+
* In that scenario the timeout can still be overridden via `timeoutOptions` but it's recommended to use the default value.
|
|
153
|
+
*
|
|
154
|
+
* @param promise - The promise to be wrapped.
|
|
155
|
+
* @param timeoutOptions - Options that can be used to override the timeout and / or define the behavior when
|
|
156
|
+
* the promise is not fulfilled. For example, instead of rejecting the promise, resolve with a specific value.
|
|
148
157
|
* @returns A new promise that will complete when the given promise resolves or the timeout expires.
|
|
149
158
|
* @internal
|
|
150
159
|
*/
|
|
@@ -156,9 +165,13 @@ export async function timeoutAwait<T = void>(
|
|
|
156
165
|
}
|
|
157
166
|
|
|
158
167
|
/**
|
|
159
|
-
* Creates a promise from the given executor that will complete after a specific timeout.
|
|
160
|
-
*
|
|
161
|
-
*
|
|
168
|
+
* Creates a promise from the given executor that will complete after a specific timeout.
|
|
169
|
+
*
|
|
170
|
+
* @remarks
|
|
171
|
+
* If used inside a mocha test, it uses the test timeout by default and completes the returned promise just before
|
|
172
|
+
* the test timeout hits, so that tests don't time out because of unpredictable awaits.
|
|
173
|
+
* In that scenario the timeout can still be overridden via `timeoutOptions` but it's recommended to use the default value.
|
|
174
|
+
*
|
|
162
175
|
* @param executor - The executor for the promise.
|
|
163
176
|
* @param timeoutOptions - Options that can be used to override the timeout and / or define the behavior when
|
|
164
177
|
* the promise is not fulfilled. For example, instead of rejecting the promise, resolve with a specific value.
|
|
@@ -192,7 +205,7 @@ export async function timeoutPromise<T = void>(
|
|
|
192
205
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
193
206
|
const errorObject = err!;
|
|
194
207
|
errorObject.message = `${
|
|
195
|
-
timeoutOptions.errorMsg ?? "
|
|
208
|
+
timeoutOptions.errorMsg ?? "Forcing timeout before test does"
|
|
196
209
|
} (${currentTestTimeout.getTimeout()}ms)`;
|
|
197
210
|
throw errorObject;
|
|
198
211
|
}
|