UNPKG

@opendatalabs/vana-sdk

Version:

A TypeScript library for interacting with Vana Network smart contracts.

107 lines (106 loc) 3.65 kB
/** * Shared platform testing utilities following TypeScript best practices. * * These utilities eliminate the need for 'as any' assertions in platform detection tests * by providing type-safe mock objects and environment setup helpers. * * @module platformTestHelpers */ export interface NodeEnvironmentGlobals { readonly process: { readonly versions: { readonly node: string; }; }; } export interface BrowserEnvironmentGlobals { readonly window: Record<string, unknown>; readonly document: Record<string, unknown>; } /** * Type-safe platform environment manager for tests. * * This class provides methods to set up different platform environments * without using 'as any' assertions, following official TypeScript best practices. */ export declare class PlatformTestHelper { private readonly originalState; constructor(); /** * Configure globals for Node.js environment detection * * @param nodeVersion - Node.js version string to use */ setupNodeEnvironment(nodeVersion?: string): void; /** * Configure globals for browser environment detection */ setupBrowserEnvironment(): void; /** * Configure ambiguous environment (should default to Node) */ setupAmbiguousEnvironment(): void; /** * Set up browser environment with crypto support * * @param cryptoOverrides - Optional crypto properties to override */ setupBrowserWithCrypto(cryptoOverrides?: Partial<Crypto>): void; /** * Set up Node environment with specific process properties * * @param processOverrides - Optional process properties to override */ setupNodeWithProcess(processOverrides?: Partial<typeof process>): void; /** * Restore original global state */ restore(): void; private captureOriginalState; private restoreGlobal; private clearNodeGlobals; private clearBrowserGlobals; private clearAllGlobals; } /** * Creates a type-safe mock crypto object for testing. * * @param overrides - Properties to override in the base mock crypto implementation * @returns A mock Crypto object with stubbed SubtleCrypto methods */ export declare function createMockCrypto(overrides?: Partial<Crypto>): Crypto; /** * Creates a type-safe mock Node.js process object for testing. * * @param overrides - Properties to override in the base process mock * @returns A mock process object with platform, version, and environment information */ export declare function createMockProcess(overrides?: Partial<typeof process>): typeof process; /** * Creates a type-safe mock Window object for browser testing. * * @param overrides - Properties to override in the base window mock * @returns A mock window object with document, location, and navigator properties */ export declare function createMockWindow(overrides?: Partial<Window>): Window & typeof globalThis; /** * Creates a type-safe mock Document object for browser testing. * * @param overrides - Properties to override in the base document mock * @returns A mock document object with DOM manipulation methods */ export declare function createMockDocument(overrides?: Partial<Document>): Document; /** * Utility for creating properly typed fetch mocks * * @returns A Vitest mock function typed as the global fetch function */ export declare function createMockFetch(): typeof fetch; /** * Utility for stubbing globals with proper typing using Vitest */ export declare class VitestGlobalStubber { private stubs; stubGlobal<T>(name: string, value: T): void; restoreAllGlobals(): void; }