added unit testing, and started implementing unit tests...phew

This commit is contained in:
Josh Burman
2019-03-12 22:28:02 -04:00
parent 74aad4a957
commit e8c2539f1b
3489 changed files with 464813 additions and 88 deletions

57
node_modules/sinon/lib/sinon.js generated vendored Normal file
View File

@ -0,0 +1,57 @@
"use strict";
var behavior = require("./sinon/behavior");
var createSandbox = require("./sinon/create-sandbox");
var deprecated = require("./sinon/util/core/deprecated");
var extend = require("./sinon/util/core/extend");
var fakeTimers = require("./sinon/util/fake-timers");
var format = require("./sinon/util/core/format");
var nise = require("nise");
var Sandbox = require("./sinon/sandbox");
var stub = require("./sinon/stub");
var apiMethods = {
createSandbox: createSandbox,
assert: require("./sinon/assert"),
match: require("@sinonjs/samsam").createMatcher,
spyCall: require("./sinon/call"),
expectation: require("./sinon/mock-expectation"),
createStubInstance: require("./sinon/stub").createStubInstance,
defaultConfig: require("./sinon/util/core/default-config"),
setFormatter: format.setFormatter,
// fake timers
timers: fakeTimers.timers,
// fake XHR
xhr: nise.fakeXhr.xhr,
FakeXMLHttpRequest: nise.fakeXhr.FakeXMLHttpRequest,
// fake server
fakeServer: nise.fakeServer,
fakeServerWithClock: nise.fakeServerWithClock,
createFakeServer: nise.fakeServer.create.bind(nise.fakeServer),
createFakeServerWithClock: nise.fakeServerWithClock.create.bind(nise.fakeServerWithClock),
addBehavior: function(name, fn) {
behavior.addBehavior(stub, name, fn);
}
};
var legacySandboxAPI = {
sandbox: {
create: deprecated.wrap(
createSandbox,
// eslint-disable-next-line max-len
"`sandbox.create()` is deprecated. Use default sandbox at `sinon.sandbox` or create new sandboxes with `sinon.createSandbox()`"
)
}
};
var sandbox = new Sandbox();
var api = extend(sandbox, legacySandboxAPI, apiMethods);
module.exports = api;

214
node_modules/sinon/lib/sinon/assert.js generated vendored Normal file
View File

@ -0,0 +1,214 @@
"use strict";
var arrayProto = require("@sinonjs/commons").prototypes.array;
var calledInOrder = require("@sinonjs/commons").calledInOrder;
var createMatcher = require("@sinonjs/samsam").createMatcher;
var orderByFirstCall = require("@sinonjs/commons").orderByFirstCall;
var timesInWords = require("./util/core/times-in-words");
var format = require("./util/core/format");
var stringSlice = require("@sinonjs/commons").prototypes.string.slice;
var arraySlice = arrayProto.slice;
var concat = arrayProto.concat;
var forEach = arrayProto.forEach;
var join = arrayProto.join;
var splice = arrayProto.splice;
var assert;
function verifyIsStub() {
var args = arraySlice(arguments);
forEach(args, function(method) {
if (!method) {
assert.fail("fake is not a spy");
}
if (method.proxy && method.proxy.isSinonProxy) {
verifyIsStub(method.proxy);
} else {
if (typeof method !== "function") {
assert.fail(method + " is not a function");
}
if (typeof method.getCall !== "function") {
assert.fail(method + " is not stubbed");
}
}
});
}
function verifyIsValidAssertion(assertionMethod, assertionArgs) {
switch (assertionMethod) {
case "notCalled":
case "called":
case "calledOnce":
case "calledTwice":
case "calledThrice":
if (assertionArgs.length !== 0) {
assert.fail(
assertionMethod +
" takes 1 argument but was called with " +
(assertionArgs.length + 1) +
" arguments"
);
}
break;
default:
break;
}
}
function failAssertion(object, msg) {
var obj = object || global;
var failMethod = obj.fail || assert.fail;
failMethod.call(obj, msg);
}
function mirrorPropAsAssertion(name, method, message) {
var msg = message;
var meth = method;
if (arguments.length === 2) {
msg = method;
meth = name;
}
assert[name] = function(fake) {
verifyIsStub(fake);
var args = arraySlice(arguments, 1);
var failed = false;
verifyIsValidAssertion(name, args);
if (typeof meth === "function") {
failed = !meth(fake);
} else {
failed = typeof fake[meth] === "function" ? !fake[meth].apply(fake, args) : !fake[meth];
}
if (failed) {
failAssertion(this, (fake.printf || fake.proxy.printf).apply(fake, concat([msg], args)));
} else {
assert.pass(name);
}
};
}
function exposedName(prefix, prop) {
return !prefix || /^fail/.test(prop) ? prop : prefix + stringSlice(prop, 0, 1).toUpperCase() + stringSlice(prop, 1);
}
assert = {
failException: "AssertError",
fail: function fail(message) {
var error = new Error(message);
error.name = this.failException || assert.failException;
throw error;
},
pass: function pass() {
return;
},
callOrder: function assertCallOrder() {
verifyIsStub.apply(null, arguments);
var expected = "";
var actual = "";
if (!calledInOrder(arguments)) {
try {
expected = join(arguments, ", ");
var calls = arraySlice(arguments);
var i = calls.length;
while (i) {
if (!calls[--i].called) {
splice(calls, i, 1);
}
}
actual = join(orderByFirstCall(calls), ", ");
} catch (e) {
// If this fails, we'll just fall back to the blank string
}
failAssertion(this, "expected " + expected + " to be called in order but were called as " + actual);
} else {
assert.pass("callOrder");
}
},
callCount: function assertCallCount(method, count) {
verifyIsStub(method);
if (method.callCount !== count) {
var msg = "expected %n to be called " + timesInWords(count) + " but was called %c%C";
failAssertion(this, method.printf(msg));
} else {
assert.pass("callCount");
}
},
expose: function expose(target, options) {
if (!target) {
throw new TypeError("target is null or undefined");
}
var o = options || {};
var prefix = (typeof o.prefix === "undefined" && "assert") || o.prefix;
var includeFail = typeof o.includeFail === "undefined" || Boolean(o.includeFail);
var instance = this;
forEach(Object.keys(instance), function(method) {
if (method !== "expose" && (includeFail || !/^(fail)/.test(method))) {
target[exposedName(prefix, method)] = instance[method];
}
});
return target;
},
match: function match(actual, expectation) {
var matcher = createMatcher(expectation);
if (matcher.test(actual)) {
assert.pass("match");
} else {
var formatted = [
"expected value to match",
" expected = " + format(expectation),
" actual = " + format(actual)
];
failAssertion(this, join(formatted, "\n"));
}
}
};
mirrorPropAsAssertion("called", "expected %n to have been called at least once but was never called");
mirrorPropAsAssertion(
"notCalled",
function(spy) {
return !spy.called;
},
"expected %n to not have been called but was called %c%C"
);
mirrorPropAsAssertion("calledOnce", "expected %n to be called once but was called %c%C");
mirrorPropAsAssertion("calledTwice", "expected %n to be called twice but was called %c%C");
mirrorPropAsAssertion("calledThrice", "expected %n to be called thrice but was called %c%C");
mirrorPropAsAssertion("calledOn", "expected %n to be called with %1 as this but was called with %t");
mirrorPropAsAssertion("alwaysCalledOn", "expected %n to always be called with %1 as this but was called with %t");
mirrorPropAsAssertion("calledWithNew", "expected %n to be called with new");
mirrorPropAsAssertion("alwaysCalledWithNew", "expected %n to always be called with new");
mirrorPropAsAssertion("calledWith", "expected %n to be called with arguments %D");
mirrorPropAsAssertion("calledWithMatch", "expected %n to be called with match %D");
mirrorPropAsAssertion("alwaysCalledWith", "expected %n to always be called with arguments %D");
mirrorPropAsAssertion("alwaysCalledWithMatch", "expected %n to always be called with match %D");
mirrorPropAsAssertion("calledWithExactly", "expected %n to be called with exact arguments %D");
mirrorPropAsAssertion("alwaysCalledWithExactly", "expected %n to always be called with exact arguments %D");
mirrorPropAsAssertion("neverCalledWith", "expected %n to never be called with arguments %*%C");
mirrorPropAsAssertion("neverCalledWithMatch", "expected %n to never be called with match %*%C");
mirrorPropAsAssertion("threw", "%n did not throw exception%C");
mirrorPropAsAssertion("alwaysThrew", "%n did not always throw exception%C");
module.exports = assert;

230
node_modules/sinon/lib/sinon/behavior.js generated vendored Normal file
View File

@ -0,0 +1,230 @@
"use strict";
var arrayProto = require("@sinonjs/commons").prototypes.array;
var extend = require("./util/core/extend");
var functionName = require("@sinonjs/commons").functionName;
var nextTick = require("./util/core/next-tick");
var valueToString = require("@sinonjs/commons").valueToString;
var exportAsyncBehaviors = require("./util/core/export-async-behaviors");
var concat = arrayProto.concat;
var join = arrayProto.join;
var reverse = arrayProto.reverse;
var slice = arrayProto.slice;
var useLeftMostCallback = -1;
var useRightMostCallback = -2;
function getCallback(behavior, args) {
var callArgAt = behavior.callArgAt;
if (callArgAt >= 0) {
return args[callArgAt];
}
var argumentList;
if (callArgAt === useLeftMostCallback) {
argumentList = args;
}
if (callArgAt === useRightMostCallback) {
argumentList = reverse(slice(args));
}
var callArgProp = behavior.callArgProp;
for (var i = 0, l = argumentList.length; i < l; ++i) {
if (!callArgProp && typeof argumentList[i] === "function") {
return argumentList[i];
}
if (callArgProp && argumentList[i] && typeof argumentList[i][callArgProp] === "function") {
return argumentList[i][callArgProp];
}
}
return null;
}
function getCallbackError(behavior, func, args) {
if (behavior.callArgAt < 0) {
var msg;
if (behavior.callArgProp) {
msg =
functionName(behavior.stub) +
" expected to yield to '" +
valueToString(behavior.callArgProp) +
"', but no object with such a property was passed.";
} else {
msg = functionName(behavior.stub) + " expected to yield, but no callback was passed.";
}
if (args.length > 0) {
msg += " Received [" + join(args, ", ") + "]";
}
return msg;
}
return "argument at index " + behavior.callArgAt + " is not a function: " + func;
}
function ensureArgs(name, behavior, args) {
// map function name to internal property
// callsArg => callArgAt
var property = name.replace(/sArg/, "ArgAt");
var index = behavior[property];
if (index >= args.length) {
throw new TypeError(
name + " failed: " + (index + 1) + " arguments required but only " + args.length + " present"
);
}
}
function callCallback(behavior, args) {
if (typeof behavior.callArgAt === "number") {
ensureArgs("callsArg", behavior, args);
var func = getCallback(behavior, args);
if (typeof func !== "function") {
throw new TypeError(getCallbackError(behavior, func, args));
}
if (behavior.callbackAsync) {
nextTick(function() {
func.apply(behavior.callbackContext, behavior.callbackArguments);
});
} else {
return func.apply(behavior.callbackContext, behavior.callbackArguments);
}
}
return undefined;
}
var proto = {
create: function create(stub) {
var behavior = extend({}, proto);
delete behavior.create;
delete behavior.addBehavior;
delete behavior.createBehavior;
behavior.stub = stub;
if (stub.defaultBehavior && stub.defaultBehavior.promiseLibrary) {
behavior.promiseLibrary = stub.defaultBehavior.promiseLibrary;
}
return behavior;
},
isPresent: function isPresent() {
return (
typeof this.callArgAt === "number" ||
this.exception ||
this.exceptionCreator ||
typeof this.returnArgAt === "number" ||
this.returnThis ||
typeof this.resolveArgAt === "number" ||
this.resolveThis ||
typeof this.throwArgAt === "number" ||
this.fakeFn ||
this.returnValueDefined
);
},
invoke: function invoke(context, args) {
/*
* callCallback (conditionally) calls ensureArgs
*
* Note: callCallback intentionally happens before
* everything else and cannot be moved lower
*/
var returnValue = callCallback(this, args);
if (this.exception) {
throw this.exception;
} else if (this.exceptionCreator) {
this.exception = this.exceptionCreator();
this.exceptionCreator = undefined;
throw this.exception;
} else if (typeof this.returnArgAt === "number") {
ensureArgs("returnsArg", this, args);
return args[this.returnArgAt];
} else if (this.returnThis) {
return context;
} else if (typeof this.throwArgAt === "number") {
ensureArgs("throwsArg", this, args);
throw args[this.throwArgAt];
} else if (this.fakeFn) {
return this.fakeFn.apply(context, args);
} else if (typeof this.resolveArgAt === "number") {
ensureArgs("resolvesArg", this, args);
return (this.promiseLibrary || Promise).resolve(args[this.resolveArgAt]);
} else if (this.resolveThis) {
return (this.promiseLibrary || Promise).resolve(context);
} else if (this.resolve) {
return (this.promiseLibrary || Promise).resolve(this.returnValue);
} else if (this.reject) {
return (this.promiseLibrary || Promise).reject(this.returnValue);
} else if (this.callsThrough) {
return this.stub.wrappedMethod.apply(context, args);
} else if (typeof this.returnValue !== "undefined") {
return this.returnValue;
} else if (typeof this.callArgAt === "number") {
return returnValue;
}
return this.returnValue;
},
onCall: function onCall(index) {
return this.stub.onCall(index);
},
onFirstCall: function onFirstCall() {
return this.stub.onFirstCall();
},
onSecondCall: function onSecondCall() {
return this.stub.onSecondCall();
},
onThirdCall: function onThirdCall() {
return this.stub.onThirdCall();
},
withArgs: function withArgs(/* arguments */) {
throw new Error(
'Defining a stub by invoking "stub.onCall(...).withArgs(...)" ' +
'is not supported. Use "stub.withArgs(...).onCall(...)" ' +
"to define sequential behavior for calls with certain arguments."
);
}
};
function createBehavior(behaviorMethod) {
return function() {
this.defaultBehavior = this.defaultBehavior || proto.create(this);
this.defaultBehavior[behaviorMethod].apply(this.defaultBehavior, arguments);
return this;
};
}
function addBehavior(stub, name, fn) {
proto[name] = function() {
fn.apply(this, concat([this], slice(arguments)));
return this.stub || this;
};
stub[name] = createBehavior(name);
}
proto.addBehavior = addBehavior;
proto.createBehavior = createBehavior;
var asyncBehaviors = exportAsyncBehaviors(proto);
module.exports = extend.nonEnum({}, proto, asyncBehaviors);

