hermes-test 1.0.1 → 1.0.3
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/bin/hermes-test.js +14 -14
- package/dist/harness.bundle.js +212 -98
- package/globals.d.ts +12 -9
- package/index.d.ts +33 -26
- package/package.json +4 -4
- package/src/expect.ts +202 -114
- package/src/fetch.ts +19 -5
- package/src/harness.ts +129 -33
- package/src/hooks.ts +131 -43
- package/src/index.ts +22 -14
- package/src/mock.ts +15 -11
- package/src/polyfills.js +151 -73
- package/src/render.ts +54 -32
- package/src/shims/async-storage.js +9 -9
- package/src/shims/react-i18next.js +30 -10
- package/src/shims/react-native-launch-arguments.js +3 -1
- package/src/shims/react-native.js +133 -41
- package/src/shims/react.js +3 -3
- package/src/shims/rtk-query-core.js +18 -8
- package/src/shims/rtk-query.js +18 -8
- package/src/shims/tanstack-query.js +2 -2
- package/src/spy.ts +32 -36
- package/src/store.ts +27 -17
- package/src/timers.ts +5 -3
package/globals.d.ts
CHANGED
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
declare global {
|
|
2
2
|
interface HtMockFetch {
|
|
3
|
-
(...handlers: import('hermes-test').FetchHandler[]): void
|
|
4
|
-
overwrite(...handlers: import('hermes-test').FetchHandler[]): void
|
|
5
|
-
reset(): void
|
|
6
|
-
clear(): void
|
|
3
|
+
(...handlers: import('hermes-test').FetchHandler[]): void;
|
|
4
|
+
overwrite(...handlers: import('hermes-test').FetchHandler[]): void;
|
|
5
|
+
reset(): void;
|
|
6
|
+
clear(): void;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
interface HtMock {
|
|
10
|
-
(modulePath: string, factory: () =>
|
|
11
|
-
fetch: HtMockFetch
|
|
10
|
+
(modulePath: string, factory: () => unknown): void;
|
|
11
|
+
fetch: HtMockFetch;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
/** Shallow render: auto-mock child components so the parent renders without deep dependencies. */
|
|
15
|
-
function htShallow(componentPath: string): void
|
|
15
|
+
function htShallow(componentPath: string): void;
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
/** Remove a previously registered mock so the real module is used. No-op at runtime (bundler directive). */
|
|
18
|
+
function htUnmock(modulePath: string): void;
|
|
19
|
+
|
|
20
|
+
const ht: { mock: HtMock; shallow: typeof htShallow; unmock: typeof htUnmock };
|
|
18
21
|
}
|
|
19
|
-
export {}
|
|
22
|
+
export {};
|
package/index.d.ts
CHANGED
|
@@ -2,27 +2,26 @@
|
|
|
2
2
|
|
|
3
3
|
// --- Spy ---
|
|
4
4
|
|
|
5
|
-
export type Spy<F extends (...args: any[]) => any = (...args: any[]) => any> =
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
};
|
|
5
|
+
export type Spy<F extends (...args: any[]) => any = (...args: any[]) => any> = F & {
|
|
6
|
+
readonly calls: ReadonlyArray<Parameters<F>>;
|
|
7
|
+
readonly callCount: number;
|
|
8
|
+
readonly returnValues: ReadonlyArray<ReturnType<F>>;
|
|
9
|
+
reset(): void;
|
|
10
|
+
setImpl(impl: F): Spy<F>;
|
|
11
|
+
returns(value: ReturnType<F>): Spy<F>;
|
|
12
|
+
mockImplementation(fn: F): Spy<F>;
|
|
13
|
+
mockImplementationOnce(fn: F): Spy<F>;
|
|
14
|
+
mockReturnValue(value: ReturnType<F>): Spy<F>;
|
|
15
|
+
mockReturnValueOnce(value: ReturnType<F>): Spy<F>;
|
|
16
|
+
mockResolvedValue<V>(value: V): Spy<(...args: Parameters<F>) => Promise<V>>;
|
|
17
|
+
mockResolvedValueOnce<V>(value: V): Spy<F>;
|
|
18
|
+
mockRejectedValue(value: unknown): Spy<F>;
|
|
19
|
+
mockRejectedValueOnce(value: unknown): Spy<F>;
|
|
20
|
+
mockClear(): void;
|
|
21
|
+
mockReset(): void;
|
|
22
|
+
mockRestore(): void;
|
|
23
|
+
readonly _isSpy: true;
|
|
24
|
+
};
|
|
26
25
|
|
|
27
26
|
export function spy(): Spy<(...args: any[]) => undefined>;
|
|
28
27
|
export function spy<F extends (...args: any[]) => any>(impl: F): Spy<F>;
|
|
@@ -214,7 +213,9 @@ export const fireEvent: FireEventObject;
|
|
|
214
213
|
|
|
215
214
|
export function useMock<T extends Record<string, unknown>>(
|
|
216
215
|
moduleExports: T,
|
|
217
|
-
implementation: Partial<{
|
|
216
|
+
implementation: Partial<{
|
|
217
|
+
[K in keyof T]: T[K] extends (...args: any[]) => any ? Spy<T[K]> | T[K] : T[K];
|
|
218
|
+
}>,
|
|
218
219
|
): void;
|
|
219
220
|
|
|
220
221
|
// --- Fetch mocking types ---
|
|
@@ -262,11 +263,17 @@ export interface StoreContext {
|
|
|
262
263
|
getState(): any;
|
|
263
264
|
setState(state: Record<string, any>): void;
|
|
264
265
|
patchState(partial: Record<string, any>): void;
|
|
265
|
-
renderHookWithReduxStore<T>(
|
|
266
|
+
renderHookWithReduxStore<T>(
|
|
267
|
+
hookFn: (props?: any) => T,
|
|
268
|
+
options?: { initialProps?: any },
|
|
269
|
+
): HookResult<T>;
|
|
266
270
|
}
|
|
267
271
|
|
|
268
272
|
export function withStore(initialState?: Record<string, any>): StoreContext;
|
|
269
|
-
export function withAppReducer(
|
|
273
|
+
export function withAppReducer(
|
|
274
|
+
reducer: (state: any, action: any) => any,
|
|
275
|
+
preloadedState?: Record<string, any>,
|
|
276
|
+
): StoreContext;
|
|
270
277
|
|
|
271
278
|
// --- Timers ---
|
|
272
279
|
|
|
@@ -293,9 +300,9 @@ declare global {
|
|
|
293
300
|
}
|
|
294
301
|
|
|
295
302
|
interface HtMock {
|
|
296
|
-
(modulePath: string, factory: () =>
|
|
303
|
+
(modulePath: string, factory: () => unknown): void;
|
|
297
304
|
fetch: HtMockFetch;
|
|
298
305
|
}
|
|
299
306
|
|
|
300
|
-
const ht: { mock: HtMock };
|
|
307
|
+
const ht: { mock: HtMock; unmock: (modulePath: string) => void };
|
|
301
308
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hermes-test",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "26-64x faster than Jest. A test runner built for React Native and Expo. One esbuild pass, one process, zero Babel.",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -54,9 +54,9 @@
|
|
|
54
54
|
"react": ">=18"
|
|
55
55
|
},
|
|
56
56
|
"optionalDependencies": {
|
|
57
|
-
"@hermes-test/darwin-arm64": "1.0.
|
|
58
|
-
"@hermes-test/darwin-x64": "1.0.
|
|
59
|
-
"@hermes-test/linux-x64": "1.0.
|
|
57
|
+
"@hermes-test/darwin-arm64": "1.0.3",
|
|
58
|
+
"@hermes-test/darwin-x64": "1.0.3",
|
|
59
|
+
"@hermes-test/linux-x64": "1.0.3"
|
|
60
60
|
},
|
|
61
61
|
"files": [
|
|
62
62
|
"src/",
|