/** * Custom Module Stubs - Layered Loader Hook (TypeScript, ESM) * * Purpose: * Many teams need to stub niche third‑party modules beyond the built‑ins (axios, winston) * without editing qtests core. This module adds a safe, additive hook on top of qtests * setup so tests can register ad‑hoc module stubs programmatically. * * Design: * - Does NOT modify qtests core setup.js implementation * - Patches Module._load a second time to return in‑memory exports for known ids * - Works even for modules that aren’t installed (useful for service SDKs) * - Honors QTESTS_SILENT to avoid noisy logs in CI * - Safe to import multiple times; patch is idempotent * * Usage: * import '../setup.js' // ALWAYS first * import { registerModuleStub } from './customStubs.js' * registerModuleStub('some-sdk', { call: () => 'ok' }) * const sdk = require('some-sdk') // returns the stub above * * Caveats: * - Must run BEFORE requiring the target module * - If the real module was already loaded, unregister + require cache tricks are risky; * prefer clean order: setup -> register -> require. */ type StubValue = any | (() => any); /** * Register a custom module stub. * Must be called BEFORE requiring the target module in tests. * * @param moduleId - The exact module id used in require/import (e.g., 'uuid') * @param stub - Either an exports object or a zero‑arg factory returning exports */ declare function registerModuleStub(moduleId: string, stub: StubValue): void; /** * Remove a previously registered custom stub. * Does not alter require cache for safety (tests should control load order). * * @param moduleId - The module id to unregister */ declare function unregisterModuleStub(moduleId: string): void; /** * List all currently registered custom stubs (ids only). * Useful for debugging and assertions in tests. */ declare function listModuleStubs(): string[]; /** * Clear all custom stubs. Safe helper for afterEach blocks. * Does not clear Node's module cache – that is an explicit choice left to tests. */ declare function clearAllModuleStubs(): void; export { registerModuleStub, unregisterModuleStub, listModuleStubs, clearAllModuleStubs }; /** * Resolve a registered stub without triggering Node resolution. * Returns the concrete exports object if present, otherwise undefined. */ export declare function resolveModuleStub(moduleId: string): any | undefined; //# sourceMappingURL=customStubs.d.ts.map