10
node_modules/sinon/lib/sinon/blob.js generated vendored Normal file
View File

@ -0,0 +1,10 @@
/*global Blob */
"use strict";
exports.isSupported = (function() {
try {
return Boolean(new Blob());
} catch (e) {
return false;
}
})();

254
node_modules/sinon/lib/sinon/call.js generated vendored Normal file
View File

@ -0,0 +1,254 @@
"use strict";
var arrayProto = require("@sinonjs/commons").prototypes.array;
var match = require("@sinonjs/samsam").createMatcher;
var deepEqual = require("@sinonjs/samsam").deepEqual;
var functionName = require("@sinonjs/commons").functionName;
var sinonFormat = require("./util/core/format");
var valueToString = require("@sinonjs/commons").valueToString;
var concat = arrayProto.concat;
var filter = arrayProto.filter;
var join = arrayProto.join;
var map = arrayProto.map;
var reduce = arrayProto.reduce;
var slice = arrayProto.slice;
function throwYieldError(proxy, text, args) {
var msg = functionName(proxy) + text;
if (args.length) {
msg += " Received [" + join(slice(args), ", ") + "]";
}
throw new Error(msg);
}
var callProto = {
calledOn: function calledOn(thisValue) {
if (match.isMatcher(thisValue)) {
return thisValue.test(this.thisValue);
}
return this.thisValue === thisValue;
},
calledWith: function calledWith() {
var self = this;
var calledWithArgs = slice(arguments);
if (calledWithArgs.length > self.args.length) {
return false;
}
return reduce(
calledWithArgs,
function(prev, arg, i) {
return prev && deepEqual(self.args[i], arg);
},
true
);
},
calledWithMatch: function calledWithMatch() {
var self = this;
var calledWithMatchArgs = slice(arguments);
if (calledWithMatchArgs.length > self.args.length) {
return false;
}
return reduce(
calledWithMatchArgs,
function(prev, expectation, i) {
var actual = self.args[i];
return prev && match(expectation).test(actual);
},
true
);
},
calledWithExactly: function calledWithExactly() {
return arguments.length === this.args.length && this.calledWith.apply(this, arguments);
},
notCalledWith: function notCalledWith() {
return !this.calledWith.apply(this, arguments);
},
notCalledWithMatch: function notCalledWithMatch() {
return !this.calledWithMatch.apply(this, arguments);
},
returned: function returned(value) {
return deepEqual(this.returnValue, value);
},
threw: function threw(error) {
if (typeof error === "undefined" || !this.exception) {
return Boolean(this.exception);
}
return this.exception === error || this.exception.name === error;
},
calledWithNew: function calledWithNew() {
return this.proxy.prototype && this.thisValue instanceof this.proxy;
},
calledBefore: function(other) {
return this.callId < other.callId;
},
calledAfter: function(other) {
return this.callId > other.callId;
},
calledImmediatelyBefore: function(other) {
return this.callId === other.callId - 1;
},
calledImmediatelyAfter: function(other) {
return this.callId === other.callId + 1;
},
callArg: function(pos) {
this.ensureArgIsAFunction(pos);
return this.args[pos]();
},
callArgOn: function(pos, thisValue) {
this.ensureArgIsAFunction(pos);
return this.args[pos].apply(thisValue);
},
callArgWith: function(pos) {
return this.callArgOnWith.apply(this, concat([pos, null], slice(arguments, 1)));
},
callArgOnWith: function(pos, thisValue) {
this.ensureArgIsAFunction(pos);
var args = slice(arguments, 2);
return this.args[pos].apply(thisValue, args);
},
throwArg: function(pos) {
if (pos > this.args.length) {
throw new TypeError("Not enough arguments: " + pos + " required but only " + this.args.length + " present");
}
throw this.args[pos];
},
yield: function() {
return this.yieldOn.apply(this, concat([null], slice(arguments, 0)));
},
yieldOn: function(thisValue) {
var args = slice(this.args);
var yieldFn = filter(args, function(arg) {
return typeof arg === "function";
})[0];
if (!yieldFn) {
throwYieldError(this.proxy, " cannot yield since no callback was passed.", args);
}
return yieldFn.apply(thisValue, slice(arguments, 1));
},
yieldTo: function(prop) {
return this.yieldToOn.apply(this, concat([prop, null], slice(arguments, 1)));
},
yieldToOn: function(prop, thisValue) {
var args = slice(this.args);
var yieldArg = filter(args, function(arg) {
return arg && typeof arg[prop] === "function";
})[0];
var yieldFn = yieldArg && yieldArg[prop];
if (!yieldFn) {
throwYieldError(
this.proxy,
" cannot yield to '" + valueToString(prop) + "' since no callback was passed.",
args
);
}
return yieldFn.apply(thisValue, slice(arguments, 2));
},
toString: function() {
var callStr = this.proxy ? String(this.proxy) + "(" : "";
var formattedArgs;
if (!this.args) {
return ":(";
}
formattedArgs = map(this.args, function(arg) {
return sinonFormat(arg);
});
callStr = callStr + join(formattedArgs, ", ") + ")";
if (typeof this.returnValue !== "undefined") {
callStr += " => " + sinonFormat(this.returnValue);
}
if (this.exception) {
callStr += " !" + this.exception.name;
if (this.exception.message) {
callStr += "(" + this.exception.message + ")";
}
}
if (this.stack) {
// Omit the error message and the two top stack frames in sinon itself:
callStr += (this.stack.split("\n")[3] || "unknown").replace(/^\s*(?:at\s+|@)?/, " at ");
}
return callStr;
},
ensureArgIsAFunction: function(pos) {
if (typeof this.args[pos] !== "function") {
throw new TypeError(
"Expected argument at position " + pos + " to be a Function, but was " + typeof this.args[pos]
);
}
}
};
Object.defineProperty(callProto, "stack", {
enumerable: true,
configurable: true,
get: function() {
return (this.errorWithCallStack && this.errorWithCallStack.stack) || "";
}
});
callProto.invokeCallback = callProto.yield;
function createSpyCall(spy, thisValue, args, returnValue, exception, id, errorWithCallStack) {
if (typeof id !== "number") {
throw new TypeError("Call id is not a number");
}
var proxyCall = Object.create(callProto);
var lastArg = (args.length > 0 && args[args.length - 1]) || undefined;
var callback = lastArg && typeof lastArg === "function" ? lastArg : undefined;
proxyCall.proxy = spy;
proxyCall.thisValue = thisValue;
proxyCall.args = args;
proxyCall.lastArg = lastArg;
proxyCall.callback = callback;
proxyCall.returnValue = returnValue;
proxyCall.exception = exception;
proxyCall.callId = id;
proxyCall.errorWithCallStack = errorWithCallStack;
return proxyCall;
}
createSpyCall.toString = callProto.toString; // used by mocks
module.exports = createSpyCall;

23
node_modules/sinon/lib/sinon/collect-own-methods.js generated vendored Normal file
View File

@ -0,0 +1,23 @@
"use strict";
var walk = require("./util/core/walk");
var getPropertyDescriptor = require("./util/core/get-property-descriptor");
var hasOwnProperty = require("@sinonjs/commons").prototypes.object.hasOwnProperty;
var push = require("@sinonjs/commons").prototypes.array.push;
function collectMethod(methods, object, prop, propOwner) {
if (typeof getPropertyDescriptor(propOwner, prop).value === "function" && hasOwnProperty(object, prop)) {
push(methods, object[prop]);
}
}
// This function returns an array of all the own methods on the passed object
function collectOwnMethods(object) {
var methods = [];
walk(object, collectMethod.bind(null, methods, object));
return methods;
}
module.exports = collectOwnMethods;

31
node_modules/sinon/lib/sinon/color.js generated vendored Normal file
View File

@ -0,0 +1,31 @@
"use strict";
var supportsColor = require("supports-color");
function colorize(str, color) {
if (supportsColor.stdout === false) {
return str;
}
return "\x1b[" + color + "m" + str + "\x1b[0m";
}
exports.red = function(str) {
return colorize(str, 31);
};
exports.green = function(str) {
return colorize(str, 32);
};
exports.cyan = function(str) {
return colorize(str, 96);
};
exports.white = function(str) {
return colorize(str, 39);
};
exports.bold = function(str) {
return colorize(str, 1);
};

67
node_modules/sinon/lib/sinon/create-sandbox.js generated vendored Normal file
View File

@ -0,0 +1,67 @@
"use strict";
var arrayProto = require("@sinonjs/commons").prototypes.array;
var Sandbox = require("./sandbox");
var forEach = arrayProto.forEach;
var push = arrayProto.push;
function prepareSandboxFromConfig(config) {
var sandbox = new Sandbox();
if (config.useFakeServer) {
if (typeof config.useFakeServer === "object") {
sandbox.serverPrototype = config.useFakeServer;
}
sandbox.useFakeServer();
}
if (config.useFakeTimers) {
if (typeof config.useFakeTimers === "object") {
sandbox.useFakeTimers(config.useFakeTimers);
} else {
sandbox.useFakeTimers();
}
}
return sandbox;
}
function exposeValue(sandbox, config, key, value) {
if (!value) {
return;
}
if (config.injectInto && !(key in config.injectInto)) {
config.injectInto[key] = value;
push(sandbox.injectedKeys, key);
} else {
push(sandbox.args, value);
}
}
function createSandbox(config) {
if (!config) {
return new Sandbox();
}
var configuredSandbox = prepareSandboxFromConfig(config);
configuredSandbox.args = configuredSandbox.args || [];
configuredSandbox.injectedKeys = [];
configuredSandbox.injectInto = config.injectInto;
var exposed = configuredSandbox.inject({});
if (config.properties) {
forEach(config.properties, function(prop) {
var value = exposed[prop] || (prop === "sandbox" && configuredSandbox);
exposeValue(configuredSandbox, config, prop, value);
});
} else {
exposeValue(configuredSandbox, config, "sandbox");
}
return configuredSandbox;
}
module.exports = createSandbox;

