This commit is contained in:
Stephen Franceschelli 2019-07-30 13:41:05 -04:00
parent 596a6da241
commit c1a589c5b6
7078 changed files with 1882834 additions and 319 deletions

23
node_modules/jest-mock/LICENSE generated vendored Normal file
View file

@ -0,0 +1,23 @@
MIT License
For Jest software
Copyright (c) 2014-present, Facebook, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

88
node_modules/jest-mock/README.md generated vendored Normal file
View file

@ -0,0 +1,88 @@
# jest-mock
## API
### `constructor(global)`
Creates a new module mocker that generates mocks as if they were created in an environment with the given global object.
### `generateFromMetadata(metadata)`
Generates a mock based on the given metadata (Metadata for the mock in the schema returned by the getMetadata method of this module). Mocks treat functions specially, and all mock functions have additional members, described in the documentation for `fn` in this module.
One important note: function prototypes are handled specially by this mocking framework. For functions with prototypes, when called as a constructor, the mock will install mocked function members on the instance. This allows different instances of the same constructor to have different values for its mocks member and its return values.
### `getMetadata(component)`
Inspects the argument and returns its schema in the following recursive format:
```
{
type: ...
members: {}
}
```
Where type is one of `array`, `object`, `function`, or `ref`, and members is an optional dictionary where the keys are member names and the values are metadata objects. Function prototypes are defined simply by defining metadata for the `member.prototype` of the function. The type of a function prototype should always be `object`. For instance, a simple class might be defined like this:
```js
const classDef = {
type: 'function',
members: {
staticMethod: {type: 'function'},
prototype: {
type: 'object',
members: {
instanceMethod: {type: 'function'},
},
},
},
};
```
Metadata may also contain references to other objects defined within the same metadata object. The metadata for the referent must be marked with `refID` key and an arbitrary value. The referrer must be marked with a `ref` key that has the same value as object with refID that it refers to. For instance, this metadata blob:
```js
const refID = {
type: 'object',
refID: 1,
members: {
self: {ref: 1},
},
};
```
defines an object with a slot named `self` that refers back to the object.
### `fn`
Generates a stand-alone function with members that help drive unit tests or confirm expectations. Specifically, functions returned by this method have the following members:
##### `.mock`
An object with three members, `calls`, `instances` and `invocationCallOrder`, which are all lists. The items in the `calls` list are the arguments with which the function was called. The "instances" list stores the value of 'this' for each call to the function. This is useful for retrieving instances from a constructor. The `invocationCallOrder` lists the order in which the mock was called in relation to all mock calls, starting at 1.
##### `.mockReturnValueOnce(value)`
Pushes the given value onto a FIFO queue of return values for the function.
##### `.mockReturnValue(value)`
Sets the default return value for the function.
##### `.mockImplementationOnce(function)`
Pushes the given mock implementation onto a FIFO queue of mock implementations for the function.
##### `.mockImplementation(function)`
Sets the default mock implementation for the function.
##### `.mockReturnThis()`
Syntactic sugar for .mockImplementation(function() {return this;})
In case both `mockImplementationOnce()/mockImplementation()` and `mockReturnValueOnce()/mockReturnValue()` are called. The priority of which to use is based on what is the last call:
- if the last call is mockReturnValueOnce() or mockReturnValue(), use the specific return value or default return value. If specific return values are used up or no default return value is set, fall back to try mockImplementation();
- if the last call is mockImplementationOnce() or mockImplementation(), run the specific implementation and return the result or run default implementation and return the result.

993
node_modules/jest-mock/build-es5/index.js generated vendored Normal file
View file

