@vitest/mocker
Advanced tools
| import './types.d-BjI5eAwu.js'; | ||
| type Key = string | symbol; | ||
| type CreateMockInstanceProcedure = (options?: { | ||
| prototypeMembers?: (string | symbol)[]; | ||
| name?: string | symbol; | ||
| originalImplementation?: (...args: any[]) => any; | ||
| keepMembersImplementation?: boolean; | ||
| }) => any; | ||
| interface MockObjectOptions { | ||
| type: "automock" | "autospy"; | ||
| globalConstructors: GlobalConstructors; | ||
| createMockInstance: CreateMockInstanceProcedure; | ||
| } | ||
| declare function mockObject(options: MockObjectOptions, object: Record<Key, any>, mockExports?: Record<Key, any>): Record<Key, any>; | ||
| interface GlobalConstructors { | ||
| Object: ObjectConstructor; | ||
| Function: FunctionConstructor; | ||
| RegExp: RegExpConstructor; | ||
| Array: ArrayConstructor; | ||
| Map: MapConstructor; | ||
| } | ||
| export { mockObject as m }; | ||
| export type { CreateMockInstanceProcedure as C, GlobalConstructors as G, MockObjectOptions as M }; |
| import { MaybeMockedDeep } from '@vitest/spy'; | ||
| import { b as ModuleMockOptions, c as ModuleMockFactoryWithHelper, a as MockedModule, T as TestModuleMocker, M as MockerRegistry, d as MockedModuleType, e as ModuleMockContext } from './types.d-BjI5eAwu.js'; | ||
| import { C as CreateMockInstanceProcedure } from './index.d-B41z0AuW.js'; | ||
| interface CompilerHintsOptions { | ||
| /** | ||
| * This is the key used to access the globalThis object in the worker. | ||
| * Unlike `globalThisAccessor` in other APIs, this is not injected into the script. | ||
| * ```ts | ||
| * // globalThisKey: '__my_variable__' produces: | ||
| * globalThis['__my_variable__'] | ||
| * // globalThisKey: '"__my_variable__"' produces: | ||
| * globalThis['"__my_variable__"'] // notice double quotes | ||
| * ``` | ||
| * @default '__vitest_mocker__' | ||
| */ | ||
| globalThisKey?: string; | ||
| } | ||
| interface ModuleMockerCompilerHints { | ||
| hoisted: <T>(factory: () => T) => T; | ||
| mock: (path: string | Promise<unknown>, factory?: ModuleMockOptions | ModuleMockFactoryWithHelper) => void; | ||
| unmock: (path: string | Promise<unknown>) => void; | ||
| doMock: (path: string | Promise<unknown>, factory?: ModuleMockOptions | ModuleMockFactoryWithHelper) => void; | ||
| doUnmock: (path: string | Promise<unknown>) => void; | ||
| importActual: <T>(path: string) => Promise<T>; | ||
| importMock: <T>(path: string) => Promise<MaybeMockedDeep<T>>; | ||
| } | ||
| declare function createCompilerHints(options?: CompilerHintsOptions): ModuleMockerCompilerHints; | ||
| interface ModuleMockerInterceptor { | ||
| register: (module: MockedModule) => Promise<void>; | ||
| delete: (url: string) => Promise<void>; | ||
| invalidate: () => Promise<void>; | ||
| } | ||
| declare class ModuleMocker implements TestModuleMocker { | ||
| private interceptor; | ||
| private rpc; | ||
| private createMockInstance; | ||
| private config; | ||
| protected registry: MockerRegistry; | ||
| private queue; | ||
| private mockedIds; | ||
| constructor(interceptor: ModuleMockerInterceptor, rpc: ModuleMockerRPC, createMockInstance: CreateMockInstanceProcedure, config: ModuleMockerConfig); | ||
| prepare(): Promise<void>; | ||
| resolveFactoryModule(id: string): Promise<Record<string | symbol, any>>; | ||
| getFactoryModule(id: string): any; | ||
| invalidate(): Promise<void>; | ||
| importActual<T>(id: string, importer: string): Promise<T>; | ||
| protected getBaseUrl(): string; | ||
| importMock<T>(rawId: string, importer: string): Promise<T>; | ||
| mockObject(object: Record<string | symbol, any>, moduleType?: "automock" | "autospy"): Record<string | symbol, any>; | ||
| mockObject(object: Record<string | symbol, any>, mockExports: Record<string | symbol, any> | undefined, moduleType?: "automock" | "autospy"): Record<string | symbol, any>; | ||
| getMockContext(): ModuleMockContext; | ||
| queueMock(rawId: string, importer: string, factoryOrOptions?: ModuleMockOptions | (() => any)): void; | ||
| queueUnmock(id: string, importer: string): void; | ||
| wrapDynamicImport<T>(moduleFactory: () => Promise<T>): Promise<T>; | ||
| getMockedModuleById(id: string): MockedModule | undefined; | ||
| reset(): void; | ||
| private resolveMockPath; | ||
| } | ||
| interface ResolveIdResult { | ||
| id: string; | ||
| url: string; | ||
| optimized: boolean; | ||
| } | ||
| interface ResolveMockResult { | ||
| mockType: MockedModuleType; | ||
| resolvedId: string; | ||
| resolvedUrl: string; | ||
| redirectUrl?: string | null; | ||
| needsInterop?: boolean; | ||
| } | ||
| interface ModuleMockerRPC { | ||
| invalidate: (ids: string[]) => Promise<void>; | ||
| resolveId: (id: string, importer: string) => Promise<ResolveIdResult | null>; | ||
| resolveMock: (id: string, importer: string, options: { | ||
| mock: "spy" | "factory" | "auto"; | ||
| }) => Promise<ResolveMockResult>; | ||
| } | ||
| interface ModuleMockerConfig { | ||
| root: string; | ||
| } | ||
| export { ModuleMocker as b, createCompilerHints as f }; | ||
| export type { CompilerHintsOptions as C, ModuleMockerInterceptor as M, ResolveIdResult as R, ModuleMockerCompilerHints as a, ModuleMockerConfig as c, ModuleMockerRPC as d, ResolveMockResult as e }; |
| declare class MockerRegistry { | ||
| private readonly registryByUrl; | ||
| private readonly registryById; | ||
| clear(): void; | ||
| keys(): IterableIterator<string>; | ||
| add(mock: MockedModule): void; | ||
| register(json: MockedModuleSerialized): MockedModule; | ||
| register(type: "redirect", raw: string, id: string, url: string, redirect: string): RedirectedModule; | ||
| register(type: "manual", raw: string, id: string, url: string, factory: () => any): ManualMockedModule; | ||
| register(type: "automock", raw: string, id: string, url: string): AutomockedModule; | ||
| register(type: "autospy", id: string, raw: string, url: string): AutospiedModule; | ||
| delete(id: string): void; | ||
| deleteById(id: string): void; | ||
| get(id: string): MockedModule | undefined; | ||
| getById(id: string): MockedModule | undefined; | ||
| has(id: string): boolean; | ||
| } | ||
| type MockedModule = AutomockedModule | AutospiedModule | ManualMockedModule | RedirectedModule; | ||
| type MockedModuleType = "automock" | "autospy" | "manual" | "redirect"; | ||
| type MockedModuleSerialized = AutomockedModuleSerialized | AutospiedModuleSerialized | ManualMockedModuleSerialized | RedirectedModuleSerialized; | ||
| declare class AutomockedModule { | ||
| raw: string; | ||
| id: string; | ||
| url: string; | ||
| readonly type = "automock"; | ||
| constructor(raw: string, id: string, url: string); | ||
| static fromJSON(data: AutomockedModuleSerialized): AutospiedModule; | ||
| toJSON(): AutomockedModuleSerialized; | ||
| } | ||
| interface AutomockedModuleSerialized { | ||
| type: "automock"; | ||
| url: string; | ||
| raw: string; | ||
| id: string; | ||
| } | ||
| declare class AutospiedModule { | ||
| raw: string; | ||
| id: string; | ||
| url: string; | ||
| readonly type = "autospy"; | ||
| constructor(raw: string, id: string, url: string); | ||
| static fromJSON(data: AutospiedModuleSerialized): AutospiedModule; | ||
| toJSON(): AutospiedModuleSerialized; | ||
| } | ||
| interface AutospiedModuleSerialized { | ||
| type: "autospy"; | ||
| url: string; | ||
| raw: string; | ||
| id: string; | ||
| } | ||
| declare class RedirectedModule { | ||
| raw: string; | ||
| id: string; | ||
| url: string; | ||
| redirect: string; | ||
| readonly type = "redirect"; | ||
| constructor(raw: string, id: string, url: string, redirect: string); | ||
| static fromJSON(data: RedirectedModuleSerialized): RedirectedModule; | ||
| toJSON(): RedirectedModuleSerialized; | ||
| } | ||
| interface RedirectedModuleSerialized { | ||
| type: "redirect"; | ||
| url: string; | ||
| id: string; | ||
| raw: string; | ||
| redirect: string; | ||
| } | ||
| declare class ManualMockedModule<T = any> { | ||
| raw: string; | ||
| id: string; | ||
| url: string; | ||
| factory: () => T; | ||
| cache: T | undefined; | ||
| readonly type = "manual"; | ||
| constructor(raw: string, id: string, url: string, factory: () => T); | ||
| resolve(): T; | ||
| static fromJSON(data: ManualMockedModuleSerialized, factory: () => any): ManualMockedModule; | ||
| toJSON(): ManualMockedModuleSerialized; | ||
| } | ||
| interface ManualMockedModuleSerialized { | ||
| type: "manual"; | ||
| url: string; | ||
| id: string; | ||
| raw: string; | ||
| } | ||
| type Awaitable<T> = T | PromiseLike<T>; | ||
| type ModuleMockFactoryWithHelper<M = unknown> = (importOriginal: <T extends M = M>() => Promise<T>) => Awaitable<Partial<M>>; | ||
| type ModuleMockFactory = () => any; | ||
| interface ModuleMockOptions { | ||
| spy?: boolean; | ||
| } | ||
| interface ServerMockResolution { | ||
| mockType: "manual" | "redirect" | "automock" | "autospy"; | ||
| resolvedId: string; | ||
| resolvedUrl: string; | ||
| needsInterop?: boolean; | ||
| redirectUrl?: string | null; | ||
| } | ||
| interface ServerIdResolution { | ||
| id: string; | ||
| url: string; | ||
| optimized: boolean; | ||
| } | ||
| interface ModuleMockContext { | ||
| /** | ||
| * When mocking with a factory, this refers to the module that imported the mock. | ||
| */ | ||
| callstack: null | string[]; | ||
| } | ||
| interface TestModuleMocker { | ||
| queueMock(id: string, importer: string, factoryOrOptions?: ModuleMockFactory | ModuleMockOptions): void; | ||
| queueUnmock(id: string, importer: string): void; | ||
| importActual<T>(rawId: string, importer: string, callstack?: string[] | null): Promise<T>; | ||
| importMock(rawId: string, importer: string): Promise<any>; | ||
| mockObject(object: Record<string | symbol, any>, moduleType?: "automock" | "autospy"): Record<string | symbol, any>; | ||
| mockObject(object: Record<string | symbol, any>, mockExports: Record<string | symbol, any> | undefined, moduleType?: "automock" | "autospy"): Record<string | symbol, any>; | ||
| getMockContext(): ModuleMockContext; | ||
| reset(): void; | ||
| } | ||
| export { AutomockedModule as A, MockerRegistry as M, RedirectedModule as R, AutospiedModule as h, ManualMockedModule as j }; | ||
| export type { ServerMockResolution as S, TestModuleMocker as T, MockedModule as a, ModuleMockOptions as b, ModuleMockFactoryWithHelper as c, MockedModuleType as d, ModuleMockContext as e, ServerIdResolution as f, AutomockedModuleSerialized as g, AutospiedModuleSerialized as i, ManualMockedModuleSerialized as k, MockedModuleSerialized as l, ModuleMockFactory as m, RedirectedModuleSerialized as n }; |
@@ -1,7 +0,7 @@ | ||
| import { M as ModuleMockerInterceptor } from './mocker.d-mKp5A05N.js'; | ||
| export { C as CompilerHintsOptions, b as ModuleMocker, a as ModuleMockerCompilerHints, c as ModuleMockerConfig, d as ModuleMockerRPC, R as ResolveIdResult, e as ResolveMockResult, f as createCompilerHints } from './mocker.d-mKp5A05N.js'; | ||
| import { M as ModuleMockerInterceptor } from './mocker.d-QEntlm6J.js'; | ||
| export { C as CompilerHintsOptions, b as ModuleMocker, a as ModuleMockerCompilerHints, c as ModuleMockerConfig, d as ModuleMockerRPC, R as ResolveIdResult, e as ResolveMockResult, f as createCompilerHints } from './mocker.d-QEntlm6J.js'; | ||
| import { StartOptions, SetupWorker } from 'msw/browser'; | ||
| import { M as MockerRegistry, a as MockedModule } from './types.d-Chmzx7Av.js'; | ||
| import { M as MockerRegistry, a as MockedModule } from './types.d-BjI5eAwu.js'; | ||
| import '@vitest/spy'; | ||
| import './index.d-BVsHe6Qq.js'; | ||
| import './index.d-B41z0AuW.js'; | ||
@@ -8,0 +8,0 @@ interface ModuleMockerMSWInterceptorOptions { |
@@ -27,3 +27,3 @@ import MagicString from 'magic-string'; | ||
| if (node.start > pos || node.end < pos) { return } | ||
| baseVisitor[type](node, st, c); | ||
| visitNode(baseVisitor, type, node, st, c); | ||
| if (test(type, node)) { throw new Found(node, st) } | ||
@@ -40,2 +40,7 @@ })(node, state); | ||
| function visitNode(baseVisitor, type, node, st, c) { | ||
| if (baseVisitor[type] == null) { throw new Error(("No walker function defined for node type " + type)) } | ||
| baseVisitor[type](node, st, c); | ||
| } | ||
| // Node walkers. | ||
@@ -252,2 +257,9 @@ | ||
| if (node.source) { c(node.source, st, "Expression"); } | ||
| if (node.attributes) | ||
| { for (var i = 0, list = node.attributes; i < list.length; i += 1) | ||
| { | ||
| var attr = list[i]; | ||
| c(attr, st); | ||
| } } | ||
| }; | ||
@@ -258,3 +270,13 @@ base.ExportAllDeclaration = function (node, st, c) { | ||
| c(node.source, st, "Expression"); | ||
| if (node.attributes) | ||
| { for (var i = 0, list = node.attributes; i < list.length; i += 1) | ||
| { | ||
| var attr = list[i]; | ||
| c(attr, st); | ||
| } } | ||
| }; | ||
| base.ImportAttribute = function (node, st, c) { | ||
| c(node.value, st, "Expression"); | ||
| }; | ||
| base.ImportDeclaration = function (node, st, c) { | ||
@@ -268,5 +290,13 @@ for (var i = 0, list = node.specifiers; i < list.length; i += 1) | ||
| c(node.source, st, "Expression"); | ||
| if (node.attributes) | ||
| { for (var i$1 = 0, list$1 = node.attributes; i$1 < list$1.length; i$1 += 1) | ||
| { | ||
| var attr = list$1[i$1]; | ||
| c(attr, st); | ||
| } } | ||
| }; | ||
| base.ImportExpression = function (node, st, c) { | ||
| c(node.source, st, "Expression"); | ||
| if (node.options) { c(node.options, st, "Expression"); } | ||
| }; | ||
@@ -273,0 +303,0 @@ base.ImportSpecifier = base.ImportDefaultSpecifier = base.ImportNamespaceSpecifier = base.Identifier = base.PrivateIdentifier = base.Literal = ignore; |
+10
-2
@@ -420,3 +420,3 @@ import { c as createSimpleStackTrace } from './chunk-helpers.js'; | ||
| ); | ||
| return this.mockObject(moduleObject, undefined, mock.type); | ||
| return this.mockObject(moduleObject, mock.type); | ||
| } | ||
@@ -428,3 +428,11 @@ return import( | ||
| } | ||
| mockObject(object, mockExports, moduleType = "automock") { | ||
| mockObject(object, mockExportsOrModuleType, moduleType) { | ||
| let mockExports; | ||
| if (mockExportsOrModuleType === "automock" || mockExportsOrModuleType === "autospy") { | ||
| moduleType = mockExportsOrModuleType; | ||
| mockExports = undefined; | ||
| } else { | ||
| mockExports = mockExportsOrModuleType; | ||
| } | ||
| moduleType ??= "automock"; | ||
| const result = mockObject({ | ||
@@ -431,0 +439,0 @@ globalConstructors: { |
+2
-2
@@ -1,2 +0,2 @@ | ||
| export { G as GlobalConstructors, M as MockObjectOptions, m as mockObject } from './index.d-BVsHe6Qq.js'; | ||
| export { A as AutomockedModule, g as AutomockedModuleSerialized, h as AutospiedModule, i as AutospiedModuleSerialized, j as ManualMockedModule, k as ManualMockedModuleSerialized, a as MockedModule, l as MockedModuleSerialized, d as MockedModuleType, M as MockerRegistry, e as ModuleMockContext, m as ModuleMockFactory, c as ModuleMockFactoryWithHelper, b as ModuleMockOptions, R as RedirectedModule, n as RedirectedModuleSerialized, f as ServerIdResolution, S as ServerMockResolution, T as TestModuleMocker } from './types.d-Chmzx7Av.js'; | ||
| export { G as GlobalConstructors, M as MockObjectOptions, m as mockObject } from './index.d-B41z0AuW.js'; | ||
| export { A as AutomockedModule, g as AutomockedModuleSerialized, h as AutospiedModule, i as AutospiedModuleSerialized, j as ManualMockedModule, k as ManualMockedModuleSerialized, a as MockedModule, l as MockedModuleSerialized, d as MockedModuleType, M as MockerRegistry, e as ModuleMockContext, m as ModuleMockFactory, c as ModuleMockFactoryWithHelper, b as ModuleMockOptions, R as RedirectedModule, n as RedirectedModuleSerialized, f as ServerIdResolution, S as ServerMockResolution, T as TestModuleMocker } from './types.d-BjI5eAwu.js'; |
+18
-3
@@ -84,5 +84,20 @@ export { A as AutomockedModule, b as AutospiedModule, a as ManualMockedModule, M as MockerRegistry, R as RedirectedModule } from './chunk-registry.js'; | ||
| } | ||
| // Sometimes this assignment fails for some unknown reason. If it does, | ||
| // just move along. | ||
| if (!define(newContainer, property, isFunction || options.type === "autospy" ? value : {})) { | ||
| if (options.type === "autospy" && type === "Module") { | ||
| // Replace with clean object to recursively autospy exported module objects: | ||
| // export * as ns from "./ns" | ||
| // or | ||
| // import * as ns from "./ns" | ||
| // export { ns } | ||
| const exports$1 = Object.create(null); | ||
| Object.defineProperty(exports$1, Symbol.toStringTag, { | ||
| value: "Module", | ||
| configurable: true, | ||
| writable: true | ||
| }); | ||
| try { | ||
| newContainer[property] = exports$1; | ||
| } catch { | ||
| continue; | ||
| } | ||
| } else if (!define(newContainer, property, isFunction || options.type === "autospy" ? value : {})) { | ||
| continue; | ||
@@ -89,0 +104,0 @@ } |
+1
-1
@@ -7,3 +7,3 @@ import { H as HoistMocksOptions } from './hoistMocks.d-w2ILr1dG.js'; | ||
| import { SourceMap } from 'magic-string'; | ||
| import { M as MockerRegistry, S as ServerMockResolution, f as ServerIdResolution } from './types.d-Chmzx7Av.js'; | ||
| import { M as MockerRegistry, S as ServerMockResolution, f as ServerIdResolution } from './types.d-BjI5eAwu.js'; | ||
| export { findMockRedirect } from './redirect.js'; | ||
@@ -10,0 +10,0 @@ |
@@ -1,5 +0,5 @@ | ||
| import { M as ModuleMockerInterceptor, a as ModuleMockerCompilerHints, b as ModuleMocker } from './mocker.d-mKp5A05N.js'; | ||
| import { M as ModuleMockerInterceptor, a as ModuleMockerCompilerHints, b as ModuleMocker } from './mocker.d-QEntlm6J.js'; | ||
| import '@vitest/spy'; | ||
| import './types.d-Chmzx7Av.js'; | ||
| import './index.d-BVsHe6Qq.js'; | ||
| import './types.d-BjI5eAwu.js'; | ||
| import './index.d-B41z0AuW.js'; | ||
@@ -6,0 +6,0 @@ declare function registerModuleMocker(interceptor: (accessor: string) => ModuleMockerInterceptor): ModuleMockerCompilerHints; |
+6
-6
| { | ||
| "name": "@vitest/mocker", | ||
| "type": "module", | ||
| "version": "4.1.0-beta.4", | ||
| "version": "4.1.0-beta.5", | ||
| "description": "Vitest module mocker implementation", | ||
@@ -75,14 +75,14 @@ "license": "MIT", | ||
| "magic-string": "^0.30.21", | ||
| "@vitest/spy": "4.1.0-beta.4" | ||
| "@vitest/spy": "4.1.0-beta.5" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/estree": "^1.0.8", | ||
| "acorn-walk": "^8.3.4", | ||
| "acorn-walk": "^8.3.5", | ||
| "cjs-module-lexer": "^2.2.0", | ||
| "es-module-lexer": "^2.0.0", | ||
| "msw": "^2.12.7", | ||
| "msw": "^2.12.10", | ||
| "pathe": "^2.0.3", | ||
| "vite": "^6.3.5", | ||
| "@vitest/spy": "4.1.0-beta.4", | ||
| "@vitest/utils": "4.1.0-beta.4" | ||
| "@vitest/utils": "4.1.0-beta.5", | ||
| "@vitest/spy": "4.1.0-beta.5" | ||
| }, | ||
@@ -89,0 +89,0 @@ "scripts": { |
| import './types.d-Chmzx7Av.js'; | ||
| type Key = string | symbol; | ||
| type CreateMockInstanceProcedure = (options?: { | ||
| prototypeMembers?: (string | symbol)[]; | ||
| name?: string | symbol; | ||
| originalImplementation?: (...args: any[]) => any; | ||
| keepMembersImplementation?: boolean; | ||
| }) => any; | ||
| interface MockObjectOptions { | ||
| type: "automock" | "autospy"; | ||
| globalConstructors: GlobalConstructors; | ||
| createMockInstance: CreateMockInstanceProcedure; | ||
| } | ||
| declare function mockObject(options: MockObjectOptions, object: Record<Key, any>, mockExports?: Record<Key, any>): Record<Key, any>; | ||
| interface GlobalConstructors { | ||
| Object: ObjectConstructor; | ||
| Function: FunctionConstructor; | ||
| RegExp: RegExpConstructor; | ||
| Array: ArrayConstructor; | ||
| Map: MapConstructor; | ||
| } | ||
| export { mockObject as m }; | ||
| export type { CreateMockInstanceProcedure as C, GlobalConstructors as G, MockObjectOptions as M }; |
| import { MaybeMockedDeep } from '@vitest/spy'; | ||
| import { b as ModuleMockOptions, c as ModuleMockFactoryWithHelper, a as MockedModule, T as TestModuleMocker, M as MockerRegistry, d as MockedModuleType, e as ModuleMockContext } from './types.d-Chmzx7Av.js'; | ||
| import { C as CreateMockInstanceProcedure } from './index.d-BVsHe6Qq.js'; | ||
| interface CompilerHintsOptions { | ||
| /** | ||
| * This is the key used to access the globalThis object in the worker. | ||
| * Unlike `globalThisAccessor` in other APIs, this is not injected into the script. | ||
| * ```ts | ||
| * // globalThisKey: '__my_variable__' produces: | ||
| * globalThis['__my_variable__'] | ||
| * // globalThisKey: '"__my_variable__"' produces: | ||
| * globalThis['"__my_variable__"'] // notice double quotes | ||
| * ``` | ||
| * @default '__vitest_mocker__' | ||
| */ | ||
| globalThisKey?: string; | ||
| } | ||
| interface ModuleMockerCompilerHints { | ||
| hoisted: <T>(factory: () => T) => T; | ||
| mock: (path: string | Promise<unknown>, factory?: ModuleMockOptions | ModuleMockFactoryWithHelper) => void; | ||
| unmock: (path: string | Promise<unknown>) => void; | ||
| doMock: (path: string | Promise<unknown>, factory?: ModuleMockOptions | ModuleMockFactoryWithHelper) => void; | ||
| doUnmock: (path: string | Promise<unknown>) => void; | ||
| importActual: <T>(path: string) => Promise<T>; | ||
| importMock: <T>(path: string) => Promise<MaybeMockedDeep<T>>; | ||
| } | ||
| declare function createCompilerHints(options?: CompilerHintsOptions): ModuleMockerCompilerHints; | ||
| interface ModuleMockerInterceptor { | ||
| register: (module: MockedModule) => Promise<void>; | ||
| delete: (url: string) => Promise<void>; | ||
| invalidate: () => Promise<void>; | ||
| } | ||
| declare class ModuleMocker implements TestModuleMocker { | ||
| private interceptor; | ||
| private rpc; | ||
| private createMockInstance; | ||
| private config; | ||
| protected registry: MockerRegistry; | ||
| private queue; | ||
| private mockedIds; | ||
| constructor(interceptor: ModuleMockerInterceptor, rpc: ModuleMockerRPC, createMockInstance: CreateMockInstanceProcedure, config: ModuleMockerConfig); | ||
| prepare(): Promise<void>; | ||
| resolveFactoryModule(id: string): Promise<Record<string | symbol, any>>; | ||
| getFactoryModule(id: string): any; | ||
| invalidate(): Promise<void>; | ||
| importActual<T>(id: string, importer: string): Promise<T>; | ||
| protected getBaseUrl(): string; | ||
| importMock<T>(rawId: string, importer: string): Promise<T>; | ||
| mockObject(object: Record<string | symbol, any>, mockExports: Record<string | symbol, any> | undefined, moduleType?: "automock" | "autospy"): Record<string | symbol, any>; | ||
| getMockContext(): ModuleMockContext; | ||
| queueMock(rawId: string, importer: string, factoryOrOptions?: ModuleMockOptions | (() => any)): void; | ||
| queueUnmock(id: string, importer: string): void; | ||
| wrapDynamicImport<T>(moduleFactory: () => Promise<T>): Promise<T>; | ||
| getMockedModuleById(id: string): MockedModule | undefined; | ||
| reset(): void; | ||
| private resolveMockPath; | ||
| } | ||
| interface ResolveIdResult { | ||
| id: string; | ||
| url: string; | ||
| optimized: boolean; | ||
| } | ||
| interface ResolveMockResult { | ||
| mockType: MockedModuleType; | ||
| resolvedId: string; | ||
| resolvedUrl: string; | ||
| redirectUrl?: string | null; | ||
| needsInterop?: boolean; | ||
| } | ||
| interface ModuleMockerRPC { | ||
| invalidate: (ids: string[]) => Promise<void>; | ||
| resolveId: (id: string, importer: string) => Promise<ResolveIdResult | null>; | ||
| resolveMock: (id: string, importer: string, options: { | ||
| mock: "spy" | "factory" | "auto"; | ||
| }) => Promise<ResolveMockResult>; | ||
| } | ||
| interface ModuleMockerConfig { | ||
| root: string; | ||
| } | ||
| export { ModuleMocker as b, createCompilerHints as f }; | ||
| export type { CompilerHintsOptions as C, ModuleMockerInterceptor as M, ResolveIdResult as R, ModuleMockerCompilerHints as a, ModuleMockerConfig as c, ModuleMockerRPC as d, ResolveMockResult as e }; |
| declare class MockerRegistry { | ||
| private readonly registryByUrl; | ||
| private readonly registryById; | ||
| clear(): void; | ||
| keys(): IterableIterator<string>; | ||
| add(mock: MockedModule): void; | ||
| register(json: MockedModuleSerialized): MockedModule; | ||
| register(type: "redirect", raw: string, id: string, url: string, redirect: string): RedirectedModule; | ||
| register(type: "manual", raw: string, id: string, url: string, factory: () => any): ManualMockedModule; | ||
| register(type: "automock", raw: string, id: string, url: string): AutomockedModule; | ||
| register(type: "autospy", id: string, raw: string, url: string): AutospiedModule; | ||
| delete(id: string): void; | ||
| deleteById(id: string): void; | ||
| get(id: string): MockedModule | undefined; | ||
| getById(id: string): MockedModule | undefined; | ||
| has(id: string): boolean; | ||
| } | ||
| type MockedModule = AutomockedModule | AutospiedModule | ManualMockedModule | RedirectedModule; | ||
| type MockedModuleType = "automock" | "autospy" | "manual" | "redirect"; | ||
| type MockedModuleSerialized = AutomockedModuleSerialized | AutospiedModuleSerialized | ManualMockedModuleSerialized | RedirectedModuleSerialized; | ||
| declare class AutomockedModule { | ||
| raw: string; | ||
| id: string; | ||
| url: string; | ||
| readonly type = "automock"; | ||
| constructor(raw: string, id: string, url: string); | ||
| static fromJSON(data: AutomockedModuleSerialized): AutospiedModule; | ||
| toJSON(): AutomockedModuleSerialized; | ||
| } | ||
| interface AutomockedModuleSerialized { | ||
| type: "automock"; | ||
| url: string; | ||
| raw: string; | ||
| id: string; | ||
| } | ||
| declare class AutospiedModule { | ||
| raw: string; | ||
| id: string; | ||
| url: string; | ||
| readonly type = "autospy"; | ||
| constructor(raw: string, id: string, url: string); | ||
| static fromJSON(data: AutospiedModuleSerialized): AutospiedModule; | ||
| toJSON(): AutospiedModuleSerialized; | ||
| } | ||
| interface AutospiedModuleSerialized { | ||
| type: "autospy"; | ||
| url: string; | ||
| raw: string; | ||
| id: string; | ||
| } | ||
| declare class RedirectedModule { | ||
| raw: string; | ||
| id: string; | ||
| url: string; | ||
| redirect: string; | ||
| readonly type = "redirect"; | ||
| constructor(raw: string, id: string, url: string, redirect: string); | ||
| static fromJSON(data: RedirectedModuleSerialized): RedirectedModule; | ||
| toJSON(): RedirectedModuleSerialized; | ||
| } | ||
| interface RedirectedModuleSerialized { | ||
| type: "redirect"; | ||
| url: string; | ||
| id: string; | ||
| raw: string; | ||
| redirect: string; | ||
| } | ||
| declare class ManualMockedModule<T = any> { | ||
| raw: string; | ||
| id: string; | ||
| url: string; | ||
| factory: () => T; | ||
| cache: T | undefined; | ||
| readonly type = "manual"; | ||
| constructor(raw: string, id: string, url: string, factory: () => T); | ||
| resolve(): T; | ||
| static fromJSON(data: ManualMockedModuleSerialized, factory: () => any): ManualMockedModule; | ||
| toJSON(): ManualMockedModuleSerialized; | ||
| } | ||
| interface ManualMockedModuleSerialized { | ||
| type: "manual"; | ||
| url: string; | ||
| id: string; | ||
| raw: string; | ||
| } | ||
| type Awaitable<T> = T | PromiseLike<T>; | ||
| type ModuleMockFactoryWithHelper<M = unknown> = (importOriginal: <T extends M = M>() => Promise<T>) => Awaitable<Partial<M>>; | ||
| type ModuleMockFactory = () => any; | ||
| interface ModuleMockOptions { | ||
| spy?: boolean; | ||
| } | ||
| interface ServerMockResolution { | ||
| mockType: "manual" | "redirect" | "automock" | "autospy"; | ||
| resolvedId: string; | ||
| resolvedUrl: string; | ||
| needsInterop?: boolean; | ||
| redirectUrl?: string | null; | ||
| } | ||
| interface ServerIdResolution { | ||
| id: string; | ||
| url: string; | ||
| optimized: boolean; | ||
| } | ||
| interface ModuleMockContext { | ||
| /** | ||
| * When mocking with a factory, this refers to the module that imported the mock. | ||
| */ | ||
| callstack: null | string[]; | ||
| } | ||
| interface TestModuleMocker { | ||
| queueMock(id: string, importer: string, factoryOrOptions?: ModuleMockFactory | ModuleMockOptions): void; | ||
| queueUnmock(id: string, importer: string): void; | ||
| importActual<T>(rawId: string, importer: string, callstack?: string[] | null): Promise<T>; | ||
| importMock(rawId: string, importer: string): Promise<any>; | ||
| mockObject(object: Record<string | symbol, any>, mockExports?: Record<string | symbol, any>, behavior?: "automock" | "autospy"): Record<string | symbol, any>; | ||
| getMockContext(): ModuleMockContext; | ||
| reset(): void; | ||
| } | ||
| export { AutomockedModule as A, MockerRegistry as M, RedirectedModule as R, AutospiedModule as h, ManualMockedModule as j }; | ||
| export type { ServerMockResolution as S, TestModuleMocker as T, MockedModule as a, ModuleMockOptions as b, ModuleMockFactoryWithHelper as c, MockedModuleType as d, ModuleMockContext as e, ServerIdResolution as f, AutomockedModuleSerialized as g, AutospiedModuleSerialized as i, ManualMockedModuleSerialized as k, MockedModuleSerialized as l, ModuleMockFactory as m, RedirectedModuleSerialized as n }; |
Sorry, the diff of this file is too big to display
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
186646
0.95%4131
1.25%+ Added
- Removed
Updated