266
node_modules/sinon/lib/sinon/default-behaviors.js generated vendored Normal file
View File

@ -0,0 +1,266 @@
"use strict";
var arrayProto = require("@sinonjs/commons").prototypes.array;
var isPropertyConfigurable = require("./util/core/is-property-configurable");
var exportAsyncBehaviors = require("./util/core/export-async-behaviors");
var extend = require("./util/core/extend");
var slice = arrayProto.slice;
var useLeftMostCallback = -1;
var useRightMostCallback = -2;
function throwsException(fake, error, message) {
if (typeof error === "function") {
fake.exceptionCreator = error;
} else if (typeof error === "string") {
fake.exceptionCreator = function() {
var newException = new Error(message || "");
newException.name = error;
return newException;
};
} else if (!error) {
fake.exceptionCreator = function() {
return new Error("Error");
};
} else {
fake.exception = error;
}
}
var defaultBehaviors = {
callsFake: function callsFake(fake, fn) {
fake.fakeFn = fn;
},
callsArg: function callsArg(fake, index) {
if (typeof index !== "number") {
throw new TypeError("argument index is not number");
}
fake.callArgAt = index;
fake.callbackArguments = [];
fake.callbackContext = undefined;
fake.callArgProp = undefined;
fake.callbackAsync = false;
},
callsArgOn: function callsArgOn(fake, index, context) {
if (typeof index !== "number") {
throw new TypeError("argument index is not number");
}
fake.callArgAt = index;
fake.callbackArguments = [];
fake.callbackContext = context;
fake.callArgProp = undefined;
fake.callbackAsync = false;
},
callsArgWith: function callsArgWith(fake, index) {
if (typeof index !== "number") {
throw new TypeError("argument index is not number");
}
fake.callArgAt = index;
fake.callbackArguments = slice(arguments, 2);
fake.callbackContext = undefined;
fake.callArgProp = undefined;
fake.callbackAsync = false;
},
callsArgOnWith: function callsArgWith(fake, index, context) {
if (typeof index !== "number") {
throw new TypeError("argument index is not number");
}
fake.callArgAt = index;
fake.callbackArguments = slice(arguments, 3);
fake.callbackContext = context;
fake.callArgProp = undefined;
fake.callbackAsync = false;
},
usingPromise: function usingPromise(fake, promiseLibrary) {
fake.promiseLibrary = promiseLibrary;
},
yields: function(fake) {
fake.callArgAt = useLeftMostCallback;
fake.callbackArguments = slice(arguments, 1);
fake.callbackContext = undefined;
fake.callArgProp = undefined;
fake.callbackAsync = false;
},
yieldsRight: function(fake) {
fake.callArgAt = useRightMostCallback;
fake.callbackArguments = slice(arguments, 1);
fake.callbackContext = undefined;
fake.callArgProp = undefined;
fake.callbackAsync = false;
},
yieldsOn: function(fake, context) {
fake.callArgAt = useLeftMostCallback;
fake.callbackArguments = slice(arguments, 2);
fake.callbackContext = context;
fake.callArgProp = undefined;
fake.callbackAsync = false;
},
yieldsTo: function(fake, prop) {
fake.callArgAt = useLeftMostCallback;
fake.callbackArguments = slice(arguments, 2);
fake.callbackContext = undefined;
fake.callArgProp = prop;
fake.callbackAsync = false;
},
yieldsToOn: function(fake, prop, context) {
fake.callArgAt = useLeftMostCallback;
fake.callbackArguments = slice(arguments, 3);
fake.callbackContext = context;
fake.callArgProp = prop;
fake.callbackAsync = false;
},
throws: throwsException,
throwsException: throwsException,
returns: function returns(fake, value) {
fake.returnValue = value;
fake.resolve = false;
fake.reject = false;
fake.returnValueDefined = true;
fake.exception = undefined;
fake.exceptionCreator = undefined;
fake.fakeFn = undefined;
},
returnsArg: function returnsArg(fake, index) {
if (typeof index !== "number") {
throw new TypeError("argument index is not number");
}
fake.returnArgAt = index;
},
throwsArg: function throwsArg(fake, index) {
if (typeof index !== "number") {
throw new TypeError("argument index is not number");
}
fake.throwArgAt = index;
},
returnsThis: function returnsThis(fake) {
fake.returnThis = true;
},
resolves: function resolves(fake, value) {
fake.returnValue = value;
fake.resolve = true;
fake.resolveThis = false;
fake.reject = false;
fake.returnValueDefined = true;
fake.exception = undefined;
fake.exceptionCreator = undefined;
fake.fakeFn = undefined;
},
resolvesArg: function resolvesArg(fake, index) {
if (typeof index !== "number") {
throw new TypeError("argument index is not number");
}
fake.resolveArgAt = index;
fake.returnValue = undefined;
fake.resolve = true;
fake.resolveThis = false;
fake.reject = false;
fake.returnValueDefined = false;
fake.exception = undefined;
fake.exceptionCreator = undefined;
fake.fakeFn = undefined;
},
rejects: function rejects(fake, error, message) {
var reason;
if (typeof error === "string") {
reason = new Error(message || "");
reason.name = error;
} else if (!error) {
reason = new Error("Error");
} else {
reason = error;
}
fake.returnValue = reason;
fake.resolve = false;
fake.resolveThis = false;
fake.reject = true;
fake.returnValueDefined = true;
fake.exception = undefined;
fake.exceptionCreator = undefined;
fake.fakeFn = undefined;
return fake;
},
resolvesThis: function resolvesThis(fake) {
fake.returnValue = undefined;
fake.resolve = false;
fake.resolveThis = true;
fake.reject = false;
fake.returnValueDefined = false;
fake.exception = undefined;
fake.exceptionCreator = undefined;
fake.fakeFn = undefined;
},
callThrough: function callThrough(fake) {
fake.callsThrough = true;
},
get: function get(fake, getterFunction) {
var rootStub = fake.stub || fake;
Object.defineProperty(rootStub.rootObj, rootStub.propName, {
get: getterFunction,
configurable: isPropertyConfigurable(rootStub.rootObj, rootStub.propName)
});
return fake;
},
set: function set(fake, setterFunction) {
var rootStub = fake.stub || fake;
Object.defineProperty(
rootStub.rootObj,
rootStub.propName,
// eslint-disable-next-line accessor-pairs
{
set: setterFunction,
configurable: isPropertyConfigurable(rootStub.rootObj, rootStub.propName)
}
);
return fake;
},
value: function value(fake, newVal) {
var rootStub = fake.stub || fake;
Object.defineProperty(rootStub.rootObj, rootStub.propName, {
value: newVal,
enumerable: true,
configurable: isPropertyConfigurable(rootStub.rootObj, rootStub.propName)
});
return fake;
}
};
var asyncBehaviors = exportAsyncBehaviors(defaultBehaviors);
module.exports = extend({}, defaultBehaviors, asyncBehaviors);

124
node_modules/sinon/lib/sinon/fake.js generated vendored Normal file
View File

@ -0,0 +1,124 @@
"use strict";
var arrayProto = require("@sinonjs/commons").prototypes.array;
var spy = require("./spy");
var nextTick = require("./util/core/next-tick");
var forEach = arrayProto.forEach;
var slice = arrayProto.slice;
function getError(value) {
return value instanceof Error ? value : new Error(value);
}
function cleanProxy(f) {
var undesirableProperties = [
"instantiateFake",
"callArg",
"callArgOn",
"callArgOnWith",
"callArgWith",
"invokeCallback",
"throwArg",
"withArgs",
"yield",
"yieldOn",
"yieldTo",
"yieldToOn"
];
forEach(undesirableProperties, function(key) {
delete f[key];
});
return f;
}
var uuid = 0;
function wrapFunc(f) {
var fakeInstance = function() {
var lastArg = arguments.length > 0 ? arguments[arguments.length - 1] : undefined;
var callback = lastArg && typeof lastArg === "function" ? lastArg : undefined;
/* eslint-disable no-use-before-define */
p.lastArg = lastArg;
p.callback = callback;
/* eslint-enable no-use-before-define */
return f && f.apply(this, arguments);
};
var p = cleanProxy(spy(fakeInstance));
p.displayName = "fake";
p.id = "fake#" + uuid++;
return p;
}
function fake(f) {
if (arguments.length > 0 && typeof f !== "function") {
throw new TypeError("Expected f argument to be a Function");
}
return wrapFunc(f);
}
fake.returns = function returns(value) {
function f() {
return value;
}
return wrapFunc(f);
};
fake.throws = function throws(value) {
function f() {
throw getError(value);
}
return wrapFunc(f);
};
fake.resolves = function resolves(value) {
function f() {
return Promise.resolve(value);
}
return wrapFunc(f);
};
fake.rejects = function rejects(value) {
function f() {
return Promise.reject(getError(value));
}
return wrapFunc(f);
};
function yieldInternal(async, values) {
function f() {
var callback = arguments[arguments.length - 1];
if (typeof callback !== "function") {
throw new TypeError("Expected last argument to be a function");
}
if (async) {
nextTick(function() {
callback.apply(null, values);
});
} else {
callback.apply(null, values);
}
}
return wrapFunc(f);
}
fake.yields = function yields() {
return yieldInternal(false, slice(arguments));
};
fake.yieldsAsync = function yieldsAsync() {
return yieldInternal(true, slice(arguments));
};
module.exports = fake;

316
node_modules/sinon/lib/sinon/mock-expectation.js generated vendored Normal file
View File

