infusion
Version:
Infusion is an application framework for developing flexible stuff with JavaScript
1,670 lines (1,343 loc) • 2.38 MB
JavaScript
/* Sinon.JS 7.2.2, 2018-12-12, @license BSD-3 */(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.sinon = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
"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;
},{"./sinon/assert":2,"./sinon/behavior":3,"./sinon/call":4,"./sinon/create-sandbox":7,"./sinon/mock-expectation":10,"./sinon/sandbox":12,"./sinon/stub":16,"./sinon/util/core/default-config":18,"./sinon/util/core/deprecated":19,"./sinon/util/core/extend":21,"./sinon/util/core/format":22,"./sinon/util/fake-timers":34,"@sinonjs/samsam":64,"nise":81}],2:[function(require,module,exports){
(function (global){
"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;
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{"./util/core/format":22,"./util/core/times-in-words":30,"@sinonjs/commons":38,"@sinonjs/samsam":64}],3:[function(require,module,exports){
"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({}, proto, asyncBehaviors);
},{"./util/core/export-async-behaviors":20,"./util/core/extend":21,"./util/core/next-tick":29,"@sinonjs/commons":38}],4:[function(require,module,exports){
"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;
},{"./util/core/format":22,"@sinonjs/commons":38,"@sinonjs/samsam":64}],5:[function(require,module,exports){
"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;
},{"./util/core/get-property-descriptor":25,"./util/core/walk":32,"@sinonjs/commons":38}],6:[function(require,module,exports){
"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);
};
},{"supports-color":84}],7:[function(require,module,exports){
"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;
},{"./sandbox":12,"@sinonjs/commons":38}],8:[function(require,module,exports){
"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);
},{"./util/core/export-async-behaviors":20,"./util/core/extend":21,"./util/core/is-property-configurable":28,"@sinonjs/commons":38}],9:[function(require,module,exports){
"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;
},{"./spy":14,"./util/core/next-tick":29,"@sinonjs/commons":38}],10:[function(require,module,exports){
"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(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;
},{"./assert":2,"./call":4,"./spy":14,"./stub":16,"./util/core/extend":21,"./util/core/format":22,"./util/core/times-in-words":30,"@sinonjs/commons":38,"@sinonjs/samsam":64}],11:[function(require,module,exports){
"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({}, mock);
mockObject.object = object;
delete mockObject.create;
return mockObject;
},
expects: function expects(method) {
if (!method) {
throw new TypeError("method is falsy");
}
if (!this.expectations) {
this.expectations = {};
thi