@corez/mock
Advanced tools
Comparing version 0.13.1 to 0.13.2
@@ -1,202 +0,8 @@ | ||
import { Faker } from '@faker-js/faker'; | ||
import { mock } from './mock.js'; | ||
export { AsyncMockedFunction, Constructor, CreateSpy, DeepPartial, EnhancedMockOptionsInput, FakerOptions, JestMatcherExtensions, JestMockedFunction, KeepOriginalFn, KeepOriginalMatcher, KeepOriginalPattern, MockAPI, MockBehavior, MockCallback, MockConfig, MockConfigObject, MockData, MockDecorator, MockMultipleConfig, MockMultipleOptions, MockOptions, MockOptionsInput, MockProperty, MockValue, MockedClass, MockedFunction, MockedObject, PromiseOrValue } from './types.js'; | ||
export { DecoratorError, Mock } from './decorators.js'; | ||
export { Faker } from '@faker-js/faker'; | ||
/** | ||
* Basic types | ||
*/ | ||
type Constructor<T = any> = new (...args: any[]) => T; | ||
type DeepPartial<T> = T extends object ? { | ||
[P in keyof T]?: DeepPartial<T[P]>; | ||
} : T; | ||
type PromiseOrValue<T> = T | Promise<T>; | ||
/** | ||
* Pattern matching types | ||
*/ | ||
type KeepOriginalPattern = string | RegExp; | ||
type KeepOriginalMatcher = KeepOriginalPattern | KeepOriginalPattern[] | ((property: MockProperty) => boolean); | ||
/** | ||
* Property information for mock configuration | ||
*/ | ||
interface MockProperty { | ||
property: string; | ||
descriptor: PropertyDescriptor; | ||
original: unknown; | ||
mock: unknown; | ||
} | ||
/** | ||
* Core function types | ||
*/ | ||
type KeepOriginalFn = (property: MockProperty) => boolean; | ||
type CreateSpy = () => MockedFunction; | ||
/** | ||
* Configuration types | ||
*/ | ||
interface MockConfig { | ||
/** | ||
* Function to determine if a property should keep its original implementation | ||
*/ | ||
keepOriginal?: KeepOriginalFn; | ||
/** | ||
* Function to create a new spy function | ||
*/ | ||
createSpy?: CreateSpy; | ||
} | ||
type MockBehavior = Required<MockConfig>; | ||
interface MockConfigObject { | ||
/** | ||
* Function or pattern to determine if a property should keep its original implementation | ||
*/ | ||
keepOriginal?: KeepOriginalMatcher; | ||
/** | ||
* Function to create a new spy function | ||
*/ | ||
createSpy?: CreateSpy; | ||
} | ||
type MockOptions = KeepOriginalMatcher | MockConfigObject; | ||
type MockOptionsInput = MockConfigObject | KeepOriginalMatcher; | ||
/** | ||
* Enhanced mock options that can be passed to Mock decorator | ||
*/ | ||
type EnhancedMockOptionsInput = MockOptionsInput | ((...args: any[]) => any) | any; | ||
/** | ||
* Mock function types | ||
*/ | ||
interface MockedFunction<TArgs extends any[] = any[], TReturn = any> { | ||
(...args: TArgs): TReturn; | ||
mock: { | ||
calls: TArgs[]; | ||
results: TReturn[]; | ||
instances: any[]; | ||
implementation: ((...args: TArgs) => TReturn) | null; | ||
}; | ||
mockImplementation<T = TReturn>(fn: (...args: TArgs) => T): MockedFunction<TArgs, T>; | ||
mockReturnValue<T = TReturn>(value: T): MockedFunction<TArgs, T>; | ||
mockResolvedValue<T>(value: PromiseOrValue<T>): MockedFunction<TArgs, Promise<T>>; | ||
mockRejectedValue<TError>(error: PromiseOrValue<TError>): MockedFunction<TArgs, Promise<never>>; | ||
mockReset(): void; | ||
} | ||
interface AsyncMockedFunction<TArgs extends any[] = any[], TReturn = any> extends MockedFunction<TArgs, Promise<TReturn>> { | ||
mockResolvedValue<T>(value: PromiseOrValue<T>): AsyncMockedFunction<TArgs, Awaited<T>>; | ||
mockRejectedValue<TError>(error: PromiseOrValue<TError>): AsyncMockedFunction<TArgs, never>; | ||
} | ||
/** | ||
* Mock object types | ||
*/ | ||
type MockedObject<T> = { | ||
[P in keyof T]: T[P] extends (...args: infer A) => infer R ? MockedFunction<A, R> : T[P]; | ||
} & { | ||
mockClear(): void; | ||
mockReset(): void; | ||
mockRestore(): void; | ||
mockImplementation(implementation: DeepPartial<T>): MockedObject<T>; | ||
mockReturnValue<TReturn>(value: TReturn): MockedObject<T>; | ||
mockResolvedValue<TReturn>(value: PromiseOrValue<TReturn>): MockedObject<T>; | ||
mockRejectedValue<TError = Error>(error: PromiseOrValue<TError>): MockedObject<T>; | ||
}; | ||
/** | ||
* Mock class types | ||
*/ | ||
type MockedClass<T extends new (...args: unknown[]) => unknown> = T & { | ||
new (...args: ConstructorParameters<T>): InstanceType<T>; | ||
prototype: InstanceType<T>; | ||
mock: { | ||
instances: InstanceType<T>[]; | ||
implementation: T | null; | ||
}; | ||
mockImplementation(fn: new (...args: ConstructorParameters<T>) => InstanceType<T>): MockedClass<T>; | ||
mockReset(): void; | ||
} & { | ||
[P in keyof T]: T[P] extends (...args: infer Args) => infer Return ? MockedFunction<Args, Return> : T[P]; | ||
}; | ||
/** | ||
* Metadata for mock tracking | ||
*/ | ||
interface MockData<T = unknown> { | ||
type: 'function' | 'object' | 'class'; | ||
original: T; | ||
options: MockOptionsInput; | ||
} | ||
/** | ||
* Core mock API | ||
*/ | ||
interface MockAPI { | ||
<T extends object>(target: Constructor<T>, overrides?: Partial<T>, options?: MockOptionsInput): InstanceType<Constructor<T>>; | ||
<T extends object>(target: T, overrides?: Partial<T>, options?: MockOptionsInput): MockedObject<T>; | ||
function<TArgs extends any[] = any[], TReturn = any>(options?: MockOptionsInput): MockedFunction<TArgs, TReturn>; | ||
object<T extends object>(target: T | undefined, options?: MockOptionsInput): MockedObject<T>; | ||
class<T extends new (...args: any[]) => any>(target: T, options?: MockOptionsInput): MockedClass<T>; | ||
instance<T extends object>(target: Constructor<T> | T, overrides?: Partial<T>, options?: MockOptionsInput): T; | ||
reset(mock: MockedFunction | MockedObject<unknown>): void; | ||
getOriginal<T>(mock: MockedFunction | MockedObject<T> | MockedClass<any>): T; | ||
isValid(value: unknown): boolean; | ||
configure(config?: MockConfig): MockAPI; | ||
resetConfig(): MockAPI; | ||
} | ||
/** | ||
* Jest adapter types | ||
*/ | ||
interface JestMatcherExtensions { | ||
asymmetricMatch?(other: unknown): boolean; | ||
} | ||
type JestMockedFunction<TArgs extends any[] = any[], TReturn = any> = MockedFunction<TArgs, TReturn> & JestMatcherExtensions; | ||
/** | ||
* Options for generating multiple instances | ||
*/ | ||
interface MockMultipleOptions<T> { | ||
type: Constructor<T> | StringConstructor; | ||
count: number; | ||
} | ||
/** | ||
* Callback function type for mock value generation | ||
*/ | ||
type MockCallback = () => any; | ||
/** | ||
* Mock parameter types for different scenarios | ||
*/ | ||
interface MockMultipleConfig<T> { | ||
type: Constructor<T>; | ||
count: number; | ||
} | ||
/** | ||
* Mock value types for different scenarios | ||
*/ | ||
type MockValue<T> = T | (() => T) | RegExp | Constructor<T> | { | ||
enum: Record<string, T>; | ||
} | { | ||
type: Constructor<T>; | ||
count: number; | ||
}; | ||
/** | ||
* Mock decorator interface | ||
*/ | ||
interface MockDecorator { | ||
(target: any, context: DecoratorContext): any; | ||
(): (target: any, context: DecoratorContext) => any; | ||
<T = unknown>(optionsOrImpl: MockOptionsInput | ((...args: any[]) => T)): (target: any, context: DecoratorContext) => any; | ||
with<T>(value: T): (target: any, context: DecoratorContext) => any; | ||
with<T>(fn: () => T): (target: any, context: DecoratorContext) => any; | ||
with(regex: RegExp): (target: any, context: DecoratorContext) => any; | ||
with<T>(targetClass: Constructor<T>): (target: any, context: DecoratorContext) => any; | ||
with<T>(enumObj: { | ||
enum: Record<string, T>; | ||
}): (target: any, context: DecoratorContext) => any; | ||
with<T>(options: { | ||
type: Constructor<T>; | ||
count: number; | ||
}): (target: any, context: DecoratorContext) => any; | ||
withFaker<T>(fn: (faker: Faker) => T, options?: FakerOptions): (target: any, context: DecoratorContext) => any; | ||
} | ||
interface FakerOptions { | ||
cached?: boolean; | ||
maxAge?: number; | ||
} | ||
declare const mock: MockAPI; | ||
declare class DecoratorError extends Error { | ||
context?: string | undefined; | ||
constructor(message: string, context?: string | undefined); | ||
} | ||
declare const Mock: MockDecorator; | ||
export { type AsyncMockedFunction, type Constructor, type CreateSpy, DecoratorError, type DeepPartial, type EnhancedMockOptionsInput, type FakerOptions, type JestMatcherExtensions, type JestMockedFunction, type KeepOriginalFn, type KeepOriginalMatcher, type KeepOriginalPattern, Mock, type MockAPI, type MockBehavior, type MockCallback, type MockConfig, type MockConfigObject, type MockData, type MockDecorator, type MockMultipleConfig, type MockMultipleOptions, type MockOptions, type MockOptionsInput, type MockProperty, type MockValue, type MockedClass, type MockedFunction, type MockedObject, type PromiseOrValue, mock as default }; | ||
export { mock as default }; |
{ | ||
"name": "@corez/mock", | ||
"version": "0.13.1", | ||
"version": "0.13.2", | ||
"description": "A powerful and flexible TypeScript mocking library for testing", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
45
0
217536
2697
1