@ -0,0 +1,316 @@
"use strict";
var arrayProto = require("@sinonjs/commons").prototypes.array;
var spyInvoke = require("./spy").invoke;
var spyCallToString = require("./call").toString;
var timesInWords = require("./util/core/times-in-words");
var extend = require("./util/core/extend");
var match = require("@sinonjs/samsam").createMatcher;
var stub = require("./stub");
var assert = require("./assert");
var deepEqual = require("@sinonjs/samsam").deepEqual;
var format = require("./util/core/format");
var valueToString = require("@sinonjs/commons").valueToString;
var every = arrayProto.every;
var forEach = arrayProto.forEach;
var push = arrayProto.push;
var slice = arrayProto.slice;
function callCountInWords(callCount) {
if (callCount === 0) {
return "never called";
}
return "called " + timesInWords(callCount);
}
function expectedCallCountInWords(expectation) {
var min = expectation.minCalls;
var max = expectation.maxCalls;
if (typeof min === "number" && typeof max === "number") {
var str = timesInWords(min);
if (min !== max) {
str = "at least " + str + " and at most " + timesInWords(max);
}
return str;
}
if (typeof min === "number") {
return "at least " + timesInWords(min);
}
return "at most " + timesInWords(max);
}
function receivedMinCalls(expectation) {
var hasMinLimit = typeof expectation.minCalls === "number";
return !hasMinLimit || expectation.callCount >= expectation.minCalls;
}
function receivedMaxCalls(expectation) {
if (typeof expectation.maxCalls !== "number") {
return false;
}
return expectation.callCount === expectation.maxCalls;
}
function verifyMatcher(possibleMatcher, arg) {
var isMatcher = match.isMatcher(possibleMatcher);
return (isMatcher && possibleMatcher.test(arg)) || true;
}
var mockExpectation = {
minCalls: 1,
maxCalls: 1,
create: function create(methodName) {
var expectation = extend.nonEnum(stub.create(), mockExpectation);
delete expectation.create;
expectation.method = methodName;
return expectation;
},
invoke: function invoke(func, thisValue, args) {
this.verifyCallAllowed(thisValue, args);
return spyInvoke.apply(this, arguments);
},
atLeast: function atLeast(num) {
if (typeof num !== "number") {
throw new TypeError("'" + valueToString(num) + "' is not number");
}
if (!this.limitsSet) {
this.maxCalls = null;
this.limitsSet = true;
}
this.minCalls = num;
return this;
},
atMost: function atMost(num) {
if (typeof num !== "number") {
throw new TypeError("'" + valueToString(num) + "' is not number");
}
if (!this.limitsSet) {
this.minCalls = null;
this.limitsSet = true;
}
this.maxCalls = num;
return this;
},
never: function never() {
return this.exactly(0);
},
once: function once() {
return this.exactly(1);
},
twice: function twice() {
return this.exactly(2);
},
thrice: function thrice() {
return this.exactly(3);
},
exactly: function exactly(num) {
if (typeof num !== "number") {
throw new TypeError("'" + valueToString(num) + "' is not a number");
}
this.atLeast(num);
return this.atMost(num);
},
met: function met() {
return !this.failed && receivedMinCalls(this);
},
verifyCallAllowed: function verifyCallAllowed(thisValue, args) {
var expectedArguments = this.expectedArguments;
if (receivedMaxCalls(this)) {
this.failed = true;
mockExpectation.fail(this.method + " already called " + timesInWords(this.maxCalls));
}
if ("expectedThis" in this && this.expectedThis !== thisValue) {
mockExpectation.fail(
this.method +
" called with " +
valueToString(thisValue) +
" as thisValue, expected " +
valueToString(this.expectedThis)
);
}
if (!("expectedArguments" in this)) {
return;
}
if (!args) {
mockExpectation.fail(this.method + " received no arguments, expected " + format(expectedArguments));
}
if (args.length < expectedArguments.length) {
mockExpectation.fail(
this.method +
" received too few arguments (" +
format(args) +
"), expected " +
format(expectedArguments)
);
}
if (this.expectsExactArgCount && args.length !== expectedArguments.length) {
mockExpectation.fail(
this.method +
" received too many arguments (" +
format(args) +
"), expected " +
format(expectedArguments)
);
}
forEach(
expectedArguments,
function(expectedArgument, i) {
if (!verifyMatcher(expectedArgument, args[i])) {
mockExpectation.fail(
this.method +
" received wrong arguments " +
format(args) +
", didn't match " +
String(expectedArguments)
);
}
if (!deepEqual(args[i], expectedArgument)) {
mockExpectation.fail(
this.method +
" received wrong arguments " +
format(args) +
", expected " +
format(expectedArguments)
);
}
},
this
);
},
allowsCall: function allowsCall(thisValue, args) {
var expectedArguments = this.expectedArguments;
if (this.met() && receivedMaxCalls(this)) {
return false;
}
if ("expectedThis" in this && this.expectedThis !== thisValue) {
return false;
}
if (!("expectedArguments" in this)) {
return true;
}
// eslint-disable-next-line no-underscore-dangle
var _args = args || [];
if (_args.length < expectedArguments.length) {
return false;
}
if (this.expectsExactArgCount && _args.length !== expectedArguments.length) {
return false;
}
return every(expectedArguments, function(expectedArgument, i) {
if (!verifyMatcher(expectedArgument, _args[i])) {
return false;
}
if (!deepEqual(_args[i], expectedArgument)) {
return false;
}
return true;
});
},
withArgs: function withArgs() {
this.expectedArguments = slice(arguments);
return this;
},
withExactArgs: function withExactArgs() {
this.withArgs.apply(this, arguments);
this.expectsExactArgCount = true;
return this;
},
on: function on(thisValue) {
this.expectedThis = thisValue;
return this;
},
toString: function() {
var args = slice(this.expectedArguments || []);
if (!this.expectsExactArgCount) {
push(args, "[...]");
}
var callStr = spyCallToString.call({
proxy: this.method || "anonymous mock expectation",
args: args
});
var message = callStr.replace(", [...", "[, ...") + " " + expectedCallCountInWords(this);
if (this.met()) {
return "Expectation met: " + message;
}
return "Expected " + message + " (" + callCountInWords(this.callCount) + ")";
},
verify: function verify() {
if (!this.met()) {
mockExpectation.fail(String(this));
} else {
mockExpectation.pass(String(this));
}
return true;
},
pass: function pass(message) {
assert.pass(message);
},
fail: function fail(message) {
var exception = new Error(message);
exception.name = "ExpectationError";
throw exception;
}
};
module.exports = mockExpectation;

200
node_modules/sinon/lib/sinon/mock.js generated vendored Normal file
View File

@ -0,0 +1,200 @@
"use strict";
var arrayProto = require("@sinonjs/commons").prototypes.array;
var mockExpectation = require("./mock-expectation");
var spyCallToString = require("./call").toString;
var extend = require("./util/core/extend");
var deepEqual = require("@sinonjs/samsam").deepEqual;
var wrapMethod = require("./util/core/wrap-method");
var usePromiseLibrary = require("./util/core/use-promise-library");
var concat = arrayProto.concat;
var filter = arrayProto.filter;
var forEach = arrayProto.forEach;
var every = arrayProto.every;
var join = arrayProto.join;
var push = arrayProto.push;
var slice = arrayProto.slice;
var unshift = arrayProto.unshift;
function mock(object) {
if (!object || typeof object === "string") {
return mockExpectation.create(object ? object : "Anonymous mock");
}
return mock.create(object);
}
function each(collection, callback) {
var col = collection || [];
forEach(col, callback);
}
function arrayEquals(arr1, arr2, compareLength) {
if (compareLength && arr1.length !== arr2.length) {
return false;
}
return every(arr1, function(element, i) {
return deepEqual(arr2[i], element);
});
}
extend(mock, {
create: function create(object) {
if (!object) {
throw new TypeError("object is null");
}
var mockObject = extend.nonEnum({}, mock, { object: object });
delete mockObject.create;
return mockObject;
},
expects: function expects(method) {
if (!method) {
throw new TypeError("method is falsy");
}
if (!this.expectations) {
this.expectations = {};
this.proxies = [];
this.failures = [];
}
if (!this.expectations[method]) {
this.expectations[method] = [];
var mockObject = this;
wrapMethod(this.object, method, function() {
return mockObject.invokeMethod(method, this, arguments);
});
push(this.proxies, method);
}
var expectation = mockExpectation.create(method);
extend.nonEnum(expectation, this.object[method]);
push(this.expectations[method], expectation);
usePromiseLibrary(this.promiseLibrary, expectation);
return expectation;
},
restore: function restore() {
var object = this.object;
each(this.proxies, function(proxy) {
if (typeof object[proxy].restore === "function") {
object[proxy].restore();
}
});
},
verify: function verify() {
var expectations = this.expectations || {};
var messages = this.failures ? slice(this.failures) : [];
var met = [];
each(this.proxies, function(proxy) {
each(expectations[proxy], function(expectation) {
if (!expectation.met()) {
push(messages, String(expectation));
} else {
push(met, String(expectation));
}
});
});
this.restore();
if (messages.length > 0) {
mockExpectation.fail(join(concat(messages, met), "\n"));
} else if (met.length > 0) {
mockExpectation.pass(join(concat(messages, met), "\n"));
}
return true;
},
usingPromise: function usingPromise(promiseLibrary) {
this.promiseLibrary = promiseLibrary;
return this;
},
invokeMethod: function invokeMethod(method, thisValue, args) {
/* if we cannot find any matching files we will explicitly call mockExpection#fail with error messages */
/* eslint consistent-return: "off" */
var expectations = this.expectations && this.expectations[method] ? this.expectations[method] : [];
var currentArgs = args || [];
var available;
var expectationsWithMatchingArgs = filter(expectations, function(expectation) {
var expectedArgs = expectation.expectedArguments || [];
return arrayEquals(expectedArgs, currentArgs, expectation.expectsExactArgCount);
});
var expectationsToApply = filter(expectationsWithMatchingArgs, function(expectation) {
return !expectation.met() && expectation.allowsCall(thisValue, args);
});
if (expectationsToApply.length > 0) {
return expectationsToApply[0].apply(thisValue, args);
}
var messages = [];
var exhausted = 0;
forEach(expectationsWithMatchingArgs, function(expectation) {
if (expectation.allowsCall(thisValue, args)) {
available = available || expectation;
} else {
exhausted += 1;
}
});
if (available && exhausted === 0) {
return available.apply(thisValue, args);
}
forEach(expectations, function(expectation) {
push(messages, " " + String(expectation));
});
unshift(
messages,
"Unexpected call: " +
spyCallToString.call({
proxy: method,
args: args
})
);
var err = new Error();
if (!err.stack) {
// PhantomJS does not serialize the stack trace until the error has been thrown
try {
throw err;
} catch (e) {
/* empty */
}
}
push(
this.failures,
"Unexpected call: " +
spyCallToString.call({
proxy: method,
args: args,
stack: err.stack
})
);
mockExpectation.fail(join(messages, "\n"));
}
});
module.exports = mock;

391
node_modules/sinon/lib/sinon/sandbox.js generated vendored Normal file
View File