@ -0,0 +1,993 @@
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
else if(typeof exports === 'object')
exports["jestMock"] = factory();
else
root["jestMock"] = factory();
})(window, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = "./packages/jest-mock/src/index.ts");
/******/ })
/************************************************************************/
/******/ ({
/***/ "./node_modules/webpack/buildin/global.js":
/*!***********************************!*\
!*** (webpack)/buildin/global.js ***!
\***********************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
var g; // This works in non-strict mode
g = function () {
return this;
}();
try {
// This works if eval is allowed (see CSP)
g = g || new Function("return this")();
} catch (e) {
// This works if the window reference is available
if ((typeof window === "undefined" ? "undefined" : _typeof(window)) === "object") g = window;
} // g can still be undefined, but nothing to do about it...
// We return undefined, instead of nothing here, so it's
// easier to handle this case. if(!global) { ...}
module.exports = g;
/***/ }),
/***/ "./packages/jest-mock/src/index.ts":
/*!*****************************************!*\
!*** ./packages/jest-mock/src/index.ts ***!
\*****************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
/* WEBPACK VAR INJECTION */(function(global) {
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
/**
* 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.
*/
/**
* 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).
*/
/**
* Represents the result of a single call to a mock function.
*/
// see https://github.com/Microsoft/TypeScript/issues/25215
var MOCK_CONSTRUCTOR_NAME = 'mockConstructor';
var FUNCTION_NAME_RESERVED_PATTERN = /[\s!-\/:-@\[-`{-~]/;
var FUNCTION_NAME_RESERVED_REPLACE = new RegExp(FUNCTION_NAME_RESERVED_PATTERN.source, 'g');
var RESERVED_KEYWORDS = new Set(['arguments', 'await', 'break', 'case', 'catch', 'class', 'const', 'continue', 'debugger', 'default', 'delete', 'do', 'else', 'enum', 'eval', 'export', 'extends', 'false', 'finally', 'for', 'function', 'if', 'implements', 'import', 'in', 'instanceof', 'interface', 'let', 'new', 'null', 'package', 'private', 'protected', 'public', 'return', 'static', 'super', 'switch', 'this', 'throw', 'true', 'try', 'typeof', 'var', 'void', 'while', 'with', 'yield']);
function matchArity(fn, length) {
var mockConstructor;
switch (length) {
case 1:
mockConstructor = function mockConstructor(_a) {
return fn.apply(this, arguments);
};
break;
case 2:
mockConstructor = function mockConstructor(_a, _b) {
return fn.apply(this, arguments);
};
break;
case 3:
mockConstructor = function mockConstructor(_a, _b, _c) {
return fn.apply(this, arguments);
};
break;
case 4:
mockConstructor = function mockConstructor(_a, _b, _c, _d) {
return fn.apply(this, arguments);
};
break;
case 5:
mockConstructor = function mockConstructor(_a, _b, _c, _d, _e) {
return fn.apply(this, arguments);
};
break;
case 6:
mockConstructor = function mockConstructor(_a, _b, _c, _d, _e, _f) {
return fn.apply(this, arguments);
};
break;
case 7:
mockConstructor = function mockConstructor(_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) {
return fn.apply(this, arguments);
};
break;
case 9:
mockConstructor = function mockConstructor(_a, _b, _c, _d, _e, _f, _g, _h, _i) {
return fn.apply(this, arguments);
};
break;
default:
mockConstructor = function mockConstructor() {
return fn.apply(this, arguments);
};
break;
}
return mockConstructor;
}
function getObjectType(value) {
return Object.prototype.toString.apply(value).slice(8, -1);
}
function getType(ref) {
var typeName = getObjectType(ref);
if (typeName === 'Function' || typeName === 'AsyncFunction' || typeName === 'GeneratorFunction') {
return 'function';
} else if (Array.isArray(ref)) {
return 'array';
} else if (typeName === 'Object') {
return 'object';
} else if (typeName === 'Number' || typeName === 'String' || typeName === 'Boolean' || typeName === 'Symbol') {
return 'constant';
} else if (typeName === 'Map' || typeName === 'WeakMap' || typeName === 'Set') {
return 'collection';
} else if (typeName === 'RegExp') {
return 'regexp';
} else if (ref === undefined) {
return 'undefined';
} else if (ref === null) {
return 'null';
} else {
return null;
}
}
function isReadonlyProp(object, prop) {
if (prop === 'arguments' || prop === 'caller' || prop === 'callee' || prop === 'name' || prop === 'length') {
var typeName = getObjectType(object);
return typeName === 'Function' || typeName === 'AsyncFunction' || typeName === 'GeneratorFunction';
}
if (prop === 'source' || prop === 'global' || prop === 'ignoreCase' || prop === 'multiline') {
return getObjectType(object) === 'RegExp';
}
return false;
}
var ModuleMockerClass =
/*#__PURE__*/
function () {
/**
* @see README.md
* @param global Global object of the test environment, used to create
* mocks
*/
function ModuleMockerClass(global) {
_classCallCheck(this, ModuleMockerClass);
this._environmentGlobal = global;
this._mockState = new WeakMap();
this._mockConfigRegistry = new WeakMap();
this._spyState = new Set();
this.ModuleMocker = ModuleMockerClass;
this._invocationCallCounter = 1;
}
_createClass(ModuleMockerClass, [{
key: "_getSlots",
value: function _getSlots(object) {
if (!object) {
return [];
}
var slots = new Set();
var EnvObjectProto = this._environmentGlobal.Object.prototype;
var EnvFunctionProto = this._environmentGlobal.Function.prototype;
var EnvRegExpProto = this._environmentGlobal.RegExp.prototype; // Also check the builtins in the current context as they leak through
// core node modules.
var ObjectProto = Object.prototype;
var FunctionProto = Function.prototype;
var RegExpProto = RegExp.prototype; // Properties of Object.prototype, Function.prototype and RegExp.prototype
// are never reported as slots
while (object != null && object !== EnvObjectProto && object !== EnvFunctionProto && object !== EnvRegExpProto && object !== ObjectProto && object !== FunctionProto && object !== RegExpProto) {
var ownNames = Object.getOwnPropertyNames(object);
for (var i = 0; i < ownNames.length; i++) {
var prop = ownNames[i];
if (!isReadonlyProp(object, prop)) {
var propDesc = Object.getOwnPropertyDescriptor(object, prop); // @ts-ignore Object.__esModule
if (propDesc !== undefined && !propDesc.get || object.__esModule) {
slots.add(prop);
}
}
}
object = Object.getPrototypeOf(object);
}
return Array.from(slots);
}
}, {
key: "_ensureMockConfig",
value: function _ensureMockConfig(f) {
var config = this._mockConfigRegistry.get(f);
if (!config) {
config = this._defaultMockConfig();
this._mockConfigRegistry.set(f, config);
}
return config;
}
}, {
key: "_ensureMockState",
value: function _ensureMockState(f) {
var state = this._mockState.get(f);
if (!state) {
state = this._defaultMockState();
this._mockState.set(f, state);
}
return state;
}
}, {
key: "_defaultMockConfig",
value: function _defaultMockConfig() {
return {
defaultReturnValue: undefined,
isReturnValueLastSet: false,
mockImpl: undefined,
mockName: 'jest.fn()',
specificMockImpls: [],
specificReturnValues: []
};
}
}, {
key: "_defaultMockState",
value: function _defaultMockState() {
return {
calls: [],
instances: [],
invocationCallOrder: [],
results: []
};
}
}, {
key: "_makeComponent",
value: function _makeComponent(metadata, restore) {
var _this2 = this;
if (metadata.type === 'object') {
return new this._environmentGlobal.Object();
} else if (metadata.type === 'array') {
return new this._environmentGlobal.Array();
} else if (metadata.type === 'regexp') {
return new this._environmentGlobal.RegExp('');
} else if (metadata.type === 'constant' || metadata.type === 'collection' || metadata.type === 'null' || metadata.type === 'undefined') {
return metadata.value;
} else if (metadata.type === 'function') {
var prototype = metadata.members && metadata.members.prototype && metadata.members.prototype.members || {};
var prototypeSlots = this._getSlots(prototype);
var mocker = this;
var mockConstructor = matchArity(function () {
var _this = this,
_arguments = arguments;
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
var mockState = mocker._ensureMockState(f);
var mockConfig = mocker._ensureMockConfig(f);
mockState.instances.push(this);
mockState.calls.push(args); // Create and record an "incomplete" mock result immediately upon
// calling rather than waiting for the mock to return. This avoids
// issues caused by recursion where results can be recorded in the
// wrong order.
var mockResult = {
type: 'incomplete',
value: undefined
};
mockState.results.push(mockResult);
mockState.invocationCallOrder.push(mocker._invocationCallCounter++); // Will be set to the return value of the mock if an error is not thrown
var finalReturnValue; // Will be set to the error that is thrown by the mock (if it throws)
var thrownError; // Will be set to true if the mock throws an error. The presence of a
// value in `thrownError` is not a 100% reliable indicator because a
// function could throw a value of undefined.
var callDidThrowError = false;
try {
// The bulk of the implementation is wrapped in an immediately
// executed arrow function so the return value of the mock function
// can be easily captured and recorded, despite the many separate
// return points within the logic.
finalReturnValue = function () {
if (_this instanceof f) {
// This is probably being called as a constructor
prototypeSlots.forEach(function (slot) {
// Copy prototype methods to the instance to make
// it easier to interact with mock instance call and
// return values
if (prototype[slot].type === 'function') {
// @ts-ignore no index signature
var protoImpl = _this[slot]; // @ts-ignore no index signature
_this[slot] = mocker.generateFromMetadata(prototype[slot]); // @ts-ignore no index signature
_this[slot]._protoImpl = protoImpl;
}
}); // Run the mock constructor implementation
var _mockImpl = mockConfig.specificMockImpls.length ? mockConfig.specificMockImpls.shift() : mockConfig.mockImpl;
return _mockImpl && _mockImpl.apply(_this, _arguments);
}
var 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.
var specificMockImpl;
if (returnValue === undefined) {
specificMockImpl = mockConfig.specificMockImpls.shift();
if (specificMockImpl === undefined) {
specificMockImpl = mockConfig.mockImpl;
}
if (specificMockImpl) {
return specificMockImpl.apply(_this, _arguments);
}
} // Otherwise use prototype implementation
if (returnValue === undefined && f._protoImpl) {
return f._protoImpl.apply(_this, _arguments);
}
return returnValue;
}();
} catch (error) {
// Store the thrown error so we can record it, then re-throw it.
thrownError = error;
callDidThrowError = true;
throw error;
} finally {
// Record the result of the function.
// NOTE: Intentionally NOT pushing/indexing into the array of mock
// results here to avoid corrupting results data if mockClear()
// is called during the execution of the mock.
mockResult.type = callDidThrowError ? 'throw' : 'return';
mockResult.value = callDidThrowError ? thrownError : finalReturnValue;
}
return finalReturnValue;
}, metadata.length || 0);
var f = this._createMockFunction(metadata, mockConstructor);
f._isMockFunction = true;
f.getMockImplementation = function () {
return _this2._ensureMockConfig(f).mockImpl;
};
if (typeof restore === 'function') {
this._spyState.add(restore);
}
this._mockState.set(f, this._defaultMockState());
this._mockConfigRegistry.set(f, this._defaultMockConfig());
Object.defineProperty(f, 'mock', {
configurable: false,
enumerable: true,
get: function get() {
return _this2._ensureMockState(f);
},
set: function set(val) {
return _this2._mockState.set(f, val);
}
});
f.mockClear = function () {
_this2._mockState.delete(f);
return f;
};
f.mockReset = function () {
f.mockClear();
_this2._mockConfigRegistry.delete(f);
return f;
};
f.mockRestore = function () {
f.mockReset();
return restore ? restore() : undefined;
};
f.mockReturnValueOnce = function (value) {
// next function call will return this value or default return value
var mockConfig = _this2._ensureMockConfig(f);
mockConfig.specificReturnValues.push(value);
return f;
};
f.mockResolvedValueOnce = function (value) {
return f.mockImplementationOnce(function () {
return Promise.resolve(value);
});
};
f.mockRejectedValueOnce = function (value) {
return f.mockImplementationOnce(function () {
return Promise.reject(value);
});
};
f.mockReturnValue = function (value) {
// next function call will return specified return value or this one
var mockConfig = _this2._ensureMockConfig(f);
mockConfig.isReturnValueLastSet = true;
mockConfig.defaultReturnValue = value;
return f;
};
f.mockResolvedValue = function (value) {
return f.mockImplementation(function () {
return Promise.resolve(value);
});
};
f.mockRejectedValue = function (value) {
return f.mockImplementation(function () {
return Promise.reject(value);
});
};
f.mockImplementationOnce = function (fn) {
// next function call will use this mock implementation return value
// or default mock implementation return value
var mockConfig = _this2._ensureMockConfig(f);
mockConfig.isReturnValueLastSet = false;
mockConfig.specificMockImpls.push(fn);
return f;
};
f.mockImplementation = function (fn) {
// next function call will use mock implementation return value
var mockConfig = _this2._ensureMockConfig(f);
mockConfig.isReturnValueLastSet = false;
mockConfig.defaultReturnValue = undefined;
mockConfig.mockImpl = fn;
return f;
};
f.mockReturnThis = function () {
return f.mockImplementation(function () {
return this;
});
};
f.mockName = function (name) {
if (name) {
var mockConfig = _this2._ensureMockConfig(f);
mockConfig.mockName = name;
}
return f;
};
f.getMockName = function () {
var mockConfig = _this2._ensureMockConfig(f);
return mockConfig.mockName || 'jest.fn()';
};
if (metadata.mockImpl) {
f.mockImplementation(metadata.mockImpl);
}
return f;
} else {
var unknownType = metadata.type || 'undefined type';
throw new Error('Unrecognized type ' + unknownType);
}
}
}, {
key: "_createMockFunction",
value: function _createMockFunction(metadata, mockConstructor) {
var name = metadata.name;
if (!name) {
return mockConstructor;
} // Preserve `name` property of mocked function.
var boundFunctionPrefix = 'bound ';
var bindCall = ''; // if-do-while for perf reasons. The common case is for the if to fail.
if (name && name.startsWith(boundFunctionPrefix)) {
do {
name = name.substring(boundFunctionPrefix.length); // Call bind() just to alter the function name.
bindCall = '.bind(null)';
} while (name && name.startsWith(boundFunctionPrefix));
} // Special case functions named `mockConstructor` to guard for infinite
// loops.
if (name === MOCK_CONSTRUCTOR_NAME) {
return mockConstructor;
}
if ( // It's a syntax error to define functions with a reserved keyword
// as name.
RESERVED_KEYWORDS.has(name) || // It's also a syntax error to define functions with a name that starts with a number
/^\d/.test(name)) {
name = '$' + name;
} // It's also a syntax error to define a function with a reserved character
// as part of it's name.
if (FUNCTION_NAME_RESERVED_PATTERN.test(name)) {
name = name.replace(FUNCTION_NAME_RESERVED_REPLACE, '$');
}
var body = 'return function ' + name + '() {' + 'return ' + MOCK_CONSTRUCTOR_NAME + '.apply(this,arguments);' + '}' + bindCall;
var createConstructor = new this._environmentGlobal.Function(MOCK_CONSTRUCTOR_NAME, body);
return createConstructor(mockConstructor);
}
}, {
key: "_generateMock",
value: function _generateMock(metadata, callbacks, refs) {
var _this3 = this;
// metadata not compatible but it's the same type, maybe problem with
// overloading of _makeComponent and not _generateMock?
// @ts-ignore
var mock = this._makeComponent(metadata);
if (metadata.refID != null) {
refs[metadata.refID] = mock;
}
this._getSlots(metadata.members).forEach(function (slot) {
var slotMetadata = metadata.members && metadata.members[slot] || {};
if (slotMetadata.ref != null) {
callbacks.push(function (ref) {
return function () {
return mock[slot] = refs[ref];
};
}(slotMetadata.ref));
} else {
mock[slot] = _this3._generateMock(slotMetadata, callbacks, refs);
}
});
if (metadata.type !== 'undefined' && metadata.type !== 'null' && mock.prototype && _typeof(mock.prototype) === 'object') {
mock.prototype.constructor = mock;
}
return mock;
}
/**
* @see README.md
* @param _metadata Metadata for the mock in the schema returned by the
* getMetadata method of this module.
*/
}, {
key: "generateFromMetadata",
value: function generateFromMetadata(_metadata) {
var callbacks = [];
var refs = {};
var mock = this._generateMock(_metadata, callbacks, refs);
callbacks.forEach(function (setter) {
return setter();
});
return mock;
}
/**
* @see README.md
* @param component The component for which to retrieve metadata.
*/
}, {
key: "getMetadata",
value: function getMetadata(component, _refs) {
var _this4 = this;
var refs = _refs || new Map();
var ref = refs.get(component);
if (ref != null) {
return {
ref: ref
};
}
var type = getType(component);
if (!type) {
return null;
}
var metadata = {
type: type
};
if (type === 'constant' || type === 'collection' || type === 'undefined' || type === 'null') {
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
if (component._isMockFunction === true) {
// @ts-ignore may be a mock
metadata.mockImpl = component.getMockImplementation();
}
}
metadata.refID = refs.size;
refs.set(component, metadata.refID);
var members = null; // Leave arrays alone
if (type !== 'array') {
this._getSlots(component).forEach(function (slot) {
if (type === 'function' && // @ts-ignore may be a mock
component._isMockFunction === true && slot.match(/^mock/)) {
return;
} // @ts-ignore no index signature
var slotMetadata = _this4.getMetadata(component[slot], refs);
if (slotMetadata) {
if (!members) {
members = {};
}
members[slot] = slotMetadata;
}
});
}
if (members) {
metadata.members = members;
}
return metadata;
}
}, {
key: "isMockFunction",
value: function isMockFunction(fn) {
return !!fn && fn._isMockFunction === true;
}
}, {
key: "fn",
value: function fn(implementation) {
var length = implementation ? implementation.length : 0;
var fn = this._makeComponent({
length: length,
type: 'function'
});
if (implementation) {
fn.mockImplementation(implementation);
}
return fn;
}
}, {
key: "spyOn",
value: function spyOn(object, methodName, accessType) {
if (accessType) {
return this._spyOnProperty(object, methodName, accessType);
}
if (_typeof(object) !== 'object' && typeof object !== 'function') {
throw new Error('Cannot spyOn on a primitive value; ' + this._typeOf(object) + ' given');
}
var original = object[methodName];
if (!this.isMockFunction(original)) {
if (typeof original !== 'function') {
throw new Error('Cannot spy the ' + methodName + ' property because it is not a function; ' + this._typeOf(original) + ' given instead');
} // @ts-ignore overriding original method with a Mock
object[methodName] = this._makeComponent({
type: 'function'
}, function () {
object[methodName] = original;
}); // @ts-ignore original method is now a Mock
object[methodName].mockImplementation(function () {
return original.apply(this, arguments);
});
}
return object[methodName];
}
}, {
key: "_spyOnProperty",
value: function _spyOnProperty(obj, propertyName) {
var accessType = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'get';
if (_typeof(obj) !== 'object' && typeof obj !== 'function') {
throw new Error('Cannot spyOn on a primitive value; ' + this._typeOf(obj) + ' given');
}
if (!obj) {
throw new Error('spyOn could not find an object to spy upon for ' + propertyName + '');
}
if (!propertyName) {
throw new Error('No property name supplied');
}
var descriptor = Object.getOwnPropertyDescriptor(obj, propertyName);
var proto = Object.getPrototypeOf(obj);
while (!descriptor && proto !== null) {
descriptor = Object.getOwnPropertyDescriptor(proto, propertyName);
proto = Object.getPrototypeOf(proto);
}
if (!descriptor) {
throw new Error(propertyName + ' property does not exist');
}
if (!descriptor.configurable) {
throw new Error(propertyName + ' is not declared configurable');
}
if (!descriptor[accessType]) {
throw new Error('Property ' + propertyName + ' does not have access type ' + accessType);
}
var original = descriptor[accessType];
if (!this.isMockFunction(original)) {
if (typeof original !== 'function') {
throw new Error('Cannot spy the ' + propertyName + ' property because it is not a function; ' + this._typeOf(original) + ' given instead');
}
descriptor[accessType] = this._makeComponent({
type: 'function'
}, function () {
descriptor[accessType] = original;
Object.defineProperty(obj, propertyName, descriptor);
});
descriptor[accessType].mockImplementation(function () {
// @ts-ignore
return original.apply(this, arguments);
});
}
Object.defineProperty(obj, propertyName, descriptor);
return descriptor[accessType];
}
}, {
key: "clearAllMocks",
value: function clearAllMocks() {
this._mockState = new WeakMap();
}
}, {
key: "resetAllMocks",
value: function resetAllMocks() {
this._mockConfigRegistry = new WeakMap();
this._mockState = new WeakMap();
}
}, {
key: "restoreAllMocks",
value: function restoreAllMocks() {
this._spyState.forEach(function (restore) {
return restore();
});
this._spyState = new Set();
}
}, {
key: "_typeOf",
value: function _typeOf(value) {
return value == null ? '' + value : _typeof(value);
}
}]);
return ModuleMockerClass;
}();
/* eslint-disable-next-line no-redeclare */
var JestMock = new ModuleMockerClass(global);
module.exports = JestMock;
/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "./node_modules/webpack/buildin/global.js")))
/***/ })
/******/ });
});
//# sourceMappingURL=index.js.map

1
node_modules/jest-mock/build-es5/index.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

136
node_modules/jest-mock/build/index.d.ts generated vendored Normal file
View file

@ -0,0 +1,136 @@
/**
* 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.
*/
/// <reference types="node" />
declare type Global = NodeJS.Global;
declare namespace JestMock {
type ModuleMocker = ModuleMockerClass;
type MockFunctionMetadataType = 'object' | 'array' | 'regexp' | 'function' | 'constant' | 'collection' | 'null' | 'undefined';
type MockFunctionMetadata<T, Y extends Array<unknown>, Type = MockFunctionMetadataType> = {
ref?: number;
members?: {
[key: string]: MockFunctionMetadata<T, Y>;
};
mockImpl?: (...args: Y) => T;
name?: string;
refID?: number;
type?: Type;
value?: T;
length?: number;
};
}
/**
* 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>;
/**
* 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;
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;
private _mockConfigRegistry;
private _spyState;
private _invocationCallCounter;
ModuleMocker: typeof ModuleMockerClass;
/**
* @see README.md
* @param global Global object of the test environment, used to create
* mocks
*/
constructor(global: Global);
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: JestMock.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>): 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;
private _spyOnProperty;
clearAllMocks(): void;
resetAllMocks(): void;
restoreAllMocks(): void;
private _typeOf;
}
declare const JestMock: ModuleMockerClass;
export = JestMock;
//# sourceMappingURL=index.d.ts.map

1
node_modules/jest-mock/build/index.d.ts.map generated vendored Normal file
View file

@ -0,0 +1 @@
{"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,UAAU,GACV,YAAY,GACZ,MAAM,GACN,WAAW,CAAC;IAEhB,KAAY,oBAAoB,CAC9B,CAAC,EACD,CAAC,SAAS,KAAK,CAAC,OAAO,CAAC,EACxB,IAAI,GAAG,wBAAwB,IAC7B;QACF,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,OAAO,CAAC,EAAE;YAAC,CAAC,GAAG,EAAE,MAAM,GAAG,oBAAoB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;SAAC,CAAC;QACtD,QAAQ,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC;QAC7B,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,IAAI,CAAC,EAAE,IAAI,CAAC;QACZ,KAAK,CAAC,EAAE,CAAC,CAAC;QACV,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,CAAC;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I,CAAC,CAAC,EAAE,CAAC,CAAC;IASb,KAAK,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,wBAAwB,CAAC,CAAC,CAAC,EACvD,MAAM,EAAE,CAAC,EACT,UAAU,EAAE,CAAC,EACb,UAAU,EAAE,KAAK,GAChB,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;IAExB,KAAK,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,wBAAwB,CAAC,CAAC,CAAC,EACvD,MAAM,EAAE,CAAC,EACT,UAAU,EAAE,CAAC,EACb,UAAU,EAAE,KAAK,GAChB,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAE5B,KAAK,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,qBAAqB,CAAC,CAAC,CAAC,EACpD,MAAM,EAAE,CAAC,EACT,UAAU,EAAE,CAAC,GACZ,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,KAAK,GAAG,GACxC,WAAW,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAC/C,KAAK;IA4CT,OAAO,CAAC,cAAc;IAyEtB,aAAa;IAIb,aAAa;IAKb,eAAe;IAKf,OAAO,CAAC,OAAO;CAGhB;AAGD,QAAA,MAAM,QAAQ,mBAAgC,CAAC;AAC/C,SAAS,QAAQ,CAAC"}

960
node_modules/jest-mock/build/index.js generated vendored Normal file
View file

@ -0,0 +1,960 @@
'use strict';
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
/**
* 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.
*/
/**
* 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).
*/
/**
* Represents the result of a single call to a mock function.
*/
// see https://github.com/Microsoft/TypeScript/issues/25215
const MOCK_CONSTRUCTOR_NAME = 'mockConstructor';
const FUNCTION_NAME_RESERVED_PATTERN = /[\s!-\/:-@\[-`{-~]/;
const FUNCTION_NAME_RESERVED_REPLACE = new RegExp(
FUNCTION_NAME_RESERVED_PATTERN.source,
'g'
);
const RESERVED_KEYWORDS = new Set([
'arguments',
'await',
'break',
'case',
'catch',
'class',
'const',
'continue',
'debugger',
'default',
'delete',
'do',
'else',
'enum',
'eval',
'export',
'extends',
'false',
'finally',
'for',
'function',
'if',
'implements',
'import',
'in',
'instanceof',
'interface',
'let',
'new',
'null',
'package',
'private',
'protected',
'public',
'return',
'static',
'super',
'switch',
'this',
'throw',
'true',
'try',
'typeof',
'var',
'void',
'while',
'with',
'yield'
]);
function matchArity(fn, length) {
let mockConstructor;
switch (length) {
case 1:
mockConstructor = function mockConstructor(_a) {
return fn.apply(this, arguments);
};
break;
case 2:
mockConstructor = function mockConstructor(_a, _b) {
return fn.apply(this, arguments);
};
break;
case 3:
mockConstructor = function mockConstructor(_a, _b, _c) {
return fn.apply(this, arguments);
};
break;
case 4:
mockConstructor = function mockConstructor(_a, _b, _c, _d) {
return fn.apply(this, arguments);
};
break;
case 5:
mockConstructor = function mockConstructor(_a, _b, _c, _d, _e) {
return fn.apply(this, arguments);
};
break;
case 6:
mockConstructor = function mockConstructor(_a, _b, _c, _d, _e, _f) {
return fn.apply(this, arguments);
};
break;
case 7:
mockConstructor = function mockConstructor(_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
) {
return fn.apply(this, arguments);
};
break;
case 9:
mockConstructor = function mockConstructor(
_a,
_b,
_c,
_d,
_e,
_f,
_g,
_h,
_i
) {
return fn.apply(this, arguments);
};
break;
default:
mockConstructor = function mockConstructor() {
return fn.apply(this, arguments);
};
break;
}
return mockConstructor;
}
function getObjectType(value) {
return Object.prototype.toString.apply(value).slice(8, -1);
}
function getType(ref) {
const typeName = getObjectType(ref);
if (
typeName === 'Function' ||
typeName === 'AsyncFunction' ||
typeName === 'GeneratorFunction'
) {
return 'function';
} else if (Array.isArray(ref)) {
return 'array';
} else if (typeName === 'Object') {
return 'object';
} else if (
typeName === 'Number' ||
typeName === 'String' ||
typeName === 'Boolean' ||
typeName === 'Symbol'
) {
return 'constant';
} else if (
typeName === 'Map' ||
typeName === 'WeakMap' ||
typeName === 'Set'
) {
return 'collection';
} else if (typeName === 'RegExp') {
return 'regexp';
} else if (ref === undefined) {
return 'undefined';
} else if (ref === null) {
return 'null';
} else {
return null;
}
}
function isReadonlyProp(object, prop) {
if (
prop === 'arguments' ||
prop === 'caller' ||
prop === 'callee' ||
prop === 'name' ||
prop === 'length'
) {
const typeName = getObjectType(object);
return (
typeName === 'Function' ||
typeName === 'AsyncFunction' ||
typeName === 'GeneratorFunction'
);
}
if (
prop === 'source' ||
prop === 'global' ||
prop === 'ignoreCase' ||
prop === 'multiline'
) {
return getObjectType(object) === 'RegExp';
}
return false;
}
class ModuleMockerClass {
/**
* @see README.md
* @param global Global object of the test environment, used to create
* mocks
*/
constructor(global) {
_defineProperty(this, '_environmentGlobal', void 0);
_defineProperty(this, '_mockState', void 0);
_defineProperty(this, '_mockConfigRegistry', void 0);
_defineProperty(this, '_spyState', void 0);
_defineProperty(this, '_invocationCallCounter', void 0);
_defineProperty(this, 'ModuleMocker', void 0);
this._environmentGlobal = global;
this._mockState = new WeakMap();
this._mockConfigRegistry = new WeakMap();
this._spyState = new Set();
this.ModuleMocker = ModuleMockerClass;
this._invocationCallCounter = 1;
}
_getSlots(object) {
if (!object) {
return [];
}
const slots = new Set();
const EnvObjectProto = this._environmentGlobal.Object.prototype;
const EnvFunctionProto = this._environmentGlobal.Function.prototype;
const EnvRegExpProto = this._environmentGlobal.RegExp.prototype; // Also check the builtins in the current context as they leak through
// core node modules.
const ObjectProto = Object.prototype;
const FunctionProto = Function.prototype;
const RegExpProto = RegExp.prototype; // Properties of Object.prototype, Function.prototype and RegExp.prototype
// are never reported as slots
while (
object != null &&
object !== EnvObjectProto &&
object !== EnvFunctionProto &&
object !== EnvRegExpProto &&
object !== ObjectProto &&
object !== FunctionProto &&
object !== RegExpProto
) {
const ownNames = Object.getOwnPropertyNames(object);
for (let i = 0; i < ownNames.length; i++) {
const prop = ownNames[i];
if (!isReadonlyProp(object, prop)) {
const propDesc = Object.getOwnPropertyDescriptor(object, prop); // @ts-ignore Object.__esModule
if ((propDesc !== undefined && !propDesc.get) || object.__esModule) {
slots.add(prop);
}
}
}
object = Object.getPrototypeOf(object);
}
return Array.from(slots);
}
_ensureMockConfig(f) {
let config = this._mockConfigRegistry.get(f);
if (!config) {
config = this._defaultMockConfig();
this._mockConfigRegistry.set(f, config);
}
return config;
}
_ensureMockState(f) {
let state = this._mockState.get(f);
if (!state) {
state = this._defaultMockState();
this._mockState.set(f, state);
}
return state;
}
_defaultMockConfig() {
return {
defaultReturnValue: undefined,
isReturnValueLastSet: false,
mockImpl: undefined,
mockName: 'jest.fn()',
specificMockImpls: [],
specificReturnValues: []
};
}
_defaultMockState() {
return {
calls: [],
instances: [],
invocationCallOrder: [],
results: []
};
}
_makeComponent(metadata, restore) {
if (metadata.type === 'object') {
return new this._environmentGlobal.Object();
} else if (metadata.type === 'array') {
return new this._environmentGlobal.Array();
} else if (metadata.type === 'regexp') {
return new this._environmentGlobal.RegExp('');
} else if (
metadata.type === 'constant' ||
metadata.type === 'collection' ||
metadata.type === 'null' ||
metadata.type === 'undefined'
) {
return metadata.value;
} else if (metadata.type === 'function') {
const prototype =
(metadata.members &&
metadata.members.prototype &&
metadata.members.prototype.members) ||
{};
const prototypeSlots = this._getSlots(prototype);
const mocker = this;
const mockConstructor = matchArity(function(...args) {
const mockState = mocker._ensureMockState(f);
const mockConfig = mocker._ensureMockConfig(f);
mockState.instances.push(this);
mockState.calls.push(args); // Create and record an "incomplete" mock result immediately upon
// calling rather than waiting for the mock to return. This avoids
// issues caused by recursion where results can be recorded in the
// wrong order.
const mockResult = {
type: 'incomplete',
value: undefined
};
mockState.results.push(mockResult);
mockState.invocationCallOrder.push(mocker._invocationCallCounter++); // Will be set to the return value of the mock if an error is not thrown
let finalReturnValue; // Will be set to the error that is thrown by the mock (if it throws)
let thrownError; // Will be set to true if the mock throws an error. The presence of a
// value in `thrownError` is not a 100% reliable indicator because a
// function could throw a value of undefined.
let callDidThrowError = false;
try {
// The bulk of the implementation is wrapped in an immediately
// executed arrow function so the return value of the mock function
// can be easily captured and recorded, despite the many separate
// return points within the logic.
finalReturnValue = (() => {
if (this instanceof f) {
// This is probably being called as a constructor
prototypeSlots.forEach(slot => {
// Copy prototype methods to the instance to make
// 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
this[slot] = mocker.generateFromMetadata(prototype[slot]); // @ts-ignore no index signature
this[slot]._protoImpl = protoImpl;
}
}); // Run the mock constructor implementation
const mockImpl = mockConfig.specificMockImpls.length
? 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.
let specificMockImpl;
if (returnValue === undefined) {
specificMockImpl = mockConfig.specificMockImpls.shift();
if (specificMockImpl === undefined) {
specificMockImpl = mockConfig.mockImpl;
}
if (specificMockImpl) {
return specificMockImpl.apply(this, arguments);
}
} // Otherwise use prototype implementation
if (returnValue === undefined && f._protoImpl) {
return f._protoImpl.apply(this, arguments);
}
return returnValue;
})();
} catch (error) {
// Store the thrown error so we can record it, then re-throw it.
thrownError = error;
callDidThrowError = true;
throw error;
} finally {
// Record the result of the function.
// NOTE: Intentionally NOT pushing/indexing into the array of mock
// results here to avoid corrupting results data if mockClear()
// is called during the execution of the mock.
mockResult.type = callDidThrowError ? 'throw' : 'return';
mockResult.value = callDidThrowError ? thrownError : finalReturnValue;
}
return finalReturnValue;
}, metadata.length || 0);
const f = this._createMockFunction(metadata, mockConstructor);
f._isMockFunction = true;
f.getMockImplementation = () => this._ensureMockConfig(f).mockImpl;
if (typeof restore === 'function') {
this._spyState.add(restore);
}
this._mockState.set(f, this._defaultMockState());
this._mockConfigRegistry.set(f, this._defaultMockConfig());
Object.defineProperty(f, 'mock', {
configurable: false,
enumerable: true,
get: () => this._ensureMockState(f),
set: val => this._mockState.set(f, val)
});
f.mockClear = () => {
this._mockState.delete(f);
return f;
};
f.mockReset = () => {
f.mockClear();
this._mockConfigRegistry.delete(f);
return f;
};
f.mockRestore = () => {
f.mockReset();
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.mockResolvedValueOnce = value =>
f.mockImplementationOnce(() => Promise.resolve(value));
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.mockResolvedValue = value =>
f.mockImplementation(() => Promise.resolve(value));
f.mockRejectedValue = value =>
f.mockImplementation(() => Promise.reject(value));
f.mockImplementationOnce = fn => {
// next function call will use this mock implementation return value
// or default mock implementation return value
const mockConfig = this._ensureMockConfig(f);
mockConfig.isReturnValueLastSet = false;
mockConfig.specificMockImpls.push(fn);
return f;
};
f.mockImplementation = fn => {
// 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() {
return this;
});
f.mockName = name => {
if (name) {
const mockConfig = this._ensureMockConfig(f);
mockConfig.mockName = name;
}
return f;
};
f.getMockName = () => {
const mockConfig = this._ensureMockConfig(f);
return mockConfig.mockName || 'jest.fn()';
};
if (metadata.mockImpl) {
f.mockImplementation(metadata.mockImpl);
}
return f;
} else {
const unknownType = metadata.type || 'undefined type';
throw new Error('Unrecognized type ' + unknownType);
}
}
_createMockFunction(metadata, mockConstructor) {
let name = metadata.name;
if (!name) {
return mockConstructor;
} // Preserve `name` property of mocked function.
const boundFunctionPrefix = 'bound ';
let bindCall = ''; // if-do-while for perf reasons. The common case is for the if to fail.
if (name && name.startsWith(boundFunctionPrefix)) {
do {
name = name.substring(boundFunctionPrefix.length); // Call bind() just to alter the function name.
bindCall = '.bind(null)';
} while (name && name.startsWith(boundFunctionPrefix));
} // Special case functions named `mockConstructor` to guard for infinite
// loops.
if (name === MOCK_CONSTRUCTOR_NAME) {
return mockConstructor;
}
if (
// It's a syntax error to define functions with a reserved keyword
// as name.
RESERVED_KEYWORDS.has(name) || // It's also a syntax error to define functions with a name that starts with a number
/^\d/.test(name)
) {
name = '$' + name;
} // It's also a syntax error to define a function with a reserved character
// as part of it's name.
if (FUNCTION_NAME_RESERVED_PATTERN.test(name)) {
name = name.replace(FUNCTION_NAME_RESERVED_REPLACE, '$');
}
const body =
'return function ' +
name +
'() {' +
'return ' +
MOCK_CONSTRUCTOR_NAME +
'.apply(this,arguments);' +
'}' +
bindCall;
const createConstructor = new this._environmentGlobal.Function(
MOCK_CONSTRUCTOR_NAME,
body
);
return createConstructor(mockConstructor);
}
_generateMock(metadata, callbacks, refs) {
// metadata not compatible but it's the same type, maybe problem with
// overloading of _makeComponent and not _generateMock?
// @ts-ignore
const mock = this._makeComponent(metadata);
if (metadata.refID != null) {
refs[metadata.refID] = mock;
}
this._getSlots(metadata.members).forEach(slot => {
const slotMetadata = (metadata.members && metadata.members[slot]) || {};
if (slotMetadata.ref != null) {
callbacks.push(
(function(ref) {
return () => (mock[slot] = refs[ref]);
})(slotMetadata.ref)
);
} else {
mock[slot] = this._generateMock(slotMetadata, callbacks, refs);
}
});
if (
metadata.type !== 'undefined' &&
metadata.type !== 'null' &&
mock.prototype &&
typeof mock.prototype === 'object'
) {
mock.prototype.constructor = mock;
}
return mock;
}
/**
* @see README.md
* @param _metadata Metadata for the mock in the schema returned by the
* getMetadata method of this module.
*/
generateFromMetadata(_metadata) {
const callbacks = [];
const refs = {};
const mock = this._generateMock(_metadata, callbacks, refs);
callbacks.forEach(setter => setter());
return mock;
}
/**
* @see README.md
* @param component The component for which to retrieve metadata.
*/
getMetadata(component, _refs) {
const refs = _refs || new Map();
const ref = refs.get(component);
if (ref != null) {
return {
ref
};
}
const type = getType(component);
if (!type) {
return null;
}
const metadata = {
type
};
if (
type === 'constant' ||
type === 'collection' ||
type === 'undefined' ||
type === 'null'
) {
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
if (component._isMockFunction === true) {
// @ts-ignore may be a mock
metadata.mockImpl = component.getMockImplementation();
}
}
metadata.refID = refs.size;
refs.set(component, metadata.refID);
let members = null; // Leave arrays alone
if (type !== 'array') {
this._getSlots(component).forEach(slot => {
if (
type === 'function' && // @ts-ignore may be a mock
component._isMockFunction === true &&
slot.match(/^mock/)
) {
return;
} // @ts-ignore no index signature
const slotMetadata = this.getMetadata(component[slot], refs);
if (slotMetadata) {
if (!members) {
members = {};
}
members[slot] = slotMetadata;
}
});
}
if (members) {
metadata.members = members;
}
return metadata;
}
isMockFunction(fn) {
return !!fn && fn._isMockFunction === true;
}
fn(implementation) {
const length = implementation ? implementation.length : 0;
const fn = this._makeComponent({
length,
type: 'function'
});
if (implementation) {
fn.mockImplementation(implementation);
}
return fn;
}
spyOn(object, methodName, accessType) {
if (accessType) {
return this._spyOnProperty(object, methodName, accessType);
}
if (typeof object !== 'object' && typeof object !== 'function') {
throw new Error(
'Cannot spyOn on a primitive value; ' + this._typeOf(object) + ' given'
);
}
const original = object[methodName];
if (!this.isMockFunction(original)) {
if (typeof original !== 'function') {
throw new Error(
'Cannot spy the ' +
methodName +
' property because it is not a function; ' +
this._typeOf(original) +
' given instead'
);
} // @ts-ignore overriding original method with a Mock
object[methodName] = this._makeComponent(
{
type: 'function'
},
() => {
object[methodName] = original;
}
); // @ts-ignore original method is now a Mock
object[methodName].mockImplementation(function() {
return original.apply(this, arguments);
});
}
return object[methodName];
}
_spyOnProperty(obj, propertyName, accessType = 'get') {
if (typeof obj !== 'object' && typeof obj !== 'function') {
throw new Error(
'Cannot spyOn on a primitive value; ' + this._typeOf(obj) + ' given'
);
}
if (!obj) {
throw new Error(
'spyOn could not find an object to spy upon for ' + propertyName + ''
);
}
if (!propertyName) {
throw new Error('No property name supplied');
}
let descriptor = Object.getOwnPropertyDescriptor(obj, propertyName);
let proto = Object.getPrototypeOf(obj);
while (!descriptor && proto !== null) {
descriptor = Object.getOwnPropertyDescriptor(proto, propertyName);
proto = Object.getPrototypeOf(proto);
}
if (!descriptor) {
throw new Error(propertyName + ' property does not exist');
}
if (!descriptor.configurable) {
throw new Error(propertyName + ' is not declared configurable');
}
if (!descriptor[accessType]) {
throw new Error(
'Property ' + propertyName + ' does not have access type ' + accessType
);
}
const original = descriptor[accessType];
if (!this.isMockFunction(original)) {
if (typeof original !== 'function') {
throw new Error(
'Cannot spy the ' +
propertyName +
' property because it is not a function; ' +
this._typeOf(original) +
' given instead'
);
}
descriptor[accessType] = this._makeComponent(
{
type: 'function'
},
() => {
descriptor[accessType] = original;
Object.defineProperty(obj, propertyName, descriptor);
}
);
descriptor[accessType].mockImplementation(function() {
// @ts-ignore
return original.apply(this, arguments);
});
}
Object.defineProperty(obj, propertyName, descriptor);
return descriptor[accessType];
}
clearAllMocks() {
this._mockState = new WeakMap();
}
resetAllMocks() {
this._mockConfigRegistry = new WeakMap();
this._mockState = new WeakMap();
}
restoreAllMocks() {
this._spyState.forEach(restore => restore());
this._spyState = new Set();
}
_typeOf(value) {
return value == null ? '' + value : typeof value;
}
}
/* eslint-disable-next-line no-redeclare */
const JestMock = new ModuleMockerClass(global);
module.exports = JestMock;

57
node_modules/jest-mock/package.json generated vendored Normal file
View file

@ -0,0 +1,57 @@
{
"_from": "jest-mock@^24.8.0",
"_id": "jest-mock@24.8.0",
"_inBundle": false,
"_integrity": "sha512-6kWugwjGjJw+ZkK4mDa0Df3sDlUTsV47MSrT0nGQ0RBWJbpODDQ8MHDVtGtUYBne3IwZUhtB7elxHspU79WH3A==",
"_location": "/jest-mock",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "jest-mock@^24.8.0",
"name": "jest-mock",
"escapedName": "jest-mock",
"rawSpec": "^24.8.0",
"saveSpec": null,
"fetchSpec": "^24.8.0"
},
"_requiredBy": [
"/@jest/environment",
"/@jest/fake-timers",
"/jest-environment-jsdom",
"/jest-environment-node",
"/jest-runtime"
],
"_resolved": "https://registry.npmjs.org/jest-mock/-/jest-mock-24.8.0.tgz",
"_shasum": "2f9d14d37699e863f1febf4e4d5a33b7fdbbde56",
"_spec": "jest-mock@^24.8.0",
"_where": "E:\\github\\setup-java\\node_modules\\@jest\\environment",
"browser": "build-es5/index.js",
"bugs": {
"url": "https://github.com/facebook/jest/issues"
},
"bundleDependencies": false,
"dependencies": {
"@jest/types": "^24.8.0"
},
"deprecated": false,
"description": "## API",
"engines": {
"node": ">= 6"
},
"gitHead": "845728f24b3ef41e450595c384e9b5c9fdf248a4",
"homepage": "https://github.com/facebook/jest#readme",
"license": "MIT",
"main": "build/index.js",
"name": "jest-mock",
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "git+https://github.com/facebook/jest.git",
"directory": "packages/jest-mock"
},
"types": "build/index.d.ts",
"version": "24.8.0"
}

8
node_modules/jest-mock/tsconfig.json generated vendored Normal file
View file

@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "build"
},
"references": [{"path": "../jest-types"}]
}

2217
node_modules/jest-mock/tsconfig.tsbuildinfo generated vendored Normal file

File diff suppressed because it is too large Load diff