import { type WebPluginFn } from '../testing/web_plugin.js'; import { TestContext } from '../testing/test_context.js'; declare global { interface Window { __LUPA_MOCKS__?: Record>>; } } /** * Developer-facing API for ESM module mocking. * Available in browser tests via the `module` fixture on `TestContext`. */ export declare class ModuleMock { #private; constructor(context: TestContext); /** * Register a mock for the given module path. * * `importMetaUrl` must be `import.meta.url` from your test file so that the * relative path resolves correctly against your project, not Lupa's internals. * * Accepts either a plain object or a factory function that receives the real * module. Both forms are merged on top of the real module — exports you do not * override are preserved from the original implementation. * * Must be called before `module.import()` in your test. * * @example * // Object form * await module.mock('../src/sdk.js', import.meta.url, { * currentUser: { name: 'Alice' }, * }) * * // Factory form — receives the real module, return only what you want to override * await module.mock('../src/auth.js', import.meta.url, (real) => ({ * authenticate: (token) => token.startsWith('test-') || real.authenticate(token), * })) */ mock(path: string, importMetaUrl: string, factoryOrObject: Record | ((real: Record) => Record | Promise>)): Promise; /** * Dynamically import a module with cache-busting so the mock registry is consulted. * All transitive imports in the module tree will also be cache-busted. * * `importMetaUrl` must be `import.meta.url` from your test file so that the * relative path resolves correctly against your project, not Lupa's internals. * * @example * await module.import('../src/ui-dashboard.js', import.meta.url) */ ['import']>(path: string, importMetaUrl: string): Promise; } /** * Browser test plugin that installs the `module` fixture on `TestContext`. * * Registered automatically when you add `moduleMocking()` to your `lupa.config.ts`. */ declare const setup: WebPluginFn; declare module '../testing/test_context.js' { interface TestContext { module: ModuleMock; } } export default setup;