@storybook/jest
Advanced tools
Comparing version 0.2.3--canary.47.6407557579.0 to 0.2.3--canary.47.6408168214.0
/// <reference types="jest" /> | ||
/// <reference types="@testing-library/jest-dom" /> | ||
import * as mock from 'jest-mock'; | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
declare type MockFunctionMetadataType = 'object' | 'array' | 'regexp' | 'function' | 'constant' | 'collection' | 'null' | 'undefined'; | ||
declare type MockFunctionMetadata<T, Y extends Array<unknown>, Type = MockFunctionMetadataType> = { | ||
ref?: number; | ||
members?: Record<string, MockFunctionMetadata<T, Y>>; | ||
mockImpl?: (...args: Y) => T; | ||
name?: string; | ||
refID?: number; | ||
type?: Type; | ||
value?: T; | ||
length?: number; | ||
}; | ||
declare type MockableFunction = (...args: Array<any>) => any; | ||
declare type MethodKeysOf<T> = { | ||
[K in keyof T]: T[K] extends MockableFunction ? K : never; | ||
}[keyof T]; | ||
declare type PropertyKeysOf<T> = { | ||
[K in keyof T]: T[K] extends MockableFunction ? never : K; | ||
}[keyof T]; | ||
declare type ArgumentsOf<T> = T extends (...args: infer A) => any ? A : never; | ||
declare type ConstructorArgumentsOf<T> = T extends new (...args: infer A) => any ? A : never; | ||
declare type MaybeMockedConstructor<T> = T extends new (...args: Array<any>) => infer R ? MockInstance<R, ConstructorArgumentsOf<T>> : T; | ||
declare type MockedFunction<T extends MockableFunction> = MockWithArgs<T> & { | ||
[K in keyof T]: T[K]; | ||
}; | ||
declare type MockedFunctionDeep<T extends MockableFunction> = MockWithArgs<T> & MockedObjectDeep<T>; | ||
declare type MockedObject<T> = MaybeMockedConstructor<T> & { | ||
[K in MethodKeysOf<T>]: T[K] extends MockableFunction ? MockedFunction<T[K]> : T[K]; | ||
} & { | ||
[K in PropertyKeysOf<T>]: T[K]; | ||
}; | ||
declare type MockedObjectDeep<T> = MaybeMockedConstructor<T> & { | ||
[K in MethodKeysOf<T>]: T[K] extends MockableFunction ? MockedFunctionDeep<T[K]> : T[K]; | ||
} & { | ||
[K in PropertyKeysOf<T>]: MaybeMockedDeep<T[K]>; | ||
}; | ||
declare type MaybeMockedDeep<T> = T extends MockableFunction ? MockedFunctionDeep<T> : T extends object ? MockedObjectDeep<T> : T; | ||
declare type MaybeMocked<T> = T extends MockableFunction ? MockedFunction<T> : T extends object ? MockedObject<T> : T; | ||
declare type ArgsType<T> = T extends (...args: infer A) => any ? A : never; | ||
declare type Mocked<T> = { | ||
[P in keyof T]: T[P] extends (...args: Array<any>) => any ? MockInstance<ReturnType<T[P]>, ArgsType<T[P]>> : T[P] extends Constructable ? MockedClass<T[P]> : T[P]; | ||
} & T; | ||
declare type MockedClass<T extends Constructable> = MockInstance<InstanceType<T>, T extends new (...args: infer P) => any ? P : never> & { | ||
prototype: T extends { | ||
prototype: any; | ||
} ? Mocked<T['prototype']> : never; | ||
} & T; | ||
interface Constructable { | ||
new (...args: Array<any>): any; | ||
} | ||
interface MockWithArgs<T extends MockableFunction> extends MockInstance<ReturnType<T>, ArgumentsOf<T>> { | ||
new (...args: ConstructorArgumentsOf<T>): T; | ||
(...args: ArgumentsOf<T>): ReturnType<T>; | ||
} | ||
interface Mock<T, Y extends Array<unknown> = Array<unknown>> extends Function, MockInstance<T, Y> { | ||
new (...args: Y): T; | ||
(...args: Y): T; | ||
} | ||
interface SpyInstance<T, Y extends Array<unknown>> extends MockInstance<T, Y> { | ||
} | ||
interface MockInstance<T, Y extends Array<unknown>> { | ||
_isMockFunction: true; | ||
_protoImpl: Function; | ||
getMockName(): string; | ||
getMockImplementation(): Function | undefined; | ||
mock: MockFunctionState<T, Y>; | ||
mockClear(): this; | ||
mockReset(): this; | ||
mockRestore(): void; | ||
mockImplementation(fn: (...args: Y) => T): this; | ||
mockImplementation(fn: () => Promise<T>): this; | ||
mockImplementationOnce(fn: (...args: Y) => T): this; | ||
mockImplementationOnce(fn: () => Promise<T>): this; | ||
mockName(name: string): this; | ||
mockReturnThis(): this; | ||
mockReturnValue(value: T): this; | ||
mockReturnValueOnce(value: T): this; | ||
mockResolvedValue(value: Unpromisify<T>): this; | ||
mockResolvedValueOnce(value: Unpromisify<T>): this; | ||
mockRejectedValue(value: unknown): this; | ||
mockRejectedValueOnce(value: unknown): this; | ||
} | ||
declare type Unpromisify<T> = T extends Promise<infer R> ? R : never; | ||
/** | ||
* Possible types of a MockFunctionResult. | ||
* 'return': The call completed by returning normally. | ||
* 'throw': The call completed by throwing a value. | ||
* 'incomplete': The call has not completed yet. This is possible if you read | ||
* the mock function result from within the mock function itself | ||
* (or a function called by the mock function). | ||
*/ | ||
declare type MockFunctionResultType = 'return' | 'throw' | 'incomplete'; | ||
/** | ||
* Represents the result of a single call to a mock function. | ||
*/ | ||
declare type MockFunctionResult = { | ||
/** | ||
* Indicates how the call completed. | ||
*/ | ||
type: MockFunctionResultType; | ||
/** | ||
* The value that was either thrown or returned by the function. | ||
* Undefined when type === 'incomplete'. | ||
*/ | ||
value: unknown; | ||
}; | ||
declare type MockFunctionState<T, Y extends Array<unknown>> = { | ||
calls: Array<Y>; | ||
instances: Array<T>; | ||
invocationCallOrder: Array<number>; | ||
/** | ||
* Getter for retrieving the last call arguments | ||
*/ | ||
lastCall?: Y; | ||
/** | ||
* List of results of calls to the mock function. | ||
*/ | ||
results: Array<MockFunctionResult>; | ||
}; | ||
declare type NonFunctionPropertyNames<T> = { | ||
[K in keyof T]: T[K] extends (...args: Array<any>) => any ? never : K; | ||
}[keyof T] & string; | ||
declare type FunctionPropertyNames<T> = { | ||
[K in keyof T]: T[K] extends (...args: Array<any>) => any ? K : never; | ||
}[keyof T] & string; | ||
declare class ModuleMocker { | ||
private _environmentGlobal; | ||
private _mockState; | ||
private _mockConfigRegistry; | ||
private _spyState; | ||
private _invocationCallCounter; | ||
/** | ||
* @see README.md | ||
* @param global Global object of the test environment, used to create | ||
* mocks | ||
*/ | ||
constructor(global: typeof globalThis); | ||
private _getSlots; | ||
private _ensureMockConfig; | ||
private _ensureMockState; | ||
private _defaultMockConfig; | ||
private _defaultMockState; | ||
private _makeComponent; | ||
private _createMockFunction; | ||
private _generateMock; | ||
/** | ||
* @see README.md | ||
* @param _metadata Metadata for the mock in the schema returned by the | ||
* getMetadata method of this module. | ||
*/ | ||
generateFromMetadata<T, Y extends Array<unknown>>(_metadata: MockFunctionMetadata<T, Y>): Mock<T, Y>; | ||
/** | ||
* @see README.md | ||
* @param component The component for which to retrieve metadata. | ||
*/ | ||
getMetadata<T, Y extends Array<unknown>>(component: T, _refs?: Map<T, number>): MockFunctionMetadata<T, Y> | null; | ||
isMockFunction<T>(fn: unknown): fn is Mock<T>; | ||
fn<T, Y extends Array<unknown>>(implementation?: (...args: Y) => T): Mock<T, Y>; | ||
spyOn<T extends {}, M extends NonFunctionPropertyNames<T>>(object: T, methodName: M, accessType: 'get'): SpyInstance<T[M], []>; | ||
spyOn<T extends {}, M extends NonFunctionPropertyNames<T>>(object: T, methodName: M, accessType: 'set'): SpyInstance<void, [T[M]]>; | ||
spyOn<T extends {}, M extends FunctionPropertyNames<T>>(object: T, methodName: M): T[M] extends (...args: Array<any>) => any ? SpyInstance<ReturnType<T[M]>, Parameters<T[M]>> : never; | ||
private _spyOnProperty; | ||
clearAllMocks(): void; | ||
resetAllMocks(): void; | ||
restoreAllMocks(): void; | ||
private _typeOf; | ||
mocked<T>(item: T, deep?: false): MaybeMocked<T>; | ||
mocked<T>(item: T, deep: true): MaybeMockedDeep<T>; | ||
} | ||
declare const fn: <T, Y extends unknown[]>(implementation?: ((...args: Y) => T) | undefined) => Mock<T, Y>; | ||
declare const spyOn: { | ||
<T extends {}, M extends NonFunctionPropertyNames<T>>(object: T, methodName: M, accessType: 'get'): SpyInstance<T[M], []>; | ||
<T_2 extends {}, M_2 extends NonFunctionPropertyNames<T_2>>(object: T_2, methodName: M_2, accessType: 'set'): SpyInstance<void, [T_2[M_2]]>; | ||
<T_4 extends {}, M_4 extends FunctionPropertyNames<T_4>>(object: T_4, methodName: M_4): T_4[M_4] extends (...args: Array<any>) => any ? SpyInstance<ReturnType<T_4[M_4]>, Parameters<T_4[M_4]>> : never; | ||
}; | ||
declare const mocked: { | ||
<T>(item: T, deep?: false | undefined): MaybeMocked<T>; | ||
<T_2>(item: T_2, deep: true): MaybeMockedDeep<T_2>; | ||
}; | ||
type mock_MockFunctionMetadataType = MockFunctionMetadataType; | ||
type mock_MockFunctionMetadata<T, Y extends Array<unknown>, Type = MockFunctionMetadataType> = MockFunctionMetadata<T, Y, Type>; | ||
type mock_MockableFunction = MockableFunction; | ||
type mock_MethodKeysOf<T> = MethodKeysOf<T>; | ||
type mock_PropertyKeysOf<T> = PropertyKeysOf<T>; | ||
type mock_ArgumentsOf<T> = ArgumentsOf<T>; | ||
type mock_ConstructorArgumentsOf<T> = ConstructorArgumentsOf<T>; | ||
type mock_MaybeMockedConstructor<T> = MaybeMockedConstructor<T>; | ||
type mock_MockedFunction<T extends MockableFunction> = MockedFunction<T>; | ||
type mock_MockedFunctionDeep<T extends MockableFunction> = MockedFunctionDeep<T>; | ||
type mock_MockedObject<T> = MockedObject<T>; | ||
type mock_MockedObjectDeep<T> = MockedObjectDeep<T>; | ||
type mock_MaybeMockedDeep<T> = MaybeMockedDeep<T>; | ||
type mock_MaybeMocked<T> = MaybeMocked<T>; | ||
type mock_ArgsType<T> = ArgsType<T>; | ||
type mock_Mocked<T> = Mocked<T>; | ||
type mock_MockedClass<T extends Constructable> = MockedClass<T>; | ||
type mock_Constructable = Constructable; | ||
type mock_MockWithArgs<T extends MockableFunction> = MockWithArgs<T>; | ||
type mock_Mock<T, Y extends Array<unknown> = Array<unknown>> = Mock<T, Y>; | ||
type mock_SpyInstance<T, Y extends Array<unknown>> = SpyInstance<T, Y>; | ||
type mock_MockInstance<T, Y extends Array<unknown>> = MockInstance<T, Y>; | ||
type mock_ModuleMocker = ModuleMocker; | ||
declare const mock_ModuleMocker: typeof ModuleMocker; | ||
declare const mock_fn: typeof fn; | ||
declare const mock_spyOn: typeof spyOn; | ||
declare const mock_mocked: typeof mocked; | ||
declare namespace mock { | ||
export { | ||
mock_MockFunctionMetadataType as MockFunctionMetadataType, | ||
mock_MockFunctionMetadata as MockFunctionMetadata, | ||
mock_MockableFunction as MockableFunction, | ||
mock_MethodKeysOf as MethodKeysOf, | ||
mock_PropertyKeysOf as PropertyKeysOf, | ||
mock_ArgumentsOf as ArgumentsOf, | ||
mock_ConstructorArgumentsOf as ConstructorArgumentsOf, | ||
mock_MaybeMockedConstructor as MaybeMockedConstructor, | ||
mock_MockedFunction as MockedFunction, | ||
mock_MockedFunctionDeep as MockedFunctionDeep, | ||
mock_MockedObject as MockedObject, | ||
mock_MockedObjectDeep as MockedObjectDeep, | ||
mock_MaybeMockedDeep as MaybeMockedDeep, | ||
mock_MaybeMocked as MaybeMocked, | ||
mock_ArgsType as ArgsType, | ||
mock_Mocked as Mocked, | ||
mock_MockedClass as MockedClass, | ||
mock_Constructable as Constructable, | ||
mock_MockWithArgs as MockWithArgs, | ||
mock_Mock as Mock, | ||
mock_SpyInstance as SpyInstance, | ||
mock_MockInstance as MockInstance, | ||
mock_ModuleMocker as ModuleMocker, | ||
mock_fn as fn, | ||
mock_spyOn as spyOn, | ||
mock_mocked as mocked, | ||
}; | ||
} | ||
declare const jest: typeof mock; | ||
@@ -6,0 +247,0 @@ /** |
{ | ||
"name": "@storybook/jest", | ||
"version": "0.2.3--canary.47.6407557579.0", | ||
"version": "0.2.3--canary.47.6408168214.0", | ||
"description": "Instrumented version of Jest for Storybook Interactions", | ||
@@ -31,6 +31,3 @@ "repository": { | ||
"dependencies": { | ||
"@storybook/expect": "storybook-jest", | ||
"@testing-library/jest-dom": "^6.1.2", | ||
"@types/jest": "28.1.3", | ||
"jest-mock": "^27.3.0" | ||
"@storybook/expect": "storybook-jest" | ||
}, | ||
@@ -40,7 +37,10 @@ "devDependencies": { | ||
"@auto-it/released": "^10.37.6", | ||
"@storybook/instrumenter": "next", | ||
"@storybook/instrumenter": "^7.0.0", | ||
"@storybook/linter-config": "^3.1.2", | ||
"@testing-library/jest-dom": "^6.1.2", | ||
"@types/jest": "28.1.3", | ||
"@types/react": "*", | ||
"auto": "^10.37.6", | ||
"expect": "^27.3.1", | ||
"jest-mock": "^27.3.0", | ||
"prettier": "^2.8.8", | ||
@@ -47,0 +47,0 @@ "tsup": "^5.12.0", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
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
Uses eval
Supply chain riskPackage uses eval() which is a dangerous function. This prevents 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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
870039
1
23777
14
3
3
- Removed@testing-library/jest-dom@^6.1.2
- Removed@types/jest@28.1.3
- Removedjest-mock@^27.3.0
- Removed@adobe/css-tools@4.4.0(transitive)
- Removed@jest/types@27.5.1(transitive)
- Removed@testing-library/jest-dom@6.5.0(transitive)
- Removed@types/istanbul-lib-coverage@2.0.6(transitive)
- Removed@types/istanbul-lib-report@3.0.3(transitive)
- Removed@types/istanbul-reports@3.0.4(transitive)
- Removed@types/node@22.5.4(transitive)
- Removed@types/yargs@16.0.9(transitive)
- Removed@types/yargs-parser@21.0.3(transitive)
- Removedaria-query@5.3.0(transitive)
- Removedchalk@3.0.0(transitive)
- Removedcss.escape@1.5.1(transitive)
- Removeddequal@2.0.3(transitive)
- Removeddom-accessibility-api@0.6.3(transitive)
- Removedindent-string@4.0.0(transitive)
- Removedjest-mock@27.5.1(transitive)
- Removedlodash@4.17.21(transitive)
- Removedmin-indent@1.0.1(transitive)
- Removedredent@3.0.0(transitive)
- Removedstrip-indent@3.0.0(transitive)
- Removedundici-types@6.19.8(transitive)