@ -0,0 +1,391 @@
"use strict";
var arrayProto = require("@sinonjs/commons").prototypes.array;
var collectOwnMethods = require("./collect-own-methods");
var getPropertyDescriptor = require("./util/core/get-property-descriptor");
var isEsModule = require("./util/core/is-es-module");
var isPropertyConfigurable = require("./util/core/is-property-configurable");
var isNonExistentOwnProperty = require("./util/core/is-non-existent-own-property");
var match = require("@sinonjs/samsam").createMatcher;
var sinonAssert = require("./assert");
var sinonClock = require("./util/fake-timers");
var sinonMock = require("./mock");
var sinonSpy = require("./spy");
var sinonStub = require("./stub");
var sinonFake = require("./fake");
var valueToString = require("@sinonjs/commons").valueToString;
var fakeServer = require("nise").fakeServer;
var fakeXhr = require("nise").fakeXhr;
var usePromiseLibrary = require("./util/core/use-promise-library");
var filter = arrayProto.filter;
var forEach = arrayProto.filter;
var push = arrayProto.push;
var reverse = arrayProto.reverse;
function applyOnEach(fakes, method) {
var matchingFakes = filter(fakes, function(fake) {
return typeof fake[method] === "function";
});
forEach(matchingFakes, function(fake) {
fake[method]();
});
}
function Sandbox() {
var sandbox = this;
var collection = [];
var fakeRestorers = [];
var promiseLib;
sandbox.serverPrototype = fakeServer;
// this is for testing only
sandbox.getFakes = function getFakes() {
return collection;
};
// this is for testing only
sandbox.getRestorers = function() {
return fakeRestorers;
};
sandbox.createStubInstance = function createStubInstance(constructor) {
if (typeof constructor !== "function") {
throw new TypeError("The constructor should be a function.");
}
return this.stub(Object.create(constructor.prototype));
};
sandbox.inject = function inject(obj) {
obj.spy = function() {
return sandbox.spy.apply(null, arguments);
};
obj.stub = function() {
return sandbox.stub.apply(null, arguments);
};
obj.mock = function() {
return sandbox.mock.apply(null, arguments);
};
if (sandbox.clock) {
obj.clock = sandbox.clock;
}
if (sandbox.server) {
obj.server = sandbox.server;
obj.requests = sandbox.server.requests;
}
obj.match = match;
return obj;
};
sandbox.mock = function mock() {
var m = sinonMock.apply(null, arguments);
push(collection, m);
usePromiseLibrary(promiseLib, m);
return m;
};
sandbox.reset = function reset() {
applyOnEach(collection, "reset");
applyOnEach(collection, "resetHistory");
};
sandbox.resetBehavior = function resetBehavior() {
applyOnEach(collection, "resetBehavior");
};
sandbox.resetHistory = function resetHistory() {
function privateResetHistory(f) {
var method = f.resetHistory || f.reset;
if (method) {
method.call(f);
}
}
forEach(collection, function(fake) {
if (typeof fake === "function") {
privateResetHistory(fake);
return;
}
var methods = [];
if (fake.get) {
push(methods, fake.get);
}
if (fake.set) {
push(methods, fake.set);
}
forEach(methods, privateResetHistory);
});
};
sandbox.restore = function restore() {
if (arguments.length) {
throw new Error("sandbox.restore() does not take any parameters. Perhaps you meant stub.restore()");
}
reverse(collection);
applyOnEach(collection, "restore");
collection = [];
forEach(fakeRestorers, function(restorer) {
restorer();
});
fakeRestorers = [];
sandbox.restoreContext();
};
sandbox.restoreContext = function restoreContext() {
var injectedKeys = sandbox.injectedKeys;
var injectInto = sandbox.injectInto;
if (!injectedKeys) {
return;
}
forEach(injectedKeys, function(injectedKey) {
delete injectInto[injectedKey];
});
injectedKeys = [];
};
function getFakeRestorer(object, property) {
var descriptor = getPropertyDescriptor(object, property);
function restorer() {
Object.defineProperty(object, property, descriptor);
}
restorer.object = object;
restorer.property = property;
return restorer;
}
function verifyNotReplaced(object, property) {
forEach(fakeRestorers, function(fakeRestorer) {
if (fakeRestorer.object === object && fakeRestorer.property === property) {
throw new TypeError("Attempted to replace " + property + " which is already replaced");
}
});
}
sandbox.replace = function replace(object, property, replacement) {
var descriptor = getPropertyDescriptor(object, property);
if (typeof descriptor === "undefined") {
throw new TypeError("Cannot replace non-existent own property " + valueToString(property));
}
if (typeof replacement === "undefined") {
throw new TypeError("Expected replacement argument to be defined");
}
if (typeof descriptor.get === "function") {
throw new Error("Use sandbox.replaceGetter for replacing getters");
}
if (typeof descriptor.set === "function") {
throw new Error("Use sandbox.replaceSetter for replacing setters");
}
if (typeof object[property] !== typeof replacement) {
throw new TypeError("Cannot replace " + typeof object[property] + " with " + typeof replacement);
}
verifyNotReplaced(object, property);
// store a function for restoring the replaced property
push(fakeRestorers, getFakeRestorer(object, property));
object[property] = replacement;
return replacement;
};
sandbox.replaceGetter = function replaceGetter(object, property, replacement) {
var descriptor = getPropertyDescriptor(object, property);
if (typeof descriptor === "undefined") {
throw new TypeError("Cannot replace non-existent own property " + valueToString(property));
}
if (typeof replacement !== "function") {
throw new TypeError("Expected replacement argument to be a function");
}
if (typeof descriptor.get !== "function") {
throw new Error("`object.property` is not a getter");
}
verifyNotReplaced(object, property);
// store a function for restoring the replaced property
push(fakeRestorers, getFakeRestorer(object, property));
Object.defineProperty(object, property, {
get: replacement,
configurable: isPropertyConfigurable(object, property)
});
return replacement;
};
sandbox.replaceSetter = function replaceSetter(object, property, replacement) {
var descriptor = getPropertyDescriptor(object, property);
if (typeof descriptor === "undefined") {
throw new TypeError("Cannot replace non-existent own property " + valueToString(property));
}
if (typeof replacement !== "function") {
throw new TypeError("Expected replacement argument to be a function");
}
if (typeof descriptor.set !== "function") {
throw new Error("`object.property` is not a setter");
}
verifyNotReplaced(object, property);
// store a function for restoring the replaced property
push(fakeRestorers, getFakeRestorer(object, property));
// eslint-disable-next-line accessor-pairs
Object.defineProperty(object, property, {
set: replacement,
configurable: isPropertyConfigurable(object, property)
});
return replacement;
};
sandbox.spy = function spy() {
var s = sinonSpy.apply(sinonSpy, arguments);
push(collection, s);
return s;
};
sandbox.stub = function stub(object, property) {
if (isEsModule(object)) {
throw new TypeError("ES Modules cannot be stubbed");
}
if (isNonExistentOwnProperty(object, property)) {
throw new TypeError("Cannot stub non-existent own property " + valueToString(property));
}
var stubbed = sinonStub.apply(null, arguments);
var isStubbingEntireObject = typeof property === "undefined" && typeof object === "object";
if (isStubbingEntireObject) {
var ownMethods = collectOwnMethods(stubbed);
forEach(ownMethods, function(method) {
push(collection, method);
});
usePromiseLibrary(promiseLib, ownMethods);
} else {
push(collection, stubbed);
usePromiseLibrary(promiseLib, stubbed);
}
return stubbed;
};
// eslint-disable-next-line no-unused-vars
sandbox.fake = function fake(f) {
var s = sinonFake.apply(sinonFake, arguments);
push(collection, s);
return s;
};
forEach(Object.keys(sinonFake), function(key) {
var fakeBehavior = sinonFake[key];
if (typeof fakeBehavior === "function") {
sandbox.fake[key] = function() {
var s = fakeBehavior.apply(fakeBehavior, arguments);
push(collection, s);
return s;
};
}
});
sandbox.useFakeTimers = function useFakeTimers(args) {
var clock = sinonClock.useFakeTimers.call(null, args);
sandbox.clock = clock;
push(collection, clock);
return clock;
};
sandbox.verify = function verify() {
applyOnEach(collection, "verify");
};
sandbox.verifyAndRestore = function verifyAndRestore() {
var exception;
try {
sandbox.verify();
} catch (e) {
exception = e;
}
sandbox.restore();
if (exception) {
throw exception;
}
};
sandbox.useFakeServer = function useFakeServer() {
var proto = sandbox.serverPrototype || fakeServer;
if (!proto || !proto.create) {
return null;
}
sandbox.server = proto.create();
push(collection, sandbox.server);
return sandbox.server;
};
sandbox.useFakeXMLHttpRequest = function useFakeXMLHttpRequest() {
var xhr = fakeXhr.useFakeXMLHttpRequest();
push(collection, xhr);
return xhr;
};
sandbox.usingPromise = function usingPromise(promiseLibrary) {
promiseLib = promiseLibrary;
collection.promiseLibrary = promiseLibrary;
return sandbox;
};
}
Sandbox.prototype.assert = sinonAssert;
Sandbox.prototype.match = match;
module.exports = Sandbox;

109
node_modules/sinon/lib/sinon/spy-formatters.js generated vendored Normal file
View File

@ -0,0 +1,109 @@
"use strict";
var arrayProto = require("@sinonjs/commons").prototypes.array;
var color = require("./color");
var match = require("@sinonjs/samsam").createMatcher;
var timesInWords = require("./util/core/times-in-words");
var sinonFormat = require("./util/core/format");
var jsDiff = require("diff");
var join = arrayProto.join;
var map = arrayProto.map;
var push = arrayProto.push;
function colorSinonMatchText(matcher, calledArg, calledArgMessage) {
var calledArgumentMessage = calledArgMessage;
if (!matcher.test(calledArg)) {
matcher.message = color.red(matcher.message);
if (calledArgumentMessage) {
calledArgumentMessage = color.green(calledArgumentMessage);
}
}
return calledArgumentMessage + " " + matcher.message;
}
function colorDiffText(diff) {
var objects = map(diff, function(part) {
var text = part.value;
if (part.added) {
text = color.green(text);
} else if (part.removed) {
text = color.red(text);
}
if (diff.length === 2) {
text += " "; // format simple diffs
}
return text;
});
return join(objects, "");
}
module.exports = {
c: function(spyInstance) {
return timesInWords(spyInstance.callCount);
},
n: function(spyInstance) {
// eslint-disable-next-line local-rules/no-prototype-methods
return spyInstance.toString();
},
D: function(spyInstance, args) {
var message = "";
for (var i = 0, l = spyInstance.callCount; i < l; ++i) {
// describe multiple calls
if (l > 1) {
message += "\nCall " + (i + 1) + ":";
}
var calledArgs = spyInstance.getCall(i).args;
for (var j = 0; j < calledArgs.length || j < args.length; ++j) {
message += "\n";
var calledArgMessage = j < calledArgs.length ? sinonFormat(calledArgs[j]) : "";
if (match.isMatcher(args[j])) {
message += colorSinonMatchText(args[j], calledArgs[j], calledArgMessage);
} else {
var expectedArgMessage = j < args.length ? sinonFormat(args[j]) : "";
var diff = jsDiff.diffJson(calledArgMessage, expectedArgMessage);
message += colorDiffText(diff);
}
}
}
return message;
},
C: function(spyInstance) {
var calls = [];
for (var i = 0, l = spyInstance.callCount; i < l; ++i) {
// eslint-disable-next-line local-rules/no-prototype-methods
var stringifiedCall = " " + spyInstance.getCall(i).toString();
if (/\n/.test(calls[i - 1])) {
stringifiedCall = "\n" + stringifiedCall;
}
push(calls, stringifiedCall);
}
return calls.length > 0 ? "\n" + join(calls, "\n") : "";
},
t: function(spyInstance) {
var objects = [];
for (var i = 0, l = spyInstance.callCount; i < l; ++i) {
push(objects, sinonFormat(spyInstance.thisValues[i]));
}
return join(objects, ", ");
},
"*": function(spyInstance, args) {
return join(
map(args, function(arg) {
return sinonFormat(arg);
}),
", "
);
}
};

588
node_modules/sinon/lib/sinon/spy.js generated vendored Normal file
View File

