@fluidframework/test-utils 0.54.2 → 0.56.0-49831
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/.eslintrc.js +1 -1
- package/dist/loaderContainerTracker.d.ts.map +1 -1
- package/dist/loaderContainerTracker.js +9 -12
- package/dist/loaderContainerTracker.js.map +1 -1
- package/dist/localCodeLoader.d.ts.map +1 -1
- package/dist/localCodeLoader.js +2 -1
- package/dist/localCodeLoader.js.map +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/testContainerRuntimeFactory.d.ts +5 -2
- package/dist/testContainerRuntimeFactory.d.ts.map +1 -1
- package/dist/testContainerRuntimeFactory.js +3 -4
- package/dist/testContainerRuntimeFactory.js.map +1 -1
- package/dist/testObjectProvider.d.ts +12 -15
- package/dist/testObjectProvider.d.ts.map +1 -1
- package/dist/testObjectProvider.js +11 -18
- package/dist/testObjectProvider.js.map +1 -1
- package/dist/timeoutUtils.d.ts.map +1 -1
- package/dist/timeoutUtils.js +11 -9
- package/dist/timeoutUtils.js.map +1 -1
- package/package.json +30 -29
- package/src/loaderContainerTracker.ts +9 -12
- package/src/localCodeLoader.ts +6 -3
- package/src/packageVersion.ts +1 -1
- package/src/testContainerRuntimeFactory.ts +8 -7
- package/src/testObjectProvider.ts +23 -31
- package/src/timeoutUtils.ts +20 -16
package/src/timeoutUtils.ts
CHANGED
|
@@ -5,47 +5,51 @@
|
|
|
5
5
|
|
|
6
6
|
export const defaultTimeoutDurationMs = 250;
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
export interface TimeoutWithError {
|
|
9
9
|
durationMs?: number;
|
|
10
10
|
reject?: true;
|
|
11
11
|
errorMsg?: string;
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
}
|
|
13
|
+
export interface TimeoutWithValue<T = void> {
|
|
14
14
|
durationMs?: number;
|
|
15
15
|
reject: false;
|
|
16
16
|
value: T;
|
|
17
|
-
|
|
17
|
+
}
|
|
18
18
|
|
|
19
|
-
// eslint-disable-next-line prefer-arrow/prefer-arrow-functions
|
|
20
19
|
export async function timeoutAwait<T = void>(
|
|
21
20
|
promise: PromiseLike<T>,
|
|
22
21
|
timeoutOptions: TimeoutWithError | TimeoutWithValue<T> = {},
|
|
23
22
|
) {
|
|
24
|
-
return Promise.race([promise, timeoutPromise<T>(()=>{}, timeoutOptions)]);
|
|
23
|
+
return Promise.race([promise, timeoutPromise<T>(() => { }, timeoutOptions)]);
|
|
25
24
|
}
|
|
26
25
|
|
|
27
|
-
|
|
26
|
+
export async function timeoutPromise<T = void>(
|
|
28
27
|
executor: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void,
|
|
29
28
|
timeoutOptions: TimeoutWithError | TimeoutWithValue<T> = {},
|
|
30
29
|
): Promise<T> {
|
|
30
|
+
const timeout =
|
|
31
|
+
timeoutOptions.durationMs !== undefined
|
|
32
|
+
&& Number.isFinite(timeoutOptions.durationMs)
|
|
33
|
+
&& timeoutOptions.durationMs > 0
|
|
34
|
+
? timeoutOptions.durationMs : defaultTimeoutDurationMs;
|
|
31
35
|
// create the timeout error outside the async task, so it's callstack includes
|
|
32
36
|
// the original call site, this makes it easier to debug
|
|
33
37
|
const err = timeoutOptions.reject === false
|
|
34
38
|
? undefined
|
|
35
|
-
: new Error(timeoutOptions.errorMsg ?? "
|
|
36
|
-
return new Promise<T>((
|
|
37
|
-
const
|
|
38
|
-
()=>timeoutOptions.reject === false ?
|
|
39
|
-
|
|
39
|
+
: new Error(`${timeoutOptions.errorMsg ?? "Timed out"}(${timeout}ms)`);
|
|
40
|
+
return new Promise<T>((resolve,reject)=>{
|
|
41
|
+
const timer = setTimeout(
|
|
42
|
+
()=>timeoutOptions.reject === false ? resolve(timeoutOptions.value) : reject(err),
|
|
43
|
+
timeout);
|
|
40
44
|
|
|
41
45
|
executor(
|
|
42
46
|
(value) => {
|
|
43
|
-
clearTimeout(
|
|
44
|
-
|
|
47
|
+
clearTimeout(timer);
|
|
48
|
+
resolve(value);
|
|
45
49
|
},
|
|
46
50
|
(reason) => {
|
|
47
|
-
clearTimeout(
|
|
48
|
-
|
|
51
|
+
clearTimeout(timer);
|
|
52
|
+
reject(reason);
|
|
49
53
|
});
|
|
50
54
|
});
|
|
51
55
|
}
|