Updating NPM dependencies
This commit is contained in:
70
node_modules/jest-mock/build/index.d.ts
generated
vendored
70
node_modules/jest-mock/build/index.d.ts
generated
vendored
@@ -19,7 +19,36 @@ declare namespace JestMock {
|
||||
value?: T;
|
||||
length?: number;
|
||||
};
|
||||
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.
|
||||
@@ -58,34 +87,6 @@ declare type NonFunctionPropertyNames<T> = {
|
||||
declare type FunctionPropertyNames<T> = {
|
||||
[K in keyof T]: T[K] extends (...args: Array<any>) => any ? K : never;
|
||||
}[keyof T] & string;
|
||||
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: T): this;
|
||||
mockResolvedValueOnce(value: T): this;
|
||||
mockRejectedValue(value: T): this;
|
||||
mockRejectedValueOnce(value: T): this;
|
||||
}
|
||||
declare class ModuleMockerClass {
|
||||
private _environmentGlobal;
|
||||
private _mockState;
|
||||
@@ -112,17 +113,17 @@ declare class ModuleMockerClass {
|
||||
* @param _metadata Metadata for the mock in the schema returned by the
|
||||
* getMetadata method of this module.
|
||||
*/
|
||||
generateFromMetadata<T, Y extends Array<unknown>>(_metadata: JestMock.MockFunctionMetadata<T, Y>): Mock<T, Y>;
|
||||
generateFromMetadata<T, Y extends Array<unknown>>(_metadata: JestMock.MockFunctionMetadata<T, Y>): JestMock.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>): JestMock.MockFunctionMetadata<T, Y> | null;
|
||||
isMockFunction<T>(fn: any): 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;
|
||||
isMockFunction<T>(fn: any): fn is JestMock.Mock<T>;
|
||||
fn<T, Y extends Array<unknown>>(implementation?: (...args: Y) => T): JestMock.Mock<T, Y>;
|
||||
spyOn<T extends {}, M extends NonFunctionPropertyNames<T>>(object: T, methodName: M, accessType: 'get'): JestMock.SpyInstance<T[M], []>;
|
||||
spyOn<T extends {}, M extends NonFunctionPropertyNames<T>>(object: T, methodName: M, accessType: 'set'): JestMock.SpyInstance<void, [T[M]]>;
|
||||
spyOn<T extends {}, M extends FunctionPropertyNames<T>>(object: T, methodName: M): T[M] extends (...args: Array<any>) => any ? JestMock.SpyInstance<ReturnType<T[M]>, Parameters<T[M]>> : never;
|
||||
private _spyOnProperty;
|
||||
clearAllMocks(): void;
|
||||
resetAllMocks(): void;
|
||||
@@ -131,4 +132,3 @@ declare class ModuleMockerClass {
|
||||
}
|
||||
declare const JestMock: ModuleMockerClass;
|
||||
export = JestMock;
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
1
node_modules/jest-mock/build/index.d.ts.map
generated
vendored
1
node_modules/jest-mock/build/index.d.ts.map
generated
vendored
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;;AAEH,aAAK,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;AAE5B,kBAAU,QAAQ,CAAC;IACjB,KAAY,YAAY,GAAG,iBAAiB,CAAC;IAC7C,KAAY,wBAAwB,GAChC,QAAQ,GACR,OAAO,GACP,QAAQ,GACR,UAAU,GACV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AK,GAAG,GACxC,WAAW,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAC/C,KAAK;IAkDT,OAAO,CAAC,cAAc;IA2EtB,aAAa;IAIb,aAAa;IAKb,eAAe;IAKf,OAAO,CAAC,OAAO;CAGhB;AAGD,QAAA,MAAM,QAAQ,mBAAgC,CAAC;AAC/C,SAAS,QAAQ,CAAC"}
|
||||
194
node_modules/jest-mock/build/index.js
generated
vendored
194
node_modules/jest-mock/build/index.js
generated
vendored
@@ -21,6 +21,9 @@ function _defineProperty(obj, key, value) {
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
/* eslint-disable local/ban-types-eventually, local/prefer-rest-params-eventually */
|
||||
// | Window – add once TS improves typings;
|
||||
|
||||
/**
|
||||
* Possible types of a MockFunctionResult.
|
||||
* 'return': The call completed by returning normally.
|
||||
@@ -96,89 +99,70 @@ function matchArity(fn, length) {
|
||||
|
||||
switch (length) {
|
||||
case 1:
|
||||
mockConstructor = function mockConstructor(_a) {
|
||||
mockConstructor = function (_a) {
|
||||
return fn.apply(this, arguments);
|
||||
};
|
||||
|
||||
break;
|
||||
|
||||
case 2:
|
||||
mockConstructor = function mockConstructor(_a, _b) {
|
||||
mockConstructor = function (_a, _b) {
|
||||
return fn.apply(this, arguments);
|
||||
};
|
||||
|
||||
break;
|
||||
|
||||
case 3:
|
||||
mockConstructor = function mockConstructor(_a, _b, _c) {
|
||||
mockConstructor = function (_a, _b, _c) {
|
||||
return fn.apply(this, arguments);
|
||||
};
|
||||
|
||||
break;
|
||||
|
||||
case 4:
|
||||
mockConstructor = function mockConstructor(_a, _b, _c, _d) {
|
||||
mockConstructor = function (_a, _b, _c, _d) {
|
||||
return fn.apply(this, arguments);
|
||||
};
|
||||
|
||||
break;
|
||||
|
||||
case 5:
|
||||
mockConstructor = function mockConstructor(_a, _b, _c, _d, _e) {
|
||||
mockConstructor = function (_a, _b, _c, _d, _e) {
|
||||
return fn.apply(this, arguments);
|
||||
};
|
||||
|
||||
break;
|
||||
|
||||
case 6:
|
||||
mockConstructor = function mockConstructor(_a, _b, _c, _d, _e, _f) {
|
||||
mockConstructor = function (_a, _b, _c, _d, _e, _f) {
|
||||
return fn.apply(this, arguments);
|
||||
};
|
||||
|
||||
break;
|
||||
|
||||
case 7:
|
||||
mockConstructor = function mockConstructor(_a, _b, _c, _d, _e, _f, _g) {
|
||||
mockConstructor = function (_a, _b, _c, _d, _e, _f, _g) {
|
||||
return fn.apply(this, arguments);
|
||||
};
|
||||
|
||||
break;
|
||||
|
||||
case 8:
|
||||
mockConstructor = function mockConstructor(
|
||||
_a,
|
||||
_b,
|
||||
_c,
|
||||
_d,
|
||||
_e,
|
||||
_f,
|
||||
_g,
|
||||
_h
|
||||
) {
|
||||
mockConstructor = function (_a, _b, _c, _d, _e, _f, _g, _h) {
|
||||
return fn.apply(this, arguments);
|
||||
};
|
||||
|
||||
break;
|
||||
|
||||
case 9:
|
||||
mockConstructor = function mockConstructor(
|
||||
_a,
|
||||
_b,
|
||||
_c,
|
||||
_d,
|
||||
_e,
|
||||
_f,
|
||||
_g,
|
||||
_h,
|
||||
_i
|
||||
) {
|
||||
mockConstructor = function (_a, _b, _c, _d, _e, _f, _g, _h, _i) {
|
||||
return fn.apply(this, arguments);
|
||||
};
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
mockConstructor = function mockConstructor() {
|
||||
mockConstructor = function () {
|
||||
return fn.apply(this, arguments);
|
||||
};
|
||||
|
||||
@@ -315,7 +299,7 @@ class ModuleMockerClass {
|
||||
const prop = ownNames[i];
|
||||
|
||||
if (!isReadonlyProp(object, prop)) {
|
||||
const propDesc = Object.getOwnPropertyDescriptor(object, prop); // @ts-ignore Object.__esModule
|
||||
const propDesc = Object.getOwnPropertyDescriptor(object, prop);
|
||||
|
||||
if ((propDesc !== undefined && !propDesc.get) || object.__esModule) {
|
||||
slots.add(prop);
|
||||
@@ -355,8 +339,6 @@ class ModuleMockerClass {
|
||||
|
||||
_defaultMockConfig() {
|
||||
return {
|
||||
defaultReturnValue: undefined,
|
||||
isReturnValueLastSet: false,
|
||||
mockImpl: undefined,
|
||||
mockName: 'jest.fn()',
|
||||
specificMockImpls: [],
|
||||
@@ -397,7 +379,7 @@ class ModuleMockerClass {
|
||||
const prototypeSlots = this._getSlots(prototype);
|
||||
|
||||
const mocker = this;
|
||||
const mockConstructor = matchArity(function(...args) {
|
||||
const mockConstructor = matchArity(function (...args) {
|
||||
const mockState = mocker._ensureMockState(f);
|
||||
|
||||
const mockConfig = mocker._ensureMockConfig(f);
|
||||
@@ -436,10 +418,10 @@ class ModuleMockerClass {
|
||||
// it easier to interact with mock instance call and
|
||||
// return values
|
||||
if (prototype[slot].type === 'function') {
|
||||
// @ts-ignore no index signature
|
||||
const protoImpl = this[slot]; // @ts-ignore no index signature
|
||||
// @ts-expect-error no index signature
|
||||
const protoImpl = this[slot]; // @ts-expect-error no index signature
|
||||
|
||||
this[slot] = mocker.generateFromMetadata(prototype[slot]); // @ts-ignore no index signature
|
||||
this[slot] = mocker.generateFromMetadata(prototype[slot]); // @ts-expect-error no index signature
|
||||
|
||||
this[slot]._protoImpl = protoImpl;
|
||||
}
|
||||
@@ -449,43 +431,24 @@ class ModuleMockerClass {
|
||||
? mockConfig.specificMockImpls.shift()
|
||||
: mockConfig.mockImpl;
|
||||
return mockImpl && mockImpl.apply(this, arguments);
|
||||
}
|
||||
|
||||
const returnValue = mockConfig.defaultReturnValue; // If return value is last set, either specific or default, i.e.
|
||||
// mockReturnValueOnce()/mockReturnValue() is called and no
|
||||
// mockImplementationOnce()/mockImplementation() is called after
|
||||
// that.
|
||||
// use the set return value.
|
||||
|
||||
if (mockConfig.specificReturnValues.length) {
|
||||
return mockConfig.specificReturnValues.shift();
|
||||
}
|
||||
|
||||
if (mockConfig.isReturnValueLastSet) {
|
||||
return mockConfig.defaultReturnValue;
|
||||
} // If mockImplementationOnce()/mockImplementation() is last set,
|
||||
// or specific return values are used up, use the mock
|
||||
// implementation.
|
||||
// implementation use the mock
|
||||
|
||||
let specificMockImpl;
|
||||
let specificMockImpl = mockConfig.specificMockImpls.shift();
|
||||
|
||||
if (returnValue === undefined) {
|
||||
specificMockImpl = mockConfig.specificMockImpls.shift();
|
||||
if (specificMockImpl === undefined) {
|
||||
specificMockImpl = mockConfig.mockImpl;
|
||||
}
|
||||
|
||||
if (specificMockImpl === undefined) {
|
||||
specificMockImpl = mockConfig.mockImpl;
|
||||
}
|
||||
|
||||
if (specificMockImpl) {
|
||||
return specificMockImpl.apply(this, arguments);
|
||||
}
|
||||
if (specificMockImpl) {
|
||||
return specificMockImpl.apply(this, arguments);
|
||||
} // Otherwise use prototype implementation
|
||||
|
||||
if (returnValue === undefined && f._protoImpl) {
|
||||
if (f._protoImpl) {
|
||||
return f._protoImpl.apply(this, arguments);
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
return undefined;
|
||||
})();
|
||||
} catch (error) {
|
||||
// Store the thrown error so we can record it, then re-throw it.
|
||||
@@ -544,13 +507,9 @@ class ModuleMockerClass {
|
||||
return restore ? restore() : undefined;
|
||||
};
|
||||
|
||||
f.mockReturnValueOnce = value => {
|
||||
// next function call will return this value or default return value
|
||||
const mockConfig = this._ensureMockConfig(f);
|
||||
|
||||
mockConfig.specificReturnValues.push(value);
|
||||
return f;
|
||||
};
|
||||
f.mockReturnValueOnce = (
|
||||
value // next function call will return this value or default return value
|
||||
) => f.mockImplementationOnce(() => value);
|
||||
|
||||
f.mockResolvedValueOnce = value =>
|
||||
f.mockImplementationOnce(() => Promise.resolve(value));
|
||||
@@ -558,14 +517,9 @@ class ModuleMockerClass {
|
||||
f.mockRejectedValueOnce = value =>
|
||||
f.mockImplementationOnce(() => Promise.reject(value));
|
||||
|
||||
f.mockReturnValue = value => {
|
||||
// next function call will return specified return value or this one
|
||||
const mockConfig = this._ensureMockConfig(f);
|
||||
|
||||
mockConfig.isReturnValueLastSet = true;
|
||||
mockConfig.defaultReturnValue = value;
|
||||
return f;
|
||||
};
|
||||
f.mockReturnValue = (
|
||||
value // next function call will return specified return value or this one
|
||||
) => f.mockImplementation(() => value);
|
||||
|
||||
f.mockResolvedValue = value =>
|
||||
f.mockImplementation(() => Promise.resolve(value));
|
||||
@@ -578,7 +532,6 @@ class ModuleMockerClass {
|
||||
// or default mock implementation return value
|
||||
const mockConfig = this._ensureMockConfig(f);
|
||||
|
||||
mockConfig.isReturnValueLastSet = false;
|
||||
mockConfig.specificMockImpls.push(fn);
|
||||
return f;
|
||||
};
|
||||
@@ -587,14 +540,12 @@ class ModuleMockerClass {
|
||||
// next function call will use mock implementation return value
|
||||
const mockConfig = this._ensureMockConfig(f);
|
||||
|
||||
mockConfig.isReturnValueLastSet = false;
|
||||
mockConfig.defaultReturnValue = undefined;
|
||||
mockConfig.mockImpl = fn;
|
||||
return f;
|
||||
};
|
||||
|
||||
f.mockReturnThis = () =>
|
||||
f.mockImplementation(function() {
|
||||
f.mockImplementation(function () {
|
||||
return this;
|
||||
});
|
||||
|
||||
@@ -681,7 +632,7 @@ class ModuleMockerClass {
|
||||
_generateMock(metadata, callbacks, refs) {
|
||||
// metadata not compatible but it's the same type, maybe problem with
|
||||
// overloading of _makeComponent and not _generateMock?
|
||||
// @ts-ignore
|
||||
// @ts-expect-error
|
||||
const mock = this._makeComponent(metadata);
|
||||
|
||||
if (metadata.refID != null) {
|
||||
@@ -693,7 +644,7 @@ class ModuleMockerClass {
|
||||
|
||||
if (slotMetadata.ref != null) {
|
||||
callbacks.push(
|
||||
(function(ref) {
|
||||
(function (ref) {
|
||||
return () => (mock[slot] = refs[ref]);
|
||||
})(slotMetadata.ref)
|
||||
);
|
||||
@@ -762,11 +713,11 @@ class ModuleMockerClass {
|
||||
metadata.value = component;
|
||||
return metadata;
|
||||
} else if (type === 'function') {
|
||||
// @ts-ignore this is a function so it has a name
|
||||
metadata.name = component.name; // @ts-ignore may be a mock
|
||||
// @ts-expect-error this is a function so it has a name
|
||||
metadata.name = component.name; // @ts-expect-error may be a mock
|
||||
|
||||
if (component._isMockFunction === true) {
|
||||
// @ts-ignore may be a mock
|
||||
// @ts-expect-error may be a mock
|
||||
metadata.mockImpl = component.getMockImplementation();
|
||||
}
|
||||
}
|
||||
@@ -778,12 +729,12 @@ class ModuleMockerClass {
|
||||
if (type !== 'array') {
|
||||
this._getSlots(component).forEach(slot => {
|
||||
if (
|
||||
type === 'function' && // @ts-ignore may be a mock
|
||||
type === 'function' && // @ts-expect-error may be a mock
|
||||
component._isMockFunction === true &&
|
||||
slot.match(/^mock/)
|
||||
) {
|
||||
return;
|
||||
} // @ts-ignore no index signature
|
||||
} // @ts-expect-error no index signature
|
||||
|
||||
const slotMetadata = this.getMetadata(component[slot], refs);
|
||||
|
||||
@@ -847,22 +798,50 @@ class ModuleMockerClass {
|
||||
);
|
||||
}
|
||||
|
||||
const isMethodOwner = object.hasOwnProperty(methodName); // @ts-ignore overriding original method with a Mock
|
||||
const isMethodOwner = object.hasOwnProperty(methodName);
|
||||
let descriptor = Object.getOwnPropertyDescriptor(object, methodName);
|
||||
let proto = Object.getPrototypeOf(object);
|
||||
|
||||
object[methodName] = this._makeComponent(
|
||||
{
|
||||
type: 'function'
|
||||
},
|
||||
() => {
|
||||
if (isMethodOwner) {
|
||||
object[methodName] = original;
|
||||
} else {
|
||||
delete object[methodName];
|
||||
while (!descriptor && proto !== null) {
|
||||
descriptor = Object.getOwnPropertyDescriptor(proto, methodName);
|
||||
proto = Object.getPrototypeOf(proto);
|
||||
}
|
||||
|
||||
let mock;
|
||||
|
||||
if (descriptor && descriptor.get) {
|
||||
const originalGet = descriptor.get;
|
||||
mock = this._makeComponent(
|
||||
{
|
||||
type: 'function'
|
||||
},
|
||||
() => {
|
||||
descriptor.get = originalGet;
|
||||
Object.defineProperty(object, methodName, descriptor);
|
||||
}
|
||||
}
|
||||
); // @ts-ignore original method is now a Mock
|
||||
);
|
||||
|
||||
object[methodName].mockImplementation(function() {
|
||||
descriptor.get = () => mock;
|
||||
|
||||
Object.defineProperty(object, methodName, descriptor);
|
||||
} else {
|
||||
mock = this._makeComponent(
|
||||
{
|
||||
type: 'function'
|
||||
},
|
||||
() => {
|
||||
if (isMethodOwner) {
|
||||
object[methodName] = original;
|
||||
} else {
|
||||
delete object[methodName];
|
||||
}
|
||||
}
|
||||
); // @ts-expect-error overriding original method with a Mock
|
||||
|
||||
object[methodName] = mock;
|
||||
}
|
||||
|
||||
mock.mockImplementation(function () {
|
||||
return original.apply(this, arguments);
|
||||
});
|
||||
}
|
||||
@@ -920,20 +899,20 @@ class ModuleMockerClass {
|
||||
this._typeOf(original) +
|
||||
' given instead'
|
||||
);
|
||||
} // @ts-ignore: mock is assignable
|
||||
} // @ts-expect-error: mock is assignable
|
||||
|
||||
descriptor[accessType] = this._makeComponent(
|
||||
{
|
||||
type: 'function'
|
||||
},
|
||||
() => {
|
||||
// @ts-ignore: mock is assignable
|
||||
// @ts-expect-error: mock is assignable
|
||||
descriptor[accessType] = original;
|
||||
Object.defineProperty(obj, propertyName, descriptor);
|
||||
}
|
||||
);
|
||||
descriptor[accessType].mockImplementation(function() {
|
||||
// @ts-ignore
|
||||
descriptor[accessType].mockImplementation(function () {
|
||||
// @ts-expect-error
|
||||
return original.apply(this, arguments);
|
||||
});
|
||||
}
|
||||
@@ -961,7 +940,6 @@ class ModuleMockerClass {
|
||||
return value == null ? '' + value : typeof value;
|
||||
}
|
||||
}
|
||||
/* eslint-disable-next-line no-redeclare */
|
||||
|
||||
const JestMock = new ModuleMockerClass(global);
|
||||
module.exports = JestMock;
|
||||
|
||||
Reference in New Issue
Block a user