@ -0,0 +1,588 @@
"use strict";
var arrayProto = require("@sinonjs/commons").prototypes.array;
var createBehavior = require("./behavior").create;
var extend = require("./util/core/extend");
var functionName = require("@sinonjs/commons").functionName;
var functionToString = require("./util/core/function-to-string");
var getPropertyDescriptor = require("./util/core/get-property-descriptor");
var deepEqual = require("@sinonjs/samsam").deepEqual;
var isEsModule = require("./util/core/is-es-module");
var spyCall = require("./call");
var wrapMethod = require("./util/core/wrap-method");
var sinonFormat = require("./util/core/format");
var valueToString = require("@sinonjs/commons").valueToString;
/* cache references to library methods so that they also can be stubbed without problems */
var concat = arrayProto.concat;
var forEach = arrayProto.forEach;
var pop = arrayProto.pop;
var push = arrayProto.push;
var slice = arrayProto.slice;
var filter = Array.prototype.filter;
var ErrorConstructor = Error.prototype.constructor;
var bind = Function.prototype.bind;
var callId = 0;
function spy(object, property, types) {
var descriptor, methodDesc;
if (isEsModule(object)) {
throw new TypeError("ES Modules cannot be spied");
}
if (!property && typeof object === "function") {
return spy.create(object);
}
if (!object && !property) {
return spy.create(function() {
return;
});
}
if (!types) {
return wrapMethod(object, property, spy.create(object[property]));
}
descriptor = {};
methodDesc = getPropertyDescriptor(object, property);
forEach(types, function(type) {
descriptor[type] = spy.create(methodDesc[type]);
});
return wrapMethod(object, property, descriptor);
}
function incrementCallCount() {
this.called = true;
this.callCount += 1;
this.notCalled = false;
this.calledOnce = this.callCount === 1;
this.calledTwice = this.callCount === 2;
this.calledThrice = this.callCount === 3;
}
function createCallProperties() {
this.firstCall = this.getCall(0);
this.secondCall = this.getCall(1);
this.thirdCall = this.getCall(2);
this.lastCall = this.getCall(this.callCount - 1);
}
function createProxy(func, proxyLength) {
// Retain the function length:
var p;
if (proxyLength) {
// Do not change this to use an eval. Projects that depend on sinon block the use of eval.
// ref: https://github.com/sinonjs/sinon/issues/710
switch (proxyLength) {
/*eslint-disable no-unused-vars, max-len*/
case 1:
p = function proxy(a) {
return p.invoke(func, this, slice(arguments));
};
break;
case 2:
p = function proxy(a, b) {
return p.invoke(func, this, slice(arguments));
};
break;
case 3:
p = function proxy(a, b, c) {
return p.invoke(func, this, slice(arguments));
};
break;
case 4:
p = function proxy(a, b, c, d) {
return p.invoke(func, this, slice(arguments));
};
break;
case 5:
p = function proxy(a, b, c, d, e) {
return p.invoke(func, this, slice(arguments));
};
break;
case 6:
p = function proxy(a, b, c, d, e, f) {
return p.invoke(func, this, slice(arguments));
};
break;
case 7:
p = function proxy(a, b, c, d, e, f, g) {
return p.invoke(func, this, slice(arguments));
};
break;
case 8:
p = function proxy(a, b, c, d, e, f, g, h) {
return p.invoke(func, this, slice(arguments));
};
break;
case 9:
p = function proxy(a, b, c, d, e, f, g, h, i) {
return p.invoke(func, this, slice(arguments));
};
break;
case 10:
p = function proxy(a, b, c, d, e, f, g, h, i, j) {
return p.invoke(func, this, slice(arguments));
};
break;
case 11:
p = function proxy(a, b, c, d, e, f, g, h, i, j, k) {
return p.invoke(func, this, slice(arguments));
};
break;
case 12:
p = function proxy(a, b, c, d, e, f, g, h, i, j, k, l) {
return p.invoke(func, this, slice(arguments));
};
break;
default:
p = function proxy() {
return p.invoke(func, this, slice(arguments));
};
break;
/*eslint-enable*/
}
} else {
p = function proxy() {
return p.invoke(func, this, slice(arguments));
};
}
var nameDescriptor = Object.getOwnPropertyDescriptor(func, "name");
if (nameDescriptor && nameDescriptor.configurable) {
// IE 11 functions don't have a name.
// Safari 9 has names that are not configurable.
Object.defineProperty(p, "name", nameDescriptor);
}
extend.nonEnum(p, {
isSinonProxy: true,
called: false,
notCalled: true,
calledOnce: false,
calledTwice: false,
calledThrice: false,
callCount: 0,
firstCall: null,
secondCall: null,
thirdCall: null,
lastCall: null,
args: [],
returnValues: [],
thisValues: [],
exceptions: [],
callIds: [],
errorsWithCallStack: []
});
return p;
}
var uuid = 0;
// Public API
var spyApi = {
formatters: require("./spy-formatters"),
resetHistory: function() {
if (this.invoking) {
var err = new Error(
"Cannot reset Sinon function while invoking it. " +
"Move the call to .resetHistory outside of the callback."
);
err.name = "InvalidResetException";
throw err;
}
this.called = false;
this.notCalled = true;
this.calledOnce = false;
this.calledTwice = false;
this.calledThrice = false;
this.callCount = 0;
this.firstCall = null;
this.secondCall = null;
this.thirdCall = null;
this.lastCall = null;
this.args = [];
this.returnValues = [];
this.thisValues = [];
this.exceptions = [];
this.callIds = [];
this.errorsWithCallStack = [];
if (this.fakes) {
forEach(this.fakes, function(fake) {
if (fake.resetHistory) {
fake.resetHistory();
} else {
fake.reset();
}
});
}
return this;
},
create: function create(func, spyLength) {
var name;
var funk = func;
if (typeof funk !== "function") {
funk = function() {
return;
};
} else {
name = functionName(funk);
}
var length = spyLength || funk.length;
var proxy = createProxy(funk, length);
extend.nonEnum(proxy, spy);
delete proxy.create;
extend(proxy, funk);
proxy.resetHistory();
proxy.prototype = funk.prototype;
extend.nonEnum(proxy, {
displayName: name || "spy",
toString: functionToString,
instantiateFake: spy.create,
id: "spy#" + uuid++
});
return proxy;
},
invoke: function invoke(func, thisValue, args) {
var matchings = this.matchingFakes(args);
var currentCallId = callId++;
var exception, returnValue;
incrementCallCount.call(this);
push(this.thisValues, thisValue);
push(this.args, args);
push(this.callIds, currentCallId);
forEach(matchings, function(matching) {
incrementCallCount.call(matching);
push(matching.thisValues, thisValue);
push(matching.args, args);
push(matching.callIds, currentCallId);
});
// Make call properties available from within the spied function:
createCallProperties.call(this);
forEach(matchings, function(matching) {
createCallProperties.call(matching);
});
try {
this.invoking = true;
var thisCall = this.getCall(this.callCount - 1);
if (thisCall.calledWithNew()) {
// Call through with `new`
returnValue = new (bind.apply(this.func || func, concat([thisValue], args)))();
if (typeof returnValue !== "object") {
returnValue = thisValue;
}
} else {
returnValue = (this.func || func).apply(thisValue, args);
}
} catch (e) {
exception = e;
} finally {
delete this.invoking;
}
push(this.exceptions, exception);
push(this.returnValues, returnValue);
forEach(matchings, function(matching) {
push(matching.exceptions, exception);
push(matching.returnValues, returnValue);
});
var err = new ErrorConstructor();
// 1. Please do not get stack at this point. It may be so very slow, and not actually used
// 2. PhantomJS does not serialize the stack trace until the error has been thrown:
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/Stack
try {
throw err;
} catch (e) {
/* empty */
}
push(this.errorsWithCallStack, err);
forEach(matchings, function(matching) {
push(matching.errorsWithCallStack, err);
});
// Make return value and exception available in the calls:
createCallProperties.call(this);
forEach(matchings, function(matching) {
createCallProperties.call(matching);
});
if (exception !== undefined) {
throw exception;
}
return returnValue;
},
named: function named(name) {
this.displayName = name;
var nameDescriptor = Object.getOwnPropertyDescriptor(this, "name");
if (nameDescriptor && nameDescriptor.configurable) {
// IE 11 functions don't have a name.
// Safari 9 has names that are not configurable.
nameDescriptor.value = name;
Object.defineProperty(this, "name", nameDescriptor);
}
return this;
},
getCall: function getCall(i) {
if (i < 0 || i >= this.callCount) {
return null;
}
return spyCall(
this,
this.thisValues[i],
this.args[i],
this.returnValues[i],
this.exceptions[i],
this.callIds[i],
this.errorsWithCallStack[i]
);
},
getCalls: function() {
var calls = [];
var i;
for (i = 0; i < this.callCount; i++) {
push(calls, this.getCall(i));
}
return calls;
},
calledBefore: function calledBefore(spyFn) {
if (!this.called) {
return false;
}
if (!spyFn.called) {
return true;
}
return this.callIds[0] < spyFn.callIds[spyFn.callIds.length - 1];
},
calledAfter: function calledAfter(spyFn) {
if (!this.called || !spyFn.called) {
return false;
}
return this.callIds[this.callCount - 1] > spyFn.callIds[0];
},
calledImmediatelyBefore: function calledImmediatelyBefore(spyFn) {
if (!this.called || !spyFn.called) {
return false;
}
return this.callIds[this.callCount - 1] === spyFn.callIds[spyFn.callCount - 1] - 1;
},
calledImmediatelyAfter: function calledImmediatelyAfter(spyFn) {
if (!this.called || !spyFn.called) {
return false;
}
return this.callIds[this.callCount - 1] === spyFn.callIds[spyFn.callCount - 1] + 1;
},
withArgs: function() {
var args = slice(arguments);
if (this.fakes) {
var matching = pop(this.matchingFakes(args, true));
if (matching) {
return matching;
}
} else {
extend.nonEnum(this, { fakes: [] });
}
var original = this;
var fake = this.instantiateFake();
fake.matchingArguments = args;
fake.parent = this;
push(this.fakes, fake);
if (original.defaultBehavior && original.defaultBehavior.promiseLibrary) {
fake.defaultBehavior = fake.defaultBehavior || createBehavior(fake);
fake.defaultBehavior.promiseLibrary = original.defaultBehavior.promiseLibrary;
}
fake.withArgs = function() {
return original.withArgs.apply(original, arguments);
};
forEach(original.args, function(arg, i) {
if (!fake.matches(arg)) {
return;
}
incrementCallCount.call(fake);
push(fake.thisValues, original.thisValues[i]);
push(fake.args, arg);
push(fake.returnValues, original.returnValues[i]);
push(fake.exceptions, original.exceptions[i]);
push(fake.callIds, original.callIds[i]);
});
createCallProperties.call(fake);
return fake;
},
matchingFakes: function(args, strict) {
return filter.call(this.fakes || [], function(fake) {
return fake.matches(args, strict);
});
},
matches: function(args, strict) {
var margs = this.matchingArguments;
if (margs.length <= args.length && deepEqual(slice(args, 0, margs.length), margs)) {
return !strict || margs.length === args.length;
}
return undefined;
},
printf: function(format) {
var spyInstance = this;
var args = slice(arguments, 1);
var formatter;
return (format || "").replace(/%(.)/g, function(match, specifyer) {
formatter = spyApi.formatters[specifyer];
if (typeof formatter === "function") {
return String(formatter(spyInstance, args));
} else if (!isNaN(parseInt(specifyer, 10))) {
return sinonFormat(args[specifyer - 1]);
}
return "%" + specifyer;
});
}
};
function delegateToCalls(method, matchAny, actual, returnsValues, notCalled, totalCallCount) {
spyApi[method] = function() {
if (!this.called) {
if (notCalled) {
return notCalled.apply(this, arguments);
}
return false;
}
if (totalCallCount !== undefined && this.callCount !== totalCallCount) {
return false;
}
var currentCall;
var matches = 0;
var returnValues = [];
for (var i = 0, l = this.callCount; i < l; i += 1) {
currentCall = this.getCall(i);
var returnValue = currentCall[actual || method].apply(currentCall, arguments);
push(returnValues, returnValue);
if (returnValue) {
matches += 1;
if (matchAny) {
return true;
}
}
}
if (returnsValues) {
return returnValues;
}
return matches === this.callCount;
};
}
delegateToCalls("calledOn", true);
delegateToCalls("alwaysCalledOn", false, "calledOn");
delegateToCalls("calledWith", true);
delegateToCalls("calledOnceWith", true, "calledWith", false, undefined, 1);
delegateToCalls("calledWithMatch", true);
delegateToCalls("alwaysCalledWith", false, "calledWith");
delegateToCalls("alwaysCalledWithMatch", false, "calledWithMatch");
delegateToCalls("calledWithExactly", true);
delegateToCalls("calledOnceWithExactly", true, "calledWithExactly", false, undefined, 1);
delegateToCalls("alwaysCalledWithExactly", false, "calledWithExactly");
delegateToCalls("neverCalledWith", false, "notCalledWith", false, function() {
return true;
});
delegateToCalls("neverCalledWithMatch", false, "notCalledWithMatch", false, function() {
return true;
});
delegateToCalls("threw", true);
delegateToCalls("alwaysThrew", false, "threw");
delegateToCalls("returned", true);
delegateToCalls("alwaysReturned", false, "returned");
delegateToCalls("calledWithNew", true);
delegateToCalls("alwaysCalledWithNew", false, "calledWithNew");
/* eslint-disable local-rules/no-prototype-methods */
delegateToCalls("callArg", false, "callArgWith", true, function() {
throw new Error(this.toString() + " cannot call arg since it was not yet invoked.");
});
spyApi.callArgWith = spyApi.callArg;
delegateToCalls("callArgOn", false, "callArgOnWith", true, function() {
throw new Error(this.toString() + " cannot call arg since it was not yet invoked.");
});
spyApi.callArgOnWith = spyApi.callArgOn;
delegateToCalls("throwArg", false, "throwArg", false, function() {
throw new Error(this.toString() + " cannot throw arg since it was not yet invoked.");
});
delegateToCalls("yield", false, "yield", true, function() {
throw new Error(this.toString() + " cannot yield since it was not yet invoked.");
});
// "invokeCallback" is an alias for "yield" since "yield" is invalid in strict mode.
spyApi.invokeCallback = spyApi.yield;
delegateToCalls("yieldOn", false, "yieldOn", true, function() {
throw new Error(this.toString() + " cannot yield since it was not yet invoked.");
});
delegateToCalls("yieldTo", false, "yieldTo", true, function(property) {
throw new Error(
this.toString() + " cannot yield to '" + valueToString(property) + "' since it was not yet invoked."
);
});
delegateToCalls("yieldToOn", false, "yieldToOn", true, function(property) {
throw new Error(
this.toString() + " cannot yield to '" + valueToString(property) + "' since it was not yet invoked."
);
});
/* eslint-enable local-rules/no-prototype-methods */
extend(spy, spyApi);
spy.spyCall = spyCall;
module.exports = spy;

22
node_modules/sinon/lib/sinon/stub-entire-object.js generated vendored Normal file
View File

@ -0,0 +1,22 @@
"use strict";
var getPropertyDescriptor = require("./util/core/get-property-descriptor");
var walk = require("./util/core/walk");
function stubEntireObject(stub, object) {
walk(object || {}, function(prop, propOwner) {
// we don't want to stub things like toString(), valueOf(), etc. so we only stub if the object
// is not Object.prototype
if (
propOwner !== Object.prototype &&
prop !== "constructor" &&
typeof getPropertyDescriptor(propOwner, prop).value === "function"
) {
stub(object, prop);
}
});
return object;
}
module.exports = stubEntireObject;

View File

@ -0,0 +1,20 @@
"use strict";
var valueToString = require("@sinonjs/commons").valueToString;
var hasOwnProperty = Object.prototype.hasOwnProperty;
function stubNonFunctionProperty(object, property) {
var original = object[property];
if (!hasOwnProperty.call(object, property)) {
throw new TypeError("Cannot stub non-existent own property " + valueToString(property));
}
return {
restore: function restore() {
object[property] = original;
}
};
}
module.exports = stubNonFunctionProperty;

221
node_modules/sinon/lib/sinon/stub.js generated vendored Normal file
View File

@ -0,0 +1,221 @@
"use strict";
var arrayProto = require("@sinonjs/commons").prototypes.array;
var behavior = require("./behavior");
var behaviors = require("./default-behaviors");
var hasOwnProperty = require("@sinonjs/commons").prototypes.object.hasOwnProperty;
var isNonExistentOwnProperty = require("./util/core/is-non-existent-own-property");
var spy = require("./spy");
var extend = require("./util/core/extend");
var functionToString = require("./util/core/function-to-string");
var getPropertyDescriptor = require("./util/core/get-property-descriptor");
var isEsModule = require("./util/core/is-es-module");
var wrapMethod = require("./util/core/wrap-method");
var stubEntireObject = require("./stub-entire-object");
var throwOnFalsyObject = require("./throw-on-falsy-object");
var valueToString = require("@sinonjs/commons").valueToString;
var forEach = arrayProto.forEach;
var pop = arrayProto.pop;
var slice = arrayProto.slice;
var sort = arrayProto.sort;
function stub(object, property) {
if (arguments.length > 2) {
throw new TypeError("stub(obj, 'meth', fn) has been removed, see documentation");
}
if (isEsModule(object)) {
throw new TypeError("ES Modules cannot be stubbed");
}
throwOnFalsyObject.apply(null, arguments);
if (isNonExistentOwnProperty(object, property)) {
throw new TypeError("Cannot stub non-existent own property " + valueToString(property));
}
var actualDescriptor = getPropertyDescriptor(object, property);
var isObject = typeof object === "object" || typeof object === "function";
var isStubbingEntireObject = typeof property === "undefined" && isObject;
var isCreatingNewStub = !object && typeof property === "undefined";
var isStubbingNonFuncProperty =
isObject &&
typeof property !== "undefined" &&
(typeof actualDescriptor === "undefined" || typeof actualDescriptor.value !== "function") &&
typeof descriptor === "undefined";
var isStubbingExistingMethod =
typeof object === "object" &&
typeof actualDescriptor !== "undefined" &&
typeof actualDescriptor.value === "function";
var arity = isStubbingExistingMethod ? object[property].length : 0;
if (isStubbingEntireObject) {
return stubEntireObject(stub, object);
}
if (isCreatingNewStub) {
return stub.create();
}
var s = stub.create(arity);
extend.nonEnum(s, {
rootObj: object,
propName: property,
restore: function restore() {
if (actualDescriptor !== undefined) {
Object.defineProperty(object, property, actualDescriptor);
return;
}
delete object[property];
}
});
return isStubbingNonFuncProperty ? s : wrapMethod(object, property, s);
}
stub.createStubInstance = function(constructor, overrides) {
if (typeof constructor !== "function") {
throw new TypeError("The constructor should be a function.");
}
var stubbedObject = stub(Object.create(constructor.prototype));
forEach(Object.keys(overrides || {}), function(propertyName) {
if (propertyName in stubbedObject) {
var value = overrides[propertyName];
if (value && value.createStubInstance) {
stubbedObject[propertyName] = value;
} else {
stubbedObject[propertyName].returns(value);
}
} else {
throw new Error("Cannot stub " + propertyName + ". Property does not exist!");
}
});
return stubbedObject;
};
/*eslint-disable no-use-before-define*/
function getParentBehaviour(stubInstance) {
return stubInstance.parent && getCurrentBehavior(stubInstance.parent);
}
function getDefaultBehavior(stubInstance) {
return stubInstance.defaultBehavior || getParentBehaviour(stubInstance) || behavior.create(stubInstance);
}
function getCurrentBehavior(stubInstance) {
var currentBehavior = stubInstance.behaviors[stubInstance.callCount - 1];
return currentBehavior && currentBehavior.isPresent() ? currentBehavior : getDefaultBehavior(stubInstance);
}
/*eslint-enable no-use-before-define*/
var uuid = 0;
var proto = {
create: function create(stubLength) {
var functionStub = function() {
var args = slice(arguments);
var matchings = functionStub.matchingFakes(args);
var fnStub =
pop(
sort(matchings, function(a, b) {
return a.matchingArguments.length - b.matchingArguments.length;
})
) || functionStub;
return getCurrentBehavior(fnStub).invoke(this, arguments);
};
var orig = functionStub;
functionStub = spy.create(functionStub, stubLength);
extend.nonEnum(functionStub, {
id: "stub#" + uuid++,
func: orig
});
extend(functionStub, stub);
extend.nonEnum(functionStub, {
instantiateFake: stub.create,
displayName: "stub",
toString: functionToString,
defaultBehavior: null,
behaviors: []
});
return functionStub;
},
resetBehavior: function() {
var fakes = this.fakes || [];
this.defaultBehavior = null;
this.behaviors = [];
delete this.returnValue;
delete this.returnArgAt;
delete this.throwArgAt;
delete this.resolveArgAt;
delete this.fakeFn;
this.returnThis = false;
this.resolveThis = false;
forEach(fakes, function(fake) {
fake.resetBehavior();
});
},
resetHistory: spy.resetHistory,
reset: function() {
this.resetHistory();
this.resetBehavior();
},
onCall: function onCall(index) {
if (!this.behaviors[index]) {
this.behaviors[index] = behavior.create(this);
}
return this.behaviors[index];
},
onFirstCall: function onFirstCall() {
return this.onCall(0);
},
onSecondCall: function onSecondCall() {
return this.onCall(1);
},
onThirdCall: function onThirdCall() {
return this.onCall(2);
}
};
forEach(Object.keys(behavior), function(method) {
if (
hasOwnProperty(behavior, method) &&
!hasOwnProperty(proto, method) &&
method !== "create" &&
method !== "withArgs" &&
method !== "invoke"
) {
proto[method] = behavior.createBehavior(method);
}
});
forEach(Object.keys(behaviors), function(method) {
if (hasOwnProperty(behaviors, method) && !hasOwnProperty(proto, method)) {
behavior.addBehavior(stub, method, behaviors[method]);
}
});
extend(stub, proto);
module.exports = stub;

11
node_modules/sinon/lib/sinon/throw-on-falsy-object.js generated vendored Normal file
View File

@ -0,0 +1,11 @@
"use strict";
var valueToString = require("@sinonjs/commons").valueToString;
function throwOnFalsyObject(object, property) {
if (property && !object) {
var type = object === null ? "null" : "undefined";
throw new Error("Trying to stub property '" + valueToString(property) + "' of " + type);
}
}
module.exports = throwOnFalsyObject;

View File

@ -0,0 +1,9 @@
"use strict";
module.exports = {
injectIntoThis: true,
injectInto: null,
properties: ["spy", "stub", "mock", "clock", "server", "requests"],
useFakeTimers: true,
useFakeServer: true
};

34
node_modules/sinon/lib/sinon/util/core/deprecated.js generated vendored Normal file
View File

@ -0,0 +1,34 @@
/* eslint-disable no-console */
"use strict";
// wrap returns a function that will invoke the supplied function and print a deprecation warning to the console each
// time it is called.
exports.wrap = function(func, msg) {
var wrapped = function() {
exports.printWarning(msg);
return func.apply(this, arguments);
};
if (func.prototype) {
wrapped.prototype = func.prototype;
}
return wrapped;
};
// defaultMsg returns a string which can be supplied to `wrap()` to notify the user that a particular part of the
// sinon API has been deprecated.
/* istanbul ignore next */
exports.defaultMsg = function(funcName) {
return "sinon." + funcName + " is deprecated and will be removed from the public API in a future version of sinon.";
};
exports.printWarning = function(msg) {
// Watch out for IE7 and below! :(
if (typeof console !== "undefined") {
/* istanbul ignore else */
if (console.info) {
console.info(msg);
} else {
console.log(msg);
}
}
};

View File

@ -0,0 +1,22 @@
"use strict";
var arrayProto = require("@sinonjs/commons").prototypes.array;
var reduce = arrayProto.reduce;
module.exports = function exportAsyncBehaviors(behaviorMethods) {
return reduce(
Object.keys(behaviorMethods),
function(acc, method) {
// need to avoid creating another async versions of the newly added async methods
if (method.match(/^(callsArg|yields)/) && !method.match(/Async/)) {
acc[method + "Async"] = function() {
var result = behaviorMethods[method].apply(this, arguments);
this.callbackAsync = true;
return result;
};
}
return acc;
},
{}
);
};

111
node_modules/sinon/lib/sinon/util/core/extend.js generated vendored Normal file
View File

@ -0,0 +1,111 @@
"use strict";
var arrayProto = require("@sinonjs/commons").prototypes.array;
var hasOwnProperty = require("@sinonjs/commons").prototypes.object.hasOwnProperty;
var join = arrayProto.join;
var push = arrayProto.push;
var slice = arrayProto.slice;
// Adapted from https://developer.mozilla.org/en/docs/ECMAScript_DontEnum_attribute#JScript_DontEnum_Bug
var hasDontEnumBug = (function() {
var obj = {
constructor: function() {
return "0";
},
toString: function() {
return "1";
},
valueOf: function() {
return "2";
},
toLocaleString: function() {
return "3";
},
prototype: function() {
return "4";
},
isPrototypeOf: function() {
return "5";
},
propertyIsEnumerable: function() {
return "6";
},
hasOwnProperty: function() {
return "7";
},
length: function() {
return "8";
},
unique: function() {
return "9";
}
};
var result = [];
for (var prop in obj) {
if (hasOwnProperty(obj, prop)) {
push(result, obj[prop]());
}
}
return join(result, "") !== "0123456789";
})();
function extendCommon(target, sources, doCopy) {
var source, i, prop;
for (i = 0; i < sources.length; i++) {
source = sources[i];
for (prop in source) {
if (hasOwnProperty(source, prop)) {
doCopy(target, source, prop);
}
}
// Make sure we copy (own) toString method even when in JScript with DontEnum bug
// See https://developer.mozilla.org/en/docs/ECMAScript_DontEnum_attribute#JScript_DontEnum_Bug
if (hasDontEnumBug && hasOwnProperty(source, "toString") && source.toString !== target.toString) {
target.toString = source.toString;
}
}
return target;
}
/** Public: Extend target in place with all (own) properties from sources in-order. Thus, last source will
* override properties in previous sources.
*
* @arg {Object} target - The Object to extend
* @arg {Object[]} sources - Objects to copy properties from.
*
* @returns {Object} the extended target
*/
module.exports = function extend(target /*, sources */) {
var sources = slice(arguments, 1);
return extendCommon(target, sources, function copyValue(dest, source, prop) {
dest[prop] = source[prop];
});
};
/** Public: Extend target in place with all (own) properties from sources in-order. Thus, last source will
* override properties in previous sources. Define the properties as non enumerable.
*
* @arg {Object} target - The Object to extend
* @arg {Object[]} sources - Objects to copy properties from.
*
* @returns {Object} the extended target
*/
module.exports.nonEnum = function extendNonEnum(target /*, sources */) {
var sources = slice(arguments, 1);
return extendCommon(target, sources, function copyProperty(dest, source, prop) {
Object.defineProperty(dest, prop, {
value: source[prop],
enumerable: false,
configurable: true,
writable: true
});
});
};

28
node_modules/sinon/lib/sinon/util/core/format.js generated vendored Normal file
View File

@ -0,0 +1,28 @@
"use strict";
var formatio = require("@sinonjs/formatio");
var formatter = formatio.configure({
quoteStrings: false,
limitChildrenCount: 250
});
var customFormatter;
function format() {
if (customFormatter) {
return customFormatter.apply(null, arguments);
}
return formatter.ascii.apply(formatter, arguments);
}
format.setFormatter = function(aCustomFormatter) {
if (typeof aCustomFormatter !== "function") {
throw new Error("format.setFormatter must be called with a function");
}
customFormatter = aCustomFormatter;
};
module.exports = format;

View File

@ -0,0 +1,20 @@
"use strict";
module.exports = function toString() {
var i, prop, thisValue;
if (this.getCall && this.callCount) {
i = this.callCount;
while (i--) {
thisValue = this.getCall(i).thisValue;
for (prop in thisValue) {
if (thisValue[prop] === this) {
return prop;
}
}
}
}
return this.displayName || "sinon fake";
};

18
node_modules/sinon/lib/sinon/util/core/get-config.js generated vendored Normal file
View File

@ -0,0 +1,18 @@
"use strict";
var defaultConfig = require("./default-config");
var hasOwnProperty = require("@sinonjs/commons").prototypes.object.hasOwnProperty;
module.exports = function getConfig(custom) {
var config = {};
var prop;
var kustom = custom || {};
for (prop in defaultConfig) {
if (hasOwnProperty(defaultConfig, prop)) {
config[prop] = hasOwnProperty(kustom, prop) ? kustom[prop] : defaultConfig[prop];
}
}
return config;
};

View File

@ -0,0 +1,18 @@
"use strict";
/* istanbul ignore next : not testing that setTimeout works */
function nextTick(callback) {
setTimeout(callback, 0);
}
module.exports = function getNextTick(process, setImmediate) {
if (typeof process === "object" && typeof process.nextTick === "function") {
return process.nextTick;
}
if (typeof setImmediate === "function") {
return setImmediate;
}
return nextTick;
};

View File

@ -0,0 +1,11 @@
"use strict";
module.exports = function getPropertyDescriptor(object, property) {
var proto = object;
var descriptor;
while (proto && !(descriptor = Object.getOwnPropertyDescriptor(proto, property))) {
proto = Object.getPrototypeOf(proto);
}
return descriptor;
};

18
node_modules/sinon/lib/sinon/util/core/is-es-module.js generated vendored Normal file
View File

@ -0,0 +1,18 @@
"use strict";
/**
* Verify if an object is a ECMAScript Module
*
* As the exports from a module is immutable we cannot alter the exports
* using spies or stubs. Let the consumer know this to avoid bug reports
* on weird error messages.
*
* @param {Object} object The object to examine
*
* @returns {Boolean} true when the object is a module
*/
module.exports = function(object) {
return (
object && typeof Symbol !== "undefined" && object[Symbol.toStringTag] === "Module" && Object.isSealed(object)
);
};

View File

@ -0,0 +1,7 @@
"use strict";
function isNonExistentOwnProperty(object, property) {
return object && typeof property !== "undefined" && !(property in object);
}
module.exports = isNonExistentOwnProperty;

View File

@ -0,0 +1,11 @@
"use strict";
var getPropertyDescriptor = require("./get-property-descriptor");
function isPropertyConfigurable(obj, propName) {
var propertyDescriptor = getPropertyDescriptor(obj, propName);
return propertyDescriptor ? propertyDescriptor.configurable : true;
}
module.exports = isPropertyConfigurable;

View File

@ -0,0 +1,7 @@
"use strict";
function isRestorable(obj) {
return typeof obj === "function" && typeof obj.restore === "function" && obj.restore.sinon;
}
module.exports = isRestorable;

8
node_modules/sinon/lib/sinon/util/core/next-tick.js generated vendored Normal file
View File

@ -0,0 +1,8 @@
"use strict";
var getNextTick = require("./get-next-tick");
/* istanbul ignore next */
var root = typeof window !== "undefined" ? window : global;
module.exports = getNextTick(root.process, root.setImmediate);

16
node_modules/sinon/lib/sinon/util/core/restore.js generated vendored Normal file
View File

@ -0,0 +1,16 @@
"use strict";
var isRestorable = require("./is-restorable");
var walk = require("./walk");
module.exports = function restore(object) {
if (object !== null && typeof object === "object") {
walk(object, function(prop) {
if (isRestorable(object[prop])) {
object[prop].restore();
}
});
} else if (isRestorable(object)) {
object.restore();
}
};

View File

@ -0,0 +1,7 @@
"use strict";
var array = [null, "once", "twice", "thrice"];
module.exports = function timesInWords(count) {
return array[count] || (count || 0) + " times";
};

View File

@ -0,0 +1,21 @@
"use strict";
var forEach = Array.prototype.forEach;
function usePromiseLibrary(library, fakes) {
if (typeof library === "undefined") {
return;
}
if (Array.isArray(fakes)) {
forEach.call(fakes, usePromiseLibrary.bind(null, library));
return;
}
if (typeof fakes.usingPromise === "function") {
fakes.usingPromise(library);
}
}
module.exports = usePromiseLibrary;

45
node_modules/sinon/lib/sinon/util/core/walk.js generated vendored Normal file
View File

@ -0,0 +1,45 @@
"use strict";
var forEach = require("@sinonjs/commons").prototypes.array.forEach;
function walkInternal(obj, iterator, context, originalObj, seen) {
var proto, prop;
if (typeof Object.getOwnPropertyNames !== "function") {
// We explicitly want to enumerate through all of the prototype's properties
// in this case, therefore we deliberately leave out an own property check.
/* eslint-disable-next-line guard-for-in */
for (prop in obj) {
iterator.call(context, obj[prop], prop, obj);
}
return;
}
forEach(Object.getOwnPropertyNames(obj), function(k) {
if (seen[k] !== true) {
seen[k] = true;
var target = typeof Object.getOwnPropertyDescriptor(obj, k).get === "function" ? originalObj : obj;
iterator.call(context, k, target);
}
});
proto = Object.getPrototypeOf(obj);
if (proto) {
walkInternal(proto, iterator, context, originalObj, seen);
}
}
/* Walks the prototype chain of an object and iterates over every own property
* name encountered. The iterator is called in the same fashion that Array.prototype.forEach
* works, where it is passed the value, key, and own object as the 1st, 2nd, and 3rd positional
* argument, respectively. In cases where Object.getOwnPropertyNames is not available, walk will
* default to using a simple for..in loop.
*
* obj - The object to walk the prototype chain for.
* iterator - The function to be called on each pass of the walk.
* context - (Optional) When given, the iterator will be called with this object as the receiver.
*/
module.exports = function walk(obj, iterator, context) {
return walkInternal(obj, iterator, context, obj, {});
};

155
node_modules/sinon/lib/sinon/util/core/wrap-method.js generated vendored Normal file
View File

@ -0,0 +1,155 @@
"use strict";
var getPropertyDescriptor = require("./get-property-descriptor");
var extend = require("./extend");
var hasOwnProperty = require("@sinonjs/commons").prototypes.object.hasOwnProperty;
var valueToString = require("@sinonjs/commons").valueToString;
function isFunction(obj) {
return typeof obj === "function" || Boolean(obj && obj.constructor && obj.call && obj.apply);
}
function mirrorProperties(target, source) {
for (var prop in source) {
if (!hasOwnProperty(target, prop)) {
target[prop] = source[prop];
}
}
}
// Cheap way to detect if we have ES5 support.
var hasES5Support = "keys" in Object;
module.exports = function wrapMethod(object, property, method) {
if (!object) {
throw new TypeError("Should wrap property of object");
}
if (typeof method !== "function" && typeof method !== "object") {
throw new TypeError("Method wrapper should be a function or a property descriptor");
}
function checkWrappedMethod(wrappedMethod) {
var error;
if (!isFunction(wrappedMethod)) {
error = new TypeError(
"Attempted to wrap " + typeof wrappedMethod + " property " + valueToString(property) + " as function"
);
} else if (wrappedMethod.restore && wrappedMethod.restore.sinon) {
error = new TypeError("Attempted to wrap " + valueToString(property) + " which is already wrapped");
} else if (wrappedMethod.calledBefore) {
var verb = wrappedMethod.returns ? "stubbed" : "spied on";
error = new TypeError("Attempted to wrap " + valueToString(property) + " which is already " + verb);
}
if (error) {
if (wrappedMethod && wrappedMethod.stackTraceError) {
error.stack += "\n--------------\n" + wrappedMethod.stackTraceError.stack;
}
throw error;
}
}
var error, wrappedMethod, i, wrappedMethodDesc;
function simplePropertyAssignment() {
wrappedMethod = object[property];
checkWrappedMethod(wrappedMethod);
object[property] = method;
method.displayName = property;
}
// Firefox has a problem when using hasOwn.call on objects from other frames.
/* eslint-disable-next-line local-rules/no-prototype-methods */
var owned = object.hasOwnProperty ? object.hasOwnProperty(property) : hasOwnProperty(object, property);
if (hasES5Support) {
var methodDesc = typeof method === "function" ? { value: method } : method;
wrappedMethodDesc = getPropertyDescriptor(object, property);
if (!wrappedMethodDesc) {
error = new TypeError(
"Attempted to wrap " + typeof wrappedMethod + " property " + property + " as function"
);
} else if (wrappedMethodDesc.restore && wrappedMethodDesc.restore.sinon) {
error = new TypeError("Attempted to wrap " + property + " which is already wrapped");
}
if (error) {
if (wrappedMethodDesc && wrappedMethodDesc.stackTraceError) {
error.stack += "\n--------------\n" + wrappedMethodDesc.stackTraceError.stack;
}
throw error;
}
var types = Object.keys(methodDesc);
for (i = 0; i < types.length; i++) {
wrappedMethod = wrappedMethodDesc[types[i]];
checkWrappedMethod(wrappedMethod);
}
mirrorProperties(methodDesc, wrappedMethodDesc);
for (i = 0; i < types.length; i++) {
mirrorProperties(methodDesc[types[i]], wrappedMethodDesc[types[i]]);
}
Object.defineProperty(object, property, methodDesc);
// catch failing assignment
// this is the converse of the check in `.restore` below
if (typeof method === "function" && object[property] !== method) {
// correct any wrongdoings caused by the defineProperty call above,
// such as adding new items (if object was a Storage object)
delete object[property];
simplePropertyAssignment();
}
} else {
simplePropertyAssignment();
}
extend.nonEnum(method, {
displayName: property,
// Set up an Error object for a stack trace which can be used later to find what line of
// code the original method was created on.
stackTraceError: new Error("Stack Trace for original"),
restore: function() {
// For prototype properties try to reset by delete first.
// If this fails (ex: localStorage on mobile safari) then force a reset
// via direct assignment.
if (!owned) {
// In some cases `delete` may throw an error
try {
delete object[property];
} catch (e) {} // eslint-disable-line no-empty
// For native code functions `delete` fails without throwing an error
// on Chrome < 43, PhantomJS, etc.
} else if (hasES5Support) {
Object.defineProperty(object, property, wrappedMethodDesc);
}
if (hasES5Support) {
var descriptor = getPropertyDescriptor(object, property);
if (descriptor && descriptor.value === method) {
object[property] = wrappedMethod;
}
} else {
// Use strict equality comparison to check failures then force a reset
// via direct assignment.
if (object[property] === method) {
object[property] = wrappedMethod;
}
}
}
});
method.wrappedMethod = wrappedMethod;
method.restore.sinon = true;
if (!hasES5Support) {
mirrorProperties(method, wrappedMethod);
}
return method;
};

62
node_modules/sinon/lib/sinon/util/fake-timers.js generated vendored Normal file
View File

@ -0,0 +1,62 @@
"use strict";
var extend = require("./core/extend");
var llx = require("lolex");
function createClock(config, globalCtx) {
var llxCtx = llx;
if (globalCtx !== null && typeof globalCtx === "object") {
llxCtx = llx.withGlobal(globalCtx);
}
var clock = llxCtx.install(config);
clock.restore = clock.uninstall;
return clock;
}
/**
* @param {number|Date|Object} dateOrConfig The unix epoch value to install with (default 0)
* @returns {Object} Returns a lolex clock instance
*/
exports.useFakeTimers = function(dateOrConfig) {
var hasArguments = typeof dateOrConfig !== "undefined";
var argumentIsDateLike =
(typeof dateOrConfig === "number" || dateOrConfig instanceof Date) && arguments.length === 1;
var argumentIsObject = dateOrConfig !== null && typeof dateOrConfig === "object" && arguments.length === 1;
if (!hasArguments) {
return createClock({
now: 0
});
}
if (argumentIsDateLike) {
return createClock({
now: dateOrConfig
});
}
if (argumentIsObject) {
var config = extend.nonEnum({}, dateOrConfig);
var globalCtx = config.global;
delete config.global;
return createClock(config, globalCtx);
}
throw new TypeError("useFakeTimers expected epoch or config object. See https://github.com/sinonjs/sinon");
};
exports.clock = {
create: function(now) {
return llx.createClock(now);
}
};
exports.timers = {
setTimeout: setTimeout,
clearTimeout: clearTimeout,
setImmediate: typeof setImmediate !== "undefined" ? setImmediate : undefined,
clearImmediate: typeof clearImmediate !== "undefined" ? clearImmediate : undefined,
setInterval: setInterval,
clearInterval: clearInterval,
Date: Date
};