import { Mock } from "vitest"; //#region src/types.d.ts /** Static methods available on the Image component mock. */ interface ImageStatic { getSize: Mock; getSizeWithHeaders: Mock; prefetch: Mock; queryCache: Mock; resolveAssetSource: Mock; } /** The Animated API mock shape. */ interface AnimatedMock { Value: new (value?: number) => any; ValueXY: new (value?: { x: number; y: number; }) => any; Color: new () => any; timing: Mock; spring: Mock; decay: Mock; sequence: Mock; parallel: Mock; stagger: Mock; loop: Mock; delay: Mock; add: Mock; subtract: Mock; multiply: Mock; divide: Mock; modulo: Mock; diffClamp: Mock; event: Mock; forkEvent: Mock; unforkEvent: Mock; createAnimatedComponent: Mock; View: React.ComponentType; Text: React.ComponentType; Image: React.ComponentType; ScrollView: React.ComponentType; FlatList: React.ComponentType; SectionList: React.ComponentType; } /** Platform API mock shape. */ interface PlatformMock { OS: "ios" | "android"; Version: string | number; isPad: boolean; isTVOS: boolean; isTV: boolean; isVision: boolean; isTesting: boolean; select: Mock; constants: { reactNativeVersion: { major: number; minor: number; patch: number; }; osVersion: number; systemName: string; isTesting: boolean; }; } /** Dimensions API mock shape. */ interface DimensionsMock { get: Mock; set: Mock; addEventListener: Mock; _reset: () => void; } /** Keyboard API mock shape. */ interface KeyboardMock { dismiss: Mock; addListener: Mock; removeListener: Mock; removeAllListeners: Mock; isVisible: Mock; metrics: Mock; scheduleLayoutAnimation: Mock; _show: (height?: number) => void; _hide: () => void; _reset: () => void; } /** AppState API mock shape. */ interface AppStateMock { currentState: string; isAvailable: boolean; addEventListener: Mock; _setState: (state: string) => void; _reset: () => void; } /** The full React Native mock object. */ interface ReactNativeMock { View: React.ComponentType; Text: React.ComponentType; Image: React.ComponentType & ImageStatic; TextInput: React.ComponentType; ScrollView: React.ComponentType; FlatList: React.ComponentType; SectionList: React.ComponentType; Modal: React.ComponentType; Pressable: React.ComponentType; TouchableOpacity: React.ComponentType; TouchableHighlight: React.ComponentType; TouchableWithoutFeedback: React.ComponentType; TouchableNativeFeedback: React.ComponentType; ActivityIndicator: React.ComponentType; Button: React.ComponentType; Switch: React.ComponentType; RefreshControl: React.ComponentType; StatusBar: Record; SafeAreaView: React.ComponentType; KeyboardAvoidingView: React.ComponentType; ImageBackground: React.ComponentType; VirtualizedList: React.ComponentType; InputAccessoryView: React.ComponentType; DrawerLayoutAndroid: React.ComponentType; Platform: PlatformMock; Dimensions: DimensionsMock; StyleSheet: Record; Animated: AnimatedMock; Alert: Record; Linking: Record; AppState: AppStateMock; Keyboard: KeyboardMock; BackHandler: Record; Vibration: Record; PermissionsAndroid: Record; Appearance: Record; PixelRatio: Record; LayoutAnimation: Record; Clipboard: Record; Share: Record; AccessibilityInfo: Record; InteractionManager: Record; PanResponder: Record; ToastAndroid: Record; ActionSheetIOS: Record; LogBox: Record; Easing: Record; I18nManager: Record; DeviceEventEmitter: Record; useColorScheme: (() => "light" | "dark") & { _setScheme: (s: "light" | "dark") => void; _resetScheme: (s: "light" | "dark") => void; }; useWindowDimensions: (() => { width: number; height: number; scale: number; fontScale: number; }) & { _setDimensions: (d: any) => void; _resetDimensions: (d: any) => void; }; NativeModules: Record; TurboModuleRegistry: Record; UIManager: Record; NativeEventEmitter: new (...args: any[]) => any; NativeAppEventEmitter: Record; EventEmitter: new (...args: any[]) => any; NativeComponentRegistry: Record; requireNativeComponent: Mock; AppRegistry: Record; VirtualizedSectionList: React.ComponentType; Touchable: Record; processColor: Mock; findNodeHandle: Mock; PlatformColor: Mock; DynamicColorIOS: Mock; Settings: Record; DeviceInfo: Record; useAnimatedValue: Mock; useAnimatedValueXY: Mock; useAnimatedColor: Mock; RootTagContext: React.Context; ReactNativeVersion: { major: number; minor: number; patch: number; }; Systrace: Record; DevSettings: Record; Networking: Record; unstable_batchedUpdates: Mock; registerCallableModule: Mock; codegenNativeCommands: Mock; codegenNativeComponent: Mock; UTFSequence: Record; ProgressBarAndroid: React.ComponentType; PushNotificationIOS: Record; NativeDialogManagerAndroid: Record; usePressability: Mock; default: ReactNativeMock; } interface PresetModule { /** Factory that builds the mock object. Only called in Vitest worker processes. */ factory: () => Record; /** Static list of named exports for virtual ESM module generation. Read at Vite config time (no vitest available). */ exports: string[]; } interface Preset { name: string; modules: Record; /** * Optional JSON-serializable configuration for the preset. Presets are rebuilt * inside Vitest worker processes from their `name`, so any options passed to a * preset factory (e.g. `navigation({ defaultRouteParams })`) must be carried * here to survive the main-process → worker boundary. Read by the native setup * file and passed back into the factory in-worker. Must be JSON-serializable. */ config?: Record; } /** Options for the `navigation` preset. */ interface NavigationPresetOptions { /** * Params returned by the mocked `useRoute().params` (and used as a ``'s * fallback `initialParams`). Lets you test components that read route params at * mount — e.g. `useRoute().params.id` — without a custom `vi.mock`. Must be * JSON-serializable (it crosses the worker boundary). * * @example * ```ts * presets.navigation({ defaultRouteParams: { id: '1', mode: 'edit' } }) * ``` */ defaultRouteParams?: Record; } interface VitestNativeOptions { /** Target platform. Default: 'ios' */ platform?: "ios" | "android"; /** * Test engine. * - 'mock' — pure-JS reimplementation of React Native (fastest, lower fidelity). * - 'native' — runs real React Native JS, mocking only the native boundary * (highest fidelity). * - 'auto' — resolves to 'native' when '@react-native/babel-preset' and * '@babel/core' are available, otherwise falls back to 'mock'. * Default: 'auto'. */ engine?: "auto" | "mock" | "native"; /** * Built-in third-party library presets. * * An ARRAY replaces auto-detection entirely: only those presets are used. * * An OBJECT keeps auto-detection and turns individual presets off by name — * `{ navigation: false }` — which is what you want when one preset gets in the * way. Listing every other detected preset back by hand just to drop one is * both tedious and a thing that silently rots as dependencies change. * * Only built-in presets are supported (reanimated, gestureHandler, * safeAreaContext, navigation, asyncStorage, screens, expo). For custom * module mocking, use vi.mock() in a setup file. * * @example * ```ts * import { reactNative, presets } from 'vitest-native'; * reactNative({ presets: [presets.reanimated(), presets.navigation()] }) * ``` */ presets?: Preset[] | Record; /** * `engine: 'mock'` only. Plain-data overrides merged into the react-native * module mock. * Values must be JSON-serializable (strings, numbers, booleans, plain * objects, arrays). Function values are not supported — use vi.mock() * in a setup file for function-based overrides. * * @example * ```ts * reactNative({ mocks: { Platform: { OS: 'web' } } }) * ``` */ mocks?: Record; /** Log plugin activity. Default: false */ diagnostics?: boolean; /** Additional asset file extensions to stub (e.g. ['.lottie', '.m4b']) */ assetExts?: string[]; /** * `engine: 'native'` only. Names of additional node_modules packages whose * source the native engine should transform (Flow/TS/JSX stripped) as it * loads them. By default only `react-native` / `@react-native` are * transformed; third-party RN libraries that ship untranspiled source * (e.g. `react-native-reanimated`, `react-native-safe-area-context`) need to * be listed here, analogous to Jest's `transformIgnorePatterns` allowlist. * * The object form adds `exclude`, which names packages the engine must NEVER * transform, whatever else would have selected them — auto-detection, a detected * package's dependency closure, or the engine's own built-in lists. * * `exclude` exists because the engine's judgement about what is React Native source * is a heuristic, and when it guesses wrong the failure is a parse error deep inside * a package the project never named. Build toolchains are the recurring case: * compiling one re-enters Babel while it is loading. The engine excludes the ones it * knows about, but that list is only as current as the last release — `exclude` is * how a project unblocks itself the same day, without waiting for one. * * Run with `diagnostics: true` to print the packages the engine chose to compile; * that list is what `exclude` subtracts from. * * @example * ```ts * reactNative({ engine: 'native', transform: ['react-native-reanimated'] }) * * reactNative({ * engine: 'native', * transform: { * include: ['react-native-reanimated'], * exclude: ['some-build-tool'], // never hand this to the Babel preset * }, * }) * ``` */ transform?: string[] | { include?: string[]; exclude?: string[]; }; /** * `engine: 'native'` only. **Experimental.** Run tests in persistent * RN-hot workers: React Native's module graph loads once per worker and * stays resident across test files, while each file still gets a fresh * Vitest module runner (per-file isolation of your app/test modules). * Uses a custom Vitest pool + worker entry + runner; requires Vitest >= 4. * * Pass an object to tune worker recycling (self-defense against suites that * leak process-wide resources the per-file reset can't reclaim): * - `recycleAfterFiles`: retire a worker after it has run N test files. This * is enforced between Vitest scheduler tasks; a single task containing * multiple files cannot be interrupted. * - `memoryLimit`: retire a worker when its reported JS heap (bytes) meets * or exceeds this value, also between scheduler tasks. When hot is enabled * and you set neither `memoryLimit` nor `recycleAfterFiles`, a default * per-worker bound of `clamp(totalmem * 0.25, 768MB, 1.5GB)` is applied so * memory stays bounded out of the box (multi-worker runs recycle a worker * once it crosses the ceiling). Single-worker hot can't recycle, so the * bound is inert there — run with `maxWorkers >= 2` for bounded hot memory. * - `preserveGlobals`: exact globalThis property names intentionally owned * by resident external libraries. App/test globals are otherwise removed * between files. Storybook's preview registry is preserved automatically. * - `esmGeneration`: re-evaluate externalized packages a test file `import`s, * so their module-level state does not carry into the next file. Node's ESM * registry cannot be invalidated, so the loader stamps a per-file generation * onto the resolved URL instead. On by default, because without it those * packages behave differently under hot than under stock isolation. It costs * re-execution: a suite whose files import many externalized (non-React * Native) packages measured 55% more wall clock at the extreme — still 9x * stock isolation, against 13.9x with it off. Set false to trade that back, * accepting that a package holding state across files will keep it. * * Default: false (each file runs in a fresh worker; RN reloads per file). */ hotRuntime?: boolean | { recycleAfterFiles?: number; memoryLimit?: number; preserveGlobals?: string[]; esmGeneration?: boolean; }; } //#endregion //#region src/presets/reanimated.d.ts declare function reanimated(): Preset; //#endregion //#region src/presets/gesture-handler.d.ts declare function gestureHandler(): Preset; //#endregion //#region src/presets/safe-area.d.ts declare function safeAreaContext(): Preset; //#endregion //#region src/presets/navigation.d.ts declare function navigation(presetOptions?: NavigationPresetOptions): Preset; //#endregion //#region src/presets/async-storage.d.ts declare function asyncStorage(): Preset; //#endregion //#region src/presets/screens.d.ts declare function screens(): Preset; //#endregion //#region src/presets/expo.d.ts declare function expo(): Preset; //#endregion //#region src/presets/device-info.d.ts declare function deviceInfo(): Preset; //#endregion //#region src/presets/mmkv.d.ts declare function mmkv(): Preset; //#endregion //#region src/presets/netinfo.d.ts declare function netInfo(): Preset; //#endregion //#region src/presets/svg.d.ts declare function svg(): Preset; //#endregion //#region src/presets/webview.d.ts declare function webview(): Preset; //#endregion //#region src/presets/vector-icons.d.ts declare function vectorIcons(): Preset; //#endregion //#region src/presets/flash-list.d.ts declare function flashList(): Preset; //#endregion //#region src/presets/bottom-sheet.d.ts declare function bottomSheet(): Preset; //#endregion //#region src/presets/keyboard-controller.d.ts declare function keyboardController(): Preset; //#endregion //#region src/presets/worklets.d.ts declare function worklets(): Preset; declare namespace index_d_exports { export { asyncStorage, bottomSheet, deviceInfo, expo, flashList, gestureHandler, keyboardController, mmkv, navigation, netInfo, reanimated, safeAreaContext, screens, svg, vectorIcons, webview, worklets }; } //#endregion export { gestureHandler as _, flashList as a, ReactNativeMock as b, svg as c, deviceInfo as d, expo as f, safeAreaContext as g, navigation as h, bottomSheet as i, netInfo as l, asyncStorage as m, worklets as n, vectorIcons as o, screens as p, keyboardController as r, webview as s, index_d_exports as t, mmkv as u, reanimated as v, VitestNativeOptions as x, Preset as y };