@remotex-labs/xjet 1.2.3 → 1.3.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/dist/bash.js +17 -17
- package/dist/bash.js.map +4 -4
- package/dist/index.d.ts +195 -30
- package/dist/index.js +54 -54
- package/dist/index.js.map +5 -5
- package/dist/shared.d.ts +194 -32
- package/dist/shared.js +4 -4
- package/dist/shared.js.map +4 -4
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
import type { xExpect } from '@remotex-labs/xjet-expect';
|
|
7
7
|
import type { FunctionLikeType, FunctionType } from '@remotex-labs/xjet-expect';
|
|
8
8
|
import type { FunctionType } from '@remotex-labs/xjet-expect';
|
|
9
|
-
import type { FunctionType, RejectedValueType, ResolvedValueType } from '@remotex-labs/xjet-expect';
|
|
10
9
|
import type { ContextType } from '@remotex-labs/xjet-expect';
|
|
11
10
|
import type { FunctionLikeType } from '@remotex-labs/xjet-expect';
|
|
12
11
|
import type { ContextType, FunctionType } from '@remotex-labs/xjet-expect';
|
|
@@ -54,8 +53,11 @@ declare global {
|
|
|
54
53
|
const runAllTimers: typeof FakeTimer.runAllTimers;
|
|
55
54
|
const useFakeTimers: typeof FakeTimer.useFakeTimers;
|
|
56
55
|
const useRealTimers: typeof FakeTimer.useRealTimers;
|
|
56
|
+
const clearAllTimers: typeof FakeTimer.clearAllTimers;
|
|
57
|
+
const runAllTimersAsync: typeof FakeTimer.runAllTimersAsync;
|
|
57
58
|
const advanceTimersByTime: typeof FakeTimer.advanceTimersByTime;
|
|
58
59
|
const runOnlyPendingTimers: typeof FakeTimer.runOnlyPendingTimers;
|
|
60
|
+
const runOnlyPendingTimersAsync: typeof FakeTimer.runOnlyPendingTimersAsync;
|
|
59
61
|
}
|
|
60
62
|
const it: TestDirectiveInterface;
|
|
61
63
|
const test: TestDirectiveInterface;
|
|
@@ -294,12 +296,15 @@ interface MockableFunctionInterface<F extends FunctionType> extends MockState<F>
|
|
|
294
296
|
}
|
|
295
297
|
/**
|
|
296
298
|
* Makes properties of a type or its resolved promise value optional.
|
|
299
|
+
* Converts `never` to `void` to avoid unassignable types.
|
|
297
300
|
*
|
|
298
301
|
* @template T - The type to transform
|
|
299
302
|
*
|
|
300
303
|
* @remarks
|
|
301
|
-
* If T is a
|
|
302
|
-
* properties optional.
|
|
304
|
+
* If `T` is a `PromiseLike` type, this utility unwraps it and makes the resolved value's
|
|
305
|
+
* properties optional.
|
|
306
|
+
* If `T` is `never`, it is converted to `void`.
|
|
307
|
+
* Otherwise, it directly makes `T`'s properties optional.
|
|
303
308
|
*
|
|
304
309
|
* @example
|
|
305
310
|
* ```ts
|
|
@@ -308,11 +313,16 @@ interface MockableFunctionInterface<F extends FunctionType> extends MockState<F>
|
|
|
308
313
|
*
|
|
309
314
|
* // Makes properties of resolved User optional
|
|
310
315
|
* type MaybeAsyncUser = PartialResolvedType<Promise<User>>;
|
|
316
|
+
*
|
|
317
|
+
* // Never becomes void
|
|
318
|
+
* type MaybeNever = PartialResolvedType<never>; // void
|
|
311
319
|
* ```
|
|
312
320
|
*
|
|
313
321
|
* @since 1.2.2
|
|
314
322
|
*/
|
|
315
|
-
type PartialResolvedType<T> =
|
|
323
|
+
type PartialResolvedType<T> = [
|
|
324
|
+
T
|
|
325
|
+
] extends [never] ? void : T extends PromiseLike<infer U> ? Promise<Partial<U>> : Partial<T>;
|
|
316
326
|
|
|
317
327
|
/**
|
|
318
328
|
* Import will remove at compile time
|
|
@@ -834,7 +844,7 @@ export declare class MockState<F extends FunctionType = FunctionType> extends Fu
|
|
|
834
844
|
*
|
|
835
845
|
* @since 1.0.0
|
|
836
846
|
*/
|
|
837
|
-
mockResolvedValue(value:
|
|
847
|
+
mockResolvedValue(value: PromiseValueType<ReturnType<F>>): this;
|
|
838
848
|
/**
|
|
839
849
|
* Adds a one-time resolved Promise return value for this mock function.
|
|
840
850
|
*
|
|
@@ -868,7 +878,7 @@ export declare class MockState<F extends FunctionType = FunctionType> extends Fu
|
|
|
868
878
|
*
|
|
869
879
|
* @since 1.0.0
|
|
870
880
|
*/
|
|
871
|
-
mockResolvedValueOnce(value:
|
|
881
|
+
mockResolvedValueOnce(value: PromiseValueType<ReturnType<F>>): this;
|
|
872
882
|
/**
|
|
873
883
|
* Sets a rejected Promise return value for this mock function.
|
|
874
884
|
*
|
|
@@ -905,7 +915,7 @@ export declare class MockState<F extends FunctionType = FunctionType> extends Fu
|
|
|
905
915
|
*
|
|
906
916
|
* @since 1.0.0
|
|
907
917
|
*/
|
|
908
|
-
mockRejectedValue(value:
|
|
918
|
+
mockRejectedValue(value: PromiseValueType<ReturnType<F>>): this;
|
|
909
919
|
/**
|
|
910
920
|
* Adds a one-time rejected Promise return value for this mock function.
|
|
911
921
|
*
|
|
@@ -941,7 +951,7 @@ export declare class MockState<F extends FunctionType = FunctionType> extends Fu
|
|
|
941
951
|
*
|
|
942
952
|
* @since 1.0.0
|
|
943
953
|
*/
|
|
944
|
-
mockRejectedValueOnce(value:
|
|
954
|
+
mockRejectedValueOnce(value: PromiseValueType<ReturnType<F>>): this;
|
|
945
955
|
/**
|
|
946
956
|
* Initializes the internal state object for the mock function.
|
|
947
957
|
*
|
|
@@ -1038,26 +1048,6 @@ export declare class MockState<F extends FunctionType = FunctionType> extends Fu
|
|
|
1038
1048
|
private invokeFunction;
|
|
1039
1049
|
}
|
|
1040
1050
|
|
|
1041
|
-
/**
|
|
1042
|
-
* Represents an interface for defining bound context and arguments.
|
|
1043
|
-
*
|
|
1044
|
-
* @template Context - The type of the bound `this` context, which can be an object, null, or undefined.
|
|
1045
|
-
* @template Args - The type of the array representing bound arguments.
|
|
1046
|
-
*
|
|
1047
|
-
* @remarks
|
|
1048
|
-
* This interface is designed to store binding metadata, specifically a reference to the bound `this` context
|
|
1049
|
-
* and any arguments that are pre-applied during function binding. It is often used in scenarios involving
|
|
1050
|
-
* dynamic contexts or partial application of functions.
|
|
1051
|
-
*
|
|
1052
|
-
* @see ContextType
|
|
1053
|
-
*
|
|
1054
|
-
* @since 1.0.0
|
|
1055
|
-
*/
|
|
1056
|
-
interface BoundInterface<Context = unknown | null | undefined, Args = Array<unknown>> {
|
|
1057
|
-
__boundThis?: Context;
|
|
1058
|
-
__boundArgs?: Args;
|
|
1059
|
-
}
|
|
1060
|
-
|
|
1061
1051
|
/**
|
|
1062
1052
|
* Import will remove at compile time
|
|
1063
1053
|
*/
|
|
@@ -1164,6 +1154,29 @@ interface MocksStateInterface<F extends FunctionType> {
|
|
|
1164
1154
|
*/
|
|
1165
1155
|
results: Array<MockInvocationResultInterface<ReturnType<F>>>;
|
|
1166
1156
|
}
|
|
1157
|
+
/**
|
|
1158
|
+
* Extracts the resolved value type from a `PromiseLike` type.
|
|
1159
|
+
*
|
|
1160
|
+
* @template T The input type to inspect.
|
|
1161
|
+
*
|
|
1162
|
+
* @remarks
|
|
1163
|
+
* If `T` extends `PromiseLike<infer U>`, the resulting type is `U | T`, meaning it includes both
|
|
1164
|
+
* the resolved value type and the original `PromiseLike` type.
|
|
1165
|
+
*
|
|
1166
|
+
* If `T` is not a `PromiseLike`, the resulting type is simply `T`.
|
|
1167
|
+
*
|
|
1168
|
+
* This utility type is useful when you want to support both synchronous and asynchronous values
|
|
1169
|
+
* transparently — for example, when a function may return either a raw value or a promise.
|
|
1170
|
+
*
|
|
1171
|
+
* @example
|
|
1172
|
+
* ```ts
|
|
1173
|
+
* type A = PromiseValueType<Promise<number>>; // number | Promise<number>
|
|
1174
|
+
* type B = PromiseValueType<string>; // string
|
|
1175
|
+
* ```
|
|
1176
|
+
*
|
|
1177
|
+
* @since 1.0.0
|
|
1178
|
+
*/
|
|
1179
|
+
type PromiseValueType<T> = T | (T extends PromiseLike<infer U> ? U | T : never);
|
|
1167
1180
|
/**
|
|
1168
1181
|
* A utility type that extracts the signature of a function and allows it to be reused in an implementation.
|
|
1169
1182
|
*
|
|
@@ -1194,7 +1207,27 @@ interface MocksStateInterface<F extends FunctionType> {
|
|
|
1194
1207
|
*
|
|
1195
1208
|
* @since 1.2.2
|
|
1196
1209
|
*/
|
|
1197
|
-
type ImplementationType<F extends FunctionType> = FunctionLikeType<ReturnType<F
|
|
1210
|
+
type ImplementationType<F extends FunctionType> = FunctionLikeType<PromiseValueType<ReturnType<F>>, Parameters<F>, ThisParameterType<F>>;
|
|
1211
|
+
|
|
1212
|
+
/**
|
|
1213
|
+
* Represents an interface for defining bound context and arguments.
|
|
1214
|
+
*
|
|
1215
|
+
* @template Context - The type of the bound `this` context, which can be an object, null, or undefined.
|
|
1216
|
+
* @template Args - The type of the array representing bound arguments.
|
|
1217
|
+
*
|
|
1218
|
+
* @remarks
|
|
1219
|
+
* This interface is designed to store binding metadata, specifically a reference to the bound `this` context
|
|
1220
|
+
* and any arguments that are pre-applied during function binding. It is often used in scenarios involving
|
|
1221
|
+
* dynamic contexts or partial application of functions.
|
|
1222
|
+
*
|
|
1223
|
+
* @see ContextType
|
|
1224
|
+
*
|
|
1225
|
+
* @since 1.0.0
|
|
1226
|
+
*/
|
|
1227
|
+
interface BoundInterface<Context = unknown | null | undefined, Args = Array<unknown>> {
|
|
1228
|
+
__boundThis?: Context;
|
|
1229
|
+
__boundArgs?: Args;
|
|
1230
|
+
}
|
|
1198
1231
|
|
|
1199
1232
|
/**
|
|
1200
1233
|
* A base error class that extends the standard Error class with enhanced JSON serialization and location tracking
|
|
@@ -1320,7 +1353,7 @@ declare class ExecutionError extends Error {
|
|
|
1320
1353
|
* @see DeepSearchInterface
|
|
1321
1354
|
* @since 1.0.0
|
|
1322
1355
|
*/
|
|
1323
|
-
declare function deepSearchObject(target: Record<string | symbol, unknown>, element: unknown, key?: string, maxDepth?: number): DeepSearchInterface | null;
|
|
1356
|
+
declare function deepSearchObject(target: Record<string | symbol, unknown>, element: unknown, key?: string | symbol, maxDepth?: number): DeepSearchInterface | null;
|
|
1324
1357
|
/**
|
|
1325
1358
|
* Resolves property references that may be affected by ESBuild's `__toESM` transformation.
|
|
1326
1359
|
*
|
|
@@ -1741,6 +1774,26 @@ declare class TimerService {
|
|
|
1741
1774
|
* @since 1.1.0
|
|
1742
1775
|
*/
|
|
1743
1776
|
useRealTimers(): void;
|
|
1777
|
+
/**
|
|
1778
|
+
* Clears all active fake timers.
|
|
1779
|
+
*
|
|
1780
|
+
* @remarks
|
|
1781
|
+
* This method removes every timer currently stored in {@link timers},
|
|
1782
|
+
* effectively resetting the fake timer state without advancing time.
|
|
1783
|
+
* It is useful for cleaning up between tests to ensure no lingering
|
|
1784
|
+
* scheduled callbacks remain.
|
|
1785
|
+
*
|
|
1786
|
+
* @example
|
|
1787
|
+
* ```ts
|
|
1788
|
+
* useFakeTimers();
|
|
1789
|
+
* setTimeout(() => console.log('A'), 100);
|
|
1790
|
+
* clearAllTimers(); // removes all scheduled timers
|
|
1791
|
+
* advanceTimersByTime(100); // nothing happens
|
|
1792
|
+
* ```
|
|
1793
|
+
*
|
|
1794
|
+
* @since 1.3.0
|
|
1795
|
+
*/
|
|
1796
|
+
clearAllTimers(): void;
|
|
1744
1797
|
/**
|
|
1745
1798
|
* Advances the simulated clock by a specific number of milliseconds and
|
|
1746
1799
|
* executes all timers whose scheduled time has elapsed.
|
|
@@ -1811,6 +1864,51 @@ declare class TimerService {
|
|
|
1811
1864
|
* @since 1.1.0
|
|
1812
1865
|
*/
|
|
1813
1866
|
runOnlyPendingTimers(): void;
|
|
1867
|
+
/**
|
|
1868
|
+
* Asynchronous equivalent of {@link runAllTimers}.
|
|
1869
|
+
*
|
|
1870
|
+
* @remarks
|
|
1871
|
+
* This method first yields to the event loop to allow any pending promises
|
|
1872
|
+
* to resolve before executing all remaining fake timers.
|
|
1873
|
+
* It ensures a deterministic sequence when timers and microtasks coexist.
|
|
1874
|
+
*
|
|
1875
|
+
* @example
|
|
1876
|
+
* ```ts
|
|
1877
|
+
* useFakeTimers();
|
|
1878
|
+
* Promise.resolve().then(() => console.log('microtask'));
|
|
1879
|
+
* setTimeout(() => console.log('timer'), 0);
|
|
1880
|
+
* await timerService.runAllTimersAsync();
|
|
1881
|
+
* // Logs:
|
|
1882
|
+
* // microtask
|
|
1883
|
+
* // timer
|
|
1884
|
+
* ```
|
|
1885
|
+
*
|
|
1886
|
+
* @since 1.3.0
|
|
1887
|
+
*/
|
|
1888
|
+
runAllTimersAsync(): Promise<void>;
|
|
1889
|
+
/**
|
|
1890
|
+
* Asynchronous equivalent of {@link runOnlyPendingTimers}.
|
|
1891
|
+
*
|
|
1892
|
+
* @remarks
|
|
1893
|
+
* This method first yields to the event loop to allow any pending promises
|
|
1894
|
+
* to resolve before executing only currently pending fake timers.
|
|
1895
|
+
* Timers scheduled during execution will not run until explicitly advanced later.
|
|
1896
|
+
*
|
|
1897
|
+
* @example
|
|
1898
|
+
* ```ts
|
|
1899
|
+
* useFakeTimers();
|
|
1900
|
+
* setTimeout(() => {
|
|
1901
|
+
* console.log('first');
|
|
1902
|
+
* setTimeout(() => console.log('second'), 100);
|
|
1903
|
+
* }, 100);
|
|
1904
|
+
* await timerService.runOnlyPendingTimersAsync();
|
|
1905
|
+
* // Logs:
|
|
1906
|
+
* // first
|
|
1907
|
+
* ```
|
|
1908
|
+
*
|
|
1909
|
+
* @since 1.3.0
|
|
1910
|
+
*/
|
|
1911
|
+
runOnlyPendingTimersAsync(): Promise<void>;
|
|
1814
1912
|
}
|
|
1815
1913
|
/**
|
|
1816
1914
|
* Globally enables fake timers using the shared {@link TimerService}.
|
|
@@ -1874,6 +1972,31 @@ declare function useRealTimers(): void;
|
|
|
1874
1972
|
* @since 1.1.0
|
|
1875
1973
|
*/
|
|
1876
1974
|
declare function runAllTimers(): void;
|
|
1975
|
+
/**
|
|
1976
|
+
* Removes all scheduled fake timers from the {@link TimerService}.
|
|
1977
|
+
*
|
|
1978
|
+
* @remarks
|
|
1979
|
+
* This function clears all active timers registered in the shared timer service,
|
|
1980
|
+
* effectively canceling any pending callbacks that would have run during
|
|
1981
|
+
* timer advancement.
|
|
1982
|
+
*
|
|
1983
|
+
* It's useful for resetting the fake timer state between test cases to ensure
|
|
1984
|
+
* no lingering timers affect further tests or for scenarios where you
|
|
1985
|
+
* need to abort all pending operations.
|
|
1986
|
+
*
|
|
1987
|
+
* @example
|
|
1988
|
+
* ```ts
|
|
1989
|
+
* useFakeTimers();
|
|
1990
|
+
* setTimeout(() => console.log('A'), 100);
|
|
1991
|
+
* setTimeout(() => console.log('B'), 200);
|
|
1992
|
+
*
|
|
1993
|
+
* clearAllTimers(); // removes all scheduled timers
|
|
1994
|
+
* advanceTimersByTime(1000); // nothing happens, not show any logs
|
|
1995
|
+
* ```
|
|
1996
|
+
*
|
|
1997
|
+
* @since 1.3.0
|
|
1998
|
+
*/
|
|
1999
|
+
declare function clearAllTimers(): void;
|
|
1877
2000
|
/**
|
|
1878
2001
|
* Executes only the timers that are pending at the time of invocation.
|
|
1879
2002
|
*
|
|
@@ -1921,6 +2044,48 @@ declare function runOnlyPendingTimers(): void;
|
|
|
1921
2044
|
* @since 1.1.0
|
|
1922
2045
|
*/
|
|
1923
2046
|
declare function advanceTimersByTime(ms?: number): void;
|
|
2047
|
+
/**
|
|
2048
|
+
* Asynchronous equivalent of {@link runAllTimers}.
|
|
2049
|
+
*
|
|
2050
|
+
* @remarks
|
|
2051
|
+
* Yields to the event loop before running all pending fake timers.
|
|
2052
|
+
* Useful when working with both Promises and fake timers.
|
|
2053
|
+
*
|
|
2054
|
+
* @example
|
|
2055
|
+
* ```ts
|
|
2056
|
+
* xJet.useFakeTimers();
|
|
2057
|
+
* Promise.resolve().then(() => console.log('promise done'));
|
|
2058
|
+
* setTimeout(() => console.log('timeout done'), 0);
|
|
2059
|
+
* await xJet.runAllTimersAsync();
|
|
2060
|
+
* // Logs:
|
|
2061
|
+
* // promise done
|
|
2062
|
+
* // timeout done
|
|
2063
|
+
* ```
|
|
2064
|
+
*
|
|
2065
|
+
* @since 1.3.0
|
|
2066
|
+
*/
|
|
2067
|
+
declare function runAllTimersAsync(): Promise<void>;
|
|
2068
|
+
/**
|
|
2069
|
+
* Asynchronous equivalent of {@link runOnlyPendingTimers}.
|
|
2070
|
+
*
|
|
2071
|
+
* @remarks
|
|
2072
|
+
* Yields to the event loop before running only timers that are currently pending.
|
|
2073
|
+
* Any timers scheduled by those callbacks will not be executed until a later call.
|
|
2074
|
+
*
|
|
2075
|
+
* @example
|
|
2076
|
+
* ```ts
|
|
2077
|
+
* useFakeTimers();
|
|
2078
|
+
* setTimeout(() => {
|
|
2079
|
+
* console.log('first');
|
|
2080
|
+
* setTimeout(() => console.log('second'), 100);
|
|
2081
|
+
* }, 100);
|
|
2082
|
+
* await runOnlyPendingTimersAsync();
|
|
2083
|
+
* // Logs only "first"
|
|
2084
|
+
* ```
|
|
2085
|
+
*
|
|
2086
|
+
* @since 1.3.0
|
|
2087
|
+
*/
|
|
2088
|
+
declare function runOnlyPendingTimersAsync(): Promise<void>;
|
|
1924
2089
|
|
|
1925
2090
|
/**
|
|
1926
2091
|
* Interface representing a single timer stored and executed by the {@link TimerService}.
|