Update checked-in dependencies
This commit is contained in:
parent
3ba511a8f1
commit
1c4c64199f
175 changed files with 13227 additions and 15136 deletions
BIN
node_modules/sinon/lib/.DS_Store
generated
vendored
Normal file
BIN
node_modules/sinon/lib/.DS_Store
generated
vendored
Normal file
Binary file not shown.
12
node_modules/sinon/lib/sinon.js
generated
vendored
12
node_modules/sinon/lib/sinon.js
generated
vendored
|
|
@ -8,6 +8,7 @@ var format = require("./sinon/util/core/format");
|
|||
var nise = require("nise");
|
||||
var Sandbox = require("./sinon/sandbox");
|
||||
var stub = require("./sinon/stub");
|
||||
var promise = require("./sinon/promise");
|
||||
|
||||
var apiMethods = {
|
||||
createSandbox: createSandbox,
|
||||
|
|
@ -31,11 +32,16 @@ var apiMethods = {
|
|||
fakeServer: nise.fakeServer,
|
||||
fakeServerWithClock: nise.fakeServerWithClock,
|
||||
createFakeServer: nise.fakeServer.create.bind(nise.fakeServer),
|
||||
createFakeServerWithClock: nise.fakeServerWithClock.create.bind(nise.fakeServerWithClock),
|
||||
createFakeServerWithClock: nise.fakeServerWithClock.create.bind(
|
||||
nise.fakeServerWithClock
|
||||
),
|
||||
|
||||
addBehavior: function(name, fn) {
|
||||
addBehavior: function (name, fn) {
|
||||
behavior.addBehavior(stub, name, fn);
|
||||
}
|
||||
},
|
||||
|
||||
// fake promise
|
||||
promise: promise,
|
||||
};
|
||||
|
||||
var sandbox = new Sandbox();
|
||||
|
|
|
|||
451
node_modules/sinon/lib/sinon/assert.js
generated
vendored
451
node_modules/sinon/lib/sinon/assert.js
generated
vendored
|
|
@ -15,202 +15,281 @@ var forEach = arrayProto.forEach;
|
|||
var join = arrayProto.join;
|
||||
var splice = arrayProto.splice;
|
||||
|
||||
var assert;
|
||||
function createAssertObject() {
|
||||
var assert;
|
||||
|
||||
function verifyIsStub() {
|
||||
var args = arraySlice(arguments);
|
||||
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");
|
||||
forEach(args, function (method) {
|
||||
if (!method) {
|
||||
assert.fail("fake is not a spy");
|
||||
}
|
||||
|
||||
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 || globalObject;
|
||||
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);
|
||||
}
|
||||
if (method.proxy && method.proxy.isSinonProxy) {
|
||||
verifyIsStub(method.proxy);
|
||||
} else {
|
||||
if (typeof method !== "function") {
|
||||
assert.fail(`${method} is not a function`);
|
||||
}
|
||||
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];
|
||||
if (typeof method.getCall !== "function") {
|
||||
assert.fail(`${method} is not stubbed`);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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"));
|
||||
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;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
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("calledOnceWithExactly", "expected %n to be called once and 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");
|
||||
function failAssertion(object, msg) {
|
||||
var obj = object || globalObject;
|
||||
var failMethod = obj.fail || assert.fail;
|
||||
failMethod.call(obj, msg);
|
||||
}
|
||||
|
||||
module.exports = assert;
|
||||
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(
|
||||
"calledOnceWithExactly",
|
||||
"expected %n to be called once and with exact arguments %D"
|
||||
);
|
||||
mirrorPropAsAssertion(
|
||||
"calledOnceWithMatch",
|
||||
"expected %n to be called once and with match %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");
|
||||
|
||||
return assert;
|
||||
}
|
||||
|
||||
module.exports = createAssertObject();
|
||||
module.exports.createAssertObject = createAssertObject;
|
||||
|
|
|
|||
60
node_modules/sinon/lib/sinon/behavior.js
generated
vendored
60
node_modules/sinon/lib/sinon/behavior.js
generated
vendored
|
|
@ -39,7 +39,11 @@ function getCallback(behavior, args) {
|
|||
return argumentList[i];
|
||||
}
|
||||
|
||||
if (callArgProp && argumentList[i] && typeof argumentList[i][callArgProp] === "function") {
|
||||
if (
|
||||
callArgProp &&
|
||||
argumentList[i] &&
|
||||
typeof argumentList[i][callArgProp] === "function"
|
||||
) {
|
||||
return argumentList[i][callArgProp];
|
||||
}
|
||||
}
|
||||
|
|
@ -52,23 +56,25 @@ function getCallbackError(behavior, func, args) {
|
|||
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.";
|
||||
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.";
|
||||
msg = `${functionName(
|
||||
behavior.stub
|
||||
)} expected to yield, but no callback was passed.`;
|
||||
}
|
||||
|
||||
if (args.length > 0) {
|
||||
msg += " Received [" + join(args, ", ") + "]";
|
||||
msg += ` Received [${join(args, ", ")}]`;
|
||||
}
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
return "argument at index " + behavior.callArgAt + " is not a function: " + func;
|
||||
return `argument at index ${behavior.callArgAt} is not a function: ${func}`;
|
||||
}
|
||||
|
||||
function ensureArgs(name, behavior, args) {
|
||||
|
|
@ -79,7 +85,9 @@ function ensureArgs(name, behavior, args) {
|
|||
|
||||
if (index >= args.length) {
|
||||
throw new TypeError(
|
||||
name + " failed: " + (index + 1) + " arguments required but only " + args.length + " present"
|
||||
`${name} failed: ${index + 1} arguments required but only ${
|
||||
args.length
|
||||
} present`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -94,11 +102,17 @@ function callCallback(behavior, args) {
|
|||
}
|
||||
|
||||
if (behavior.callbackAsync) {
|
||||
nextTick(function() {
|
||||
func.apply(behavior.callbackContext, behavior.callbackArguments);
|
||||
nextTick(function () {
|
||||
func.apply(
|
||||
behavior.callbackContext,
|
||||
behavior.callbackArguments
|
||||
);
|
||||
});
|
||||
} else {
|
||||
return func.apply(behavior.callbackContext, behavior.callbackArguments);
|
||||
return func.apply(
|
||||
behavior.callbackContext,
|
||||
behavior.callbackArguments
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -163,7 +177,9 @@ var proto = {
|
|||
return this.fakeFn.apply(context, args);
|
||||
} else if (typeof this.resolveArgAt === "number") {
|
||||
ensureArgs("resolvesArg", this, args);
|
||||
return (this.promiseLibrary || Promise).resolve(args[this.resolveArgAt]);
|
||||
return (this.promiseLibrary || Promise).resolve(
|
||||
args[this.resolveArgAt]
|
||||
);
|
||||
} else if (this.resolveThis) {
|
||||
return (this.promiseLibrary || Promise).resolve(context);
|
||||
} else if (this.resolve) {
|
||||
|
|
@ -180,7 +196,10 @@ var proto = {
|
|||
// Turn the arguments object into a normal array
|
||||
var argsArray = slice(args);
|
||||
// Call the constructor
|
||||
var F = WrappedClass.bind.apply(WrappedClass, concat([null], argsArray));
|
||||
var F = WrappedClass.bind.apply(
|
||||
WrappedClass,
|
||||
concat([null], argsArray)
|
||||
);
|
||||
return new F();
|
||||
} else if (typeof this.returnValue !== "undefined") {
|
||||
return this.returnValue;
|
||||
|
|
@ -222,19 +241,22 @@ var proto = {
|
|||
'is not supported. Use "stub.withArgs(...).onCall(...)" ' +
|
||||
"to define sequential behavior for calls with certain arguments."
|
||||
);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
function createBehavior(behaviorMethod) {
|
||||
return function() {
|
||||
return function () {
|
||||
this.defaultBehavior = this.defaultBehavior || proto.create(this);
|
||||
this.defaultBehavior[behaviorMethod].apply(this.defaultBehavior, arguments);
|
||||
this.defaultBehavior[behaviorMethod].apply(
|
||||
this.defaultBehavior,
|
||||
arguments
|
||||
);
|
||||
return this;
|
||||
};
|
||||
}
|
||||
|
||||
function addBehavior(stub, name, fn) {
|
||||
proto[name] = function() {
|
||||
proto[name] = function () {
|
||||
fn.apply(this, concat([this], slice(arguments)));
|
||||
return this.stub || this;
|
||||
};
|
||||
|
|
|
|||
2
node_modules/sinon/lib/sinon/blob.js
generated
vendored
2
node_modules/sinon/lib/sinon/blob.js
generated
vendored
|
|
@ -1,6 +1,6 @@
|
|||
"use strict";
|
||||
|
||||
exports.isSupported = (function() {
|
||||
exports.isSupported = (function () {
|
||||
try {
|
||||
return Boolean(new Blob());
|
||||
} catch (e) {
|
||||
|
|
|
|||
8
node_modules/sinon/lib/sinon/collect-own-methods.js
generated
vendored
8
node_modules/sinon/lib/sinon/collect-own-methods.js
generated
vendored
|
|
@ -2,11 +2,15 @@
|
|||
|
||||
var walk = require("./util/core/walk");
|
||||
var getPropertyDescriptor = require("./util/core/get-property-descriptor");
|
||||
var hasOwnProperty = require("@sinonjs/commons").prototypes.object.hasOwnProperty;
|
||||
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)) {
|
||||
if (
|
||||
typeof getPropertyDescriptor(propOwner, prop).value === "function" &&
|
||||
hasOwnProperty(object, prop)
|
||||
) {
|
||||
push(methods, object[prop]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
12
node_modules/sinon/lib/sinon/color.js
generated
vendored
12
node_modules/sinon/lib/sinon/color.js
generated
vendored
|
|
@ -7,25 +7,25 @@ function colorize(str, color) {
|
|||
return str;
|
||||
}
|
||||
|
||||
return "\x1b[" + color + "m" + str + "\x1b[0m";
|
||||
return `\x1b[${color}m${str}\x1b[0m`;
|
||||
}
|
||||
|
||||
exports.red = function(str) {
|
||||
exports.red = function (str) {
|
||||
return colorize(str, 31);
|
||||
};
|
||||
|
||||
exports.green = function(str) {
|
||||
exports.green = function (str) {
|
||||
return colorize(str, 32);
|
||||
};
|
||||
|
||||
exports.cyan = function(str) {
|
||||
exports.cyan = function (str) {
|
||||
return colorize(str, 96);
|
||||
};
|
||||
|
||||
exports.white = function(str) {
|
||||
exports.white = function (str) {
|
||||
return colorize(str, 39);
|
||||
};
|
||||
|
||||
exports.bold = function(str) {
|
||||
exports.bold = function (str) {
|
||||
return colorize(str, 1);
|
||||
};
|
||||
|
|
|
|||
5
node_modules/sinon/lib/sinon/create-sandbox.js
generated
vendored
5
node_modules/sinon/lib/sinon/create-sandbox.js
generated
vendored
|
|
@ -53,8 +53,9 @@ function createSandbox(config) {
|
|||
var exposed = configuredSandbox.inject({});
|
||||
|
||||
if (config.properties) {
|
||||
forEach(config.properties, function(prop) {
|
||||
var value = exposed[prop] || (prop === "sandbox" && configuredSandbox);
|
||||
forEach(config.properties, function (prop) {
|
||||
var value =
|
||||
exposed[prop] || (prop === "sandbox" && configuredSandbox);
|
||||
exposeValue(configuredSandbox, config, prop, value);
|
||||
});
|
||||
} else {
|
||||
|
|
|
|||
35
node_modules/sinon/lib/sinon/default-behaviors.js
generated
vendored
35
node_modules/sinon/lib/sinon/default-behaviors.js
generated
vendored
|
|
@ -14,13 +14,13 @@ function throwsException(fake, error, message) {
|
|||
if (typeof error === "function") {
|
||||
fake.exceptionCreator = error;
|
||||
} else if (typeof error === "string") {
|
||||
fake.exceptionCreator = function() {
|
||||
fake.exceptionCreator = function () {
|
||||
var newException = new Error(message || "");
|
||||
newException.name = error;
|
||||
return newException;
|
||||
};
|
||||
} else if (!error) {
|
||||
fake.exceptionCreator = function() {
|
||||
fake.exceptionCreator = function () {
|
||||
return new Error("Error");
|
||||
};
|
||||
} else {
|
||||
|
|
@ -85,44 +85,49 @@ var defaultBehaviors = {
|
|||
fake.promiseLibrary = promiseLibrary;
|
||||
},
|
||||
|
||||
yields: function(fake) {
|
||||
yields: function (fake) {
|
||||
fake.callArgAt = useLeftMostCallback;
|
||||
fake.callbackArguments = slice(arguments, 1);
|
||||
fake.callbackContext = undefined;
|
||||
fake.callArgProp = undefined;
|
||||
fake.callbackAsync = false;
|
||||
fake.fakeFn = undefined;
|
||||
},
|
||||
|
||||
yieldsRight: function(fake) {
|
||||
yieldsRight: function (fake) {
|
||||
fake.callArgAt = useRightMostCallback;
|
||||
fake.callbackArguments = slice(arguments, 1);
|
||||
fake.callbackContext = undefined;
|
||||
fake.callArgProp = undefined;
|
||||
fake.callbackAsync = false;
|
||||
fake.fakeFn = undefined;
|
||||
},
|
||||
|
||||
yieldsOn: function(fake, context) {
|
||||
yieldsOn: function (fake, context) {
|
||||
fake.callArgAt = useLeftMostCallback;
|
||||
fake.callbackArguments = slice(arguments, 2);
|
||||
fake.callbackContext = context;
|
||||
fake.callArgProp = undefined;
|
||||
fake.callbackAsync = false;
|
||||
fake.fakeFn = undefined;
|
||||
},
|
||||
|
||||
yieldsTo: function(fake, prop) {
|
||||
yieldsTo: function (fake, prop) {
|
||||
fake.callArgAt = useLeftMostCallback;
|
||||
fake.callbackArguments = slice(arguments, 2);
|
||||
fake.callbackContext = undefined;
|
||||
fake.callArgProp = prop;
|
||||
fake.callbackAsync = false;
|
||||
fake.fakeFn = undefined;
|
||||
},
|
||||
|
||||
yieldsToOn: function(fake, prop, context) {
|
||||
yieldsToOn: function (fake, prop, context) {
|
||||
fake.callArgAt = useLeftMostCallback;
|
||||
fake.callbackArguments = slice(arguments, 3);
|
||||
fake.callbackContext = context;
|
||||
fake.callArgProp = prop;
|
||||
fake.callbackAsync = false;
|
||||
fake.fakeFn = undefined;
|
||||
},
|
||||
|
||||
throws: throwsException,
|
||||
|
|
@ -230,7 +235,10 @@ var defaultBehaviors = {
|
|||
|
||||
Object.defineProperty(rootStub.rootObj, rootStub.propName, {
|
||||
get: getterFunction,
|
||||
configurable: isPropertyConfigurable(rootStub.rootObj, rootStub.propName)
|
||||
configurable: isPropertyConfigurable(
|
||||
rootStub.rootObj,
|
||||
rootStub.propName
|
||||
),
|
||||
});
|
||||
|
||||
return fake;
|
||||
|
|
@ -245,7 +253,10 @@ var defaultBehaviors = {
|
|||
// eslint-disable-next-line accessor-pairs
|
||||
{
|
||||
set: setterFunction,
|
||||
configurable: isPropertyConfigurable(rootStub.rootObj, rootStub.propName)
|
||||
configurable: isPropertyConfigurable(
|
||||
rootStub.rootObj,
|
||||
rootStub.propName
|
||||
),
|
||||
}
|
||||
);
|
||||
|
||||
|
|
@ -258,11 +269,13 @@ var defaultBehaviors = {
|
|||
Object.defineProperty(rootStub.rootObj, rootStub.propName, {
|
||||
value: newVal,
|
||||
enumerable: true,
|
||||
configurable: rootStub.shadowsPropOnPrototype || isPropertyConfigurable(rootStub.rootObj, rootStub.propName)
|
||||
configurable:
|
||||
rootStub.shadowsPropOnPrototype ||
|
||||
isPropertyConfigurable(rootStub.rootObj, rootStub.propName),
|
||||
});
|
||||
|
||||
return fake;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
var asyncBehaviors = exportAsyncBehaviors(defaultBehaviors);
|
||||
|
|
|
|||
323
node_modules/sinon/lib/sinon/fake.js
generated
vendored
323
node_modules/sinon/lib/sinon/fake.js
generated
vendored
|
|
@ -5,15 +5,251 @@ var createProxy = require("./proxy");
|
|||
var nextTick = require("./util/core/next-tick");
|
||||
|
||||
var slice = arrayProto.slice;
|
||||
var promiseLib = Promise;
|
||||
|
||||
function getError(value) {
|
||||
return value instanceof Error ? value : new Error(value);
|
||||
module.exports = fake;
|
||||
|
||||
/**
|
||||
* Returns a `fake` that records all calls, arguments and return values.
|
||||
*
|
||||
* When an `f` argument is supplied, this implementation will be used.
|
||||
*
|
||||
* @example
|
||||
* // create an empty fake
|
||||
* var f1 = sinon.fake();
|
||||
*
|
||||
* f1();
|
||||
*
|
||||
* f1.calledOnce()
|
||||
* // true
|
||||
*
|
||||
* @example
|
||||
* function greet(greeting) {
|
||||
* console.log(`Hello ${greeting}`);
|
||||
* }
|
||||
*
|
||||
* // create a fake with implementation
|
||||
* var f2 = sinon.fake(greet);
|
||||
*
|
||||
* // Hello world
|
||||
* f2("world");
|
||||
*
|
||||
* f2.calledWith("world");
|
||||
* // true
|
||||
*
|
||||
* @param {Function|undefined} f
|
||||
* @returns {Function}
|
||||
* @namespace
|
||||
*/
|
||||
function fake(f) {
|
||||
if (arguments.length > 0 && typeof f !== "function") {
|
||||
throw new TypeError("Expected f argument to be a Function");
|
||||
}
|
||||
|
||||
return wrapFunc(f);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a `fake` that returns the provided `value`, as well as recording all
|
||||
* calls, arguments and return values.
|
||||
*
|
||||
* @example
|
||||
* var f1 = sinon.fake.returns(42);
|
||||
*
|
||||
* f1();
|
||||
* // 42
|
||||
*
|
||||
* @memberof fake
|
||||
* @param {*} value
|
||||
* @returns {Function}
|
||||
*/
|
||||
fake.returns = function returns(value) {
|
||||
// eslint-disable-next-line jsdoc/require-jsdoc
|
||||
function f() {
|
||||
return value;
|
||||
}
|
||||
|
||||
return wrapFunc(f);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a `fake` that throws an Error.
|
||||
* If the `value` argument does not have Error in its prototype chain, it will
|
||||
* be used for creating a new error.
|
||||
*
|
||||
* @example
|
||||
* var f1 = sinon.fake.throws("hello");
|
||||
*
|
||||
* f1();
|
||||
* // Uncaught Error: hello
|
||||
*
|
||||
* @example
|
||||
* var f2 = sinon.fake.throws(new TypeError("Invalid argument"));
|
||||
*
|
||||
* f2();
|
||||
* // Uncaught TypeError: Invalid argument
|
||||
*
|
||||
* @memberof fake
|
||||
* @param {*|Error} value
|
||||
* @returns {Function}
|
||||
*/
|
||||
fake.throws = function throws(value) {
|
||||
// eslint-disable-next-line jsdoc/require-jsdoc
|
||||
function f() {
|
||||
throw getError(value);
|
||||
}
|
||||
|
||||
return wrapFunc(f);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a `fake` that returns a promise that resolves to the passed `value`
|
||||
* argument.
|
||||
*
|
||||
* @example
|
||||
* var f1 = sinon.fake.resolves("apple pie");
|
||||
*
|
||||
* await f1();
|
||||
* // "apple pie"
|
||||
*
|
||||
* @memberof fake
|
||||
* @param {*} value
|
||||
* @returns {Function}
|
||||
*/
|
||||
fake.resolves = function resolves(value) {
|
||||
// eslint-disable-next-line jsdoc/require-jsdoc
|
||||
function f() {
|
||||
return promiseLib.resolve(value);
|
||||
}
|
||||
|
||||
return wrapFunc(f);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a `fake` that returns a promise that rejects to the passed `value`
|
||||
* argument. When `value` does not have Error in its prototype chain, it will be
|
||||
* wrapped in an Error.
|
||||
*
|
||||
* @example
|
||||
* var f1 = sinon.fake.rejects(":(");
|
||||
*
|
||||
* try {
|
||||
* await ft();
|
||||
* } catch (error) {
|
||||
* console.log(error);
|
||||
* // ":("
|
||||
* }
|
||||
*
|
||||
* @memberof fake
|
||||
* @param {*} value
|
||||
* @returns {Function}
|
||||
*/
|
||||
fake.rejects = function rejects(value) {
|
||||
// eslint-disable-next-line jsdoc/require-jsdoc
|
||||
function f() {
|
||||
return promiseLib.reject(getError(value));
|
||||
}
|
||||
|
||||
return wrapFunc(f);
|
||||
};
|
||||
|
||||
/**
|
||||
* Causes `fake` to use a custom Promise implementation, instead of the native
|
||||
* Promise implementation.
|
||||
*
|
||||
* @example
|
||||
* const bluebird = require("bluebird");
|
||||
* sinon.fake.usingPromise(bluebird);
|
||||
*
|
||||
* @memberof fake
|
||||
* @param {*} promiseLibrary
|
||||
* @returns {Function}
|
||||
*/
|
||||
fake.usingPromise = function usingPromise(promiseLibrary) {
|
||||
promiseLib = promiseLibrary;
|
||||
return fake;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a `fake` that calls the callback with the defined arguments.
|
||||
*
|
||||
* @example
|
||||
* function callback() {
|
||||
* console.log(arguments.join("*"));
|
||||
* }
|
||||
*
|
||||
* const f1 = sinon.fake.yields("apple", "pie");
|
||||
*
|
||||
* f1(callback);
|
||||
* // "apple*pie"
|
||||
*
|
||||
* @memberof fake
|
||||
* @returns {Function}
|
||||
*/
|
||||
fake.yields = function yields() {
|
||||
var values = slice(arguments);
|
||||
|
||||
// eslint-disable-next-line jsdoc/require-jsdoc
|
||||
function f() {
|
||||
var callback = arguments[arguments.length - 1];
|
||||
if (typeof callback !== "function") {
|
||||
throw new TypeError("Expected last argument to be a function");
|
||||
}
|
||||
|
||||
callback.apply(null, values);
|
||||
}
|
||||
|
||||
return wrapFunc(f);
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a `fake` that calls the callback **asynchronously** with the
|
||||
* defined arguments.
|
||||
*
|
||||
* @example
|
||||
* function callback() {
|
||||
* console.log(arguments.join("*"));
|
||||
* }
|
||||
*
|
||||
* const f1 = sinon.fake.yields("apple", "pie");
|
||||
*
|
||||
* f1(callback);
|
||||
*
|
||||
* setTimeout(() => {
|
||||
* // "apple*pie"
|
||||
* });
|
||||
*
|
||||
* @memberof fake
|
||||
* @returns {Function}
|
||||
*/
|
||||
fake.yieldsAsync = function yieldsAsync() {
|
||||
var values = slice(arguments);
|
||||
|
||||
// eslint-disable-next-line jsdoc/require-jsdoc
|
||||
function f() {
|
||||
var callback = arguments[arguments.length - 1];
|
||||
if (typeof callback !== "function") {
|
||||
throw new TypeError("Expected last argument to be a function");
|
||||
}
|
||||
nextTick(function () {
|
||||
callback.apply(null, values);
|
||||
});
|
||||
}
|
||||
|
||||
return wrapFunc(f);
|
||||
};
|
||||
|
||||
var uuid = 0;
|
||||
/**
|
||||
* Creates a proxy (sinon concept) from the passed function.
|
||||
*
|
||||
* @private
|
||||
* @param {Function} f
|
||||
* @returns {Function}
|
||||
*/
|
||||
function wrapFunc(f) {
|
||||
var proxy;
|
||||
var fakeInstance = function() {
|
||||
var fakeInstance = function () {
|
||||
var firstArg, lastArg;
|
||||
|
||||
if (arguments.length > 0) {
|
||||
|
|
@ -21,7 +257,8 @@ function wrapFunc(f) {
|
|||
lastArg = arguments[arguments.length - 1];
|
||||
}
|
||||
|
||||
var callback = lastArg && typeof lastArg === "function" ? lastArg : undefined;
|
||||
var callback =
|
||||
lastArg && typeof lastArg === "function" ? lastArg : undefined;
|
||||
|
||||
proxy.firstArg = firstArg;
|
||||
proxy.lastArg = lastArg;
|
||||
|
|
@ -32,75 +269,19 @@ function wrapFunc(f) {
|
|||
proxy = createProxy(fakeInstance, f || fakeInstance);
|
||||
|
||||
proxy.displayName = "fake";
|
||||
proxy.id = "fake#" + uuid++;
|
||||
proxy.id = `fake#${uuid++}`;
|
||||
|
||||
return proxy;
|
||||
}
|
||||
|
||||
function fake(f) {
|
||||
if (arguments.length > 0 && typeof f !== "function") {
|
||||
throw new TypeError("Expected f argument to be a Function");
|
||||
}
|
||||
|
||||
return wrapFunc(f);
|
||||
/**
|
||||
* Returns an Error instance from the passed value, if the value is not
|
||||
* already an Error instance.
|
||||
*
|
||||
* @private
|
||||
* @param {*} value [description]
|
||||
* @returns {Error} [description]
|
||||
*/
|
||||
function getError(value) {
|
||||
return value instanceof Error ? value : new Error(value);
|
||||
}
|
||||
|
||||
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;
|
||||
|
|
|
|||
93
node_modules/sinon/lib/sinon/mock-expectation.js
generated
vendored
93
node_modules/sinon/lib/sinon/mock-expectation.js
generated
vendored
|
|
@ -22,7 +22,7 @@ function callCountInWords(callCount) {
|
|||
return "never called";
|
||||
}
|
||||
|
||||
return "called " + timesInWords(callCount);
|
||||
return `called ${timesInWords(callCount)}`;
|
||||
}
|
||||
|
||||
function expectedCallCountInWords(expectation) {
|
||||
|
|
@ -33,17 +33,17 @@ function expectedCallCountInWords(expectation) {
|
|||
var str = timesInWords(min);
|
||||
|
||||
if (min !== max) {
|
||||
str = "at least " + str + " and at most " + timesInWords(max);
|
||||
str = `at least ${str} and at most ${timesInWords(max)}`;
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
if (typeof min === "number") {
|
||||
return "at least " + timesInWords(min);
|
||||
return `at least ${timesInWords(min)}`;
|
||||
}
|
||||
|
||||
return "at most " + timesInWords(max);
|
||||
return `at most ${timesInWords(max)}`;
|
||||
}
|
||||
|
||||
function receivedMinCalls(expectation) {
|
||||
|
|
@ -85,7 +85,7 @@ var mockExpectation = {
|
|||
|
||||
atLeast: function atLeast(num) {
|
||||
if (typeof num !== "number") {
|
||||
throw new TypeError("'" + valueToString(num) + "' is not number");
|
||||
throw new TypeError(`'${valueToString(num)}' is not number`);
|
||||
}
|
||||
|
||||
if (!this.limitsSet) {
|
||||
|
|
@ -100,7 +100,7 @@ var mockExpectation = {
|
|||
|
||||
atMost: function atMost(num) {
|
||||
if (typeof num !== "number") {
|
||||
throw new TypeError("'" + valueToString(num) + "' is not number");
|
||||
throw new TypeError(`'${valueToString(num)}' is not number`);
|
||||
}
|
||||
|
||||
if (!this.limitsSet) {
|
||||
|
|
@ -131,7 +131,7 @@ var mockExpectation = {
|
|||
|
||||
exactly: function exactly(num) {
|
||||
if (typeof num !== "number") {
|
||||
throw new TypeError("'" + valueToString(num) + "' is not a number");
|
||||
throw new TypeError(`'${valueToString(num)}' is not a number`);
|
||||
}
|
||||
|
||||
this.atLeast(num);
|
||||
|
|
@ -147,16 +147,16 @@ var mockExpectation = {
|
|||
|
||||
if (receivedMaxCalls(this)) {
|
||||
this.failed = true;
|
||||
mockExpectation.fail(this.method + " already called " + timesInWords(this.maxCalls));
|
||||
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)
|
||||
`${this.method} called with ${valueToString(
|
||||
thisValue
|
||||
)} as thisValue, expected ${valueToString(this.expectedThis)}`
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -165,49 +165,48 @@ var mockExpectation = {
|
|||
}
|
||||
|
||||
if (!args) {
|
||||
mockExpectation.fail(this.method + " received no arguments, expected " + format(expectedArguments));
|
||||
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)
|
||||
`${this.method} received too few arguments (${format(
|
||||
args
|
||||
)}), expected ${format(expectedArguments)}`
|
||||
);
|
||||
}
|
||||
|
||||
if (this.expectsExactArgCount && args.length !== expectedArguments.length) {
|
||||
if (
|
||||
this.expectsExactArgCount &&
|
||||
args.length !== expectedArguments.length
|
||||
) {
|
||||
mockExpectation.fail(
|
||||
this.method +
|
||||
" received too many arguments (" +
|
||||
format(args) +
|
||||
"), expected " +
|
||||
format(expectedArguments)
|
||||
`${this.method} received too many arguments (${format(
|
||||
args
|
||||
)}), expected ${format(expectedArguments)}`
|
||||
);
|
||||
}
|
||||
|
||||
forEach(
|
||||
expectedArguments,
|
||||
function(expectedArgument, i) {
|
||||
function (expectedArgument, i) {
|
||||
if (!verifyMatcher(expectedArgument, args[i])) {
|
||||
mockExpectation.fail(
|
||||
this.method +
|
||||
" received wrong arguments " +
|
||||
format(args) +
|
||||
", didn't match " +
|
||||
String(expectedArguments)
|
||||
`${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.method} received wrong arguments ${format(
|
||||
args
|
||||
)}, expected ${format(expectedArguments)}`
|
||||
);
|
||||
}
|
||||
},
|
||||
|
|
@ -237,11 +236,14 @@ var mockExpectation = {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (this.expectsExactArgCount && _args.length !== expectedArguments.length) {
|
||||
if (
|
||||
this.expectsExactArgCount &&
|
||||
_args.length !== expectedArguments.length
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return every(expectedArguments, function(expectedArgument, i) {
|
||||
return every(expectedArguments, function (expectedArgument, i) {
|
||||
if (!verifyMatcher(expectedArgument, _args[i])) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -270,7 +272,7 @@ var mockExpectation = {
|
|||
return this;
|
||||
},
|
||||
|
||||
toString: function() {
|
||||
toString: function () {
|
||||
var args = slice(this.expectedArguments || []);
|
||||
|
||||
if (!this.expectsExactArgCount) {
|
||||
|
|
@ -279,16 +281,19 @@ var mockExpectation = {
|
|||
|
||||
var callStr = proxyCallToString.call({
|
||||
proxy: this.method || "anonymous mock expectation",
|
||||
args: args
|
||||
args: args,
|
||||
});
|
||||
|
||||
var message = callStr.replace(", [...", "[, ...") + " " + expectedCallCountInWords(this);
|
||||
var message = `${callStr.replace(
|
||||
", [...",
|
||||
"[, ..."
|
||||
)} ${expectedCallCountInWords(this)}`;
|
||||
|
||||
if (this.met()) {
|
||||
return "Expectation met: " + message;
|
||||
return `Expectation met: ${message}`;
|
||||
}
|
||||
|
||||
return "Expected " + message + " (" + callCountInWords(this.callCount) + ")";
|
||||
return `Expected ${message} (${callCountInWords(this.callCount)})`;
|
||||
},
|
||||
|
||||
verify: function verify() {
|
||||
|
|
@ -310,7 +315,7 @@ var mockExpectation = {
|
|||
exception.name = "ExpectationError";
|
||||
|
||||
throw exception;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = mockExpectation;
|
||||
|
|
|
|||
70
node_modules/sinon/lib/sinon/mock.js
generated
vendored
70
node_modules/sinon/lib/sinon/mock.js
generated
vendored
|
|
@ -36,7 +36,7 @@ function arrayEquals(arr1, arr2, compareLength) {
|
|||
return false;
|
||||
}
|
||||
|
||||
return every(arr1, function(element, i) {
|
||||
return every(arr1, function (element, i) {
|
||||
return deepEqual(arr2[i], element);
|
||||
});
|
||||
}
|
||||
|
|
@ -68,7 +68,7 @@ extend(mock, {
|
|||
this.expectations[method] = [];
|
||||
var mockObject = this;
|
||||
|
||||
wrapMethod(this.object, method, function() {
|
||||
wrapMethod(this.object, method, function () {
|
||||
return mockObject.invokeMethod(method, this, arguments);
|
||||
});
|
||||
|
||||
|
|
@ -86,7 +86,7 @@ extend(mock, {
|
|||
restore: function restore() {
|
||||
var object = this.object;
|
||||
|
||||
each(this.proxies, function(proxy) {
|
||||
each(this.proxies, function (proxy) {
|
||||
if (typeof object[proxy].restore === "function") {
|
||||
object[proxy].restore();
|
||||
}
|
||||
|
|
@ -98,8 +98,8 @@ extend(mock, {
|
|||
var messages = this.failures ? slice(this.failures) : [];
|
||||
var met = [];
|
||||
|
||||
each(this.proxies, function(proxy) {
|
||||
each(expectations[proxy], function(expectation) {
|
||||
each(this.proxies, function (proxy) {
|
||||
each(expectations[proxy], function (expectation) {
|
||||
if (!expectation.met()) {
|
||||
push(messages, String(expectation));
|
||||
} else {
|
||||
|
|
@ -128,19 +128,35 @@ extend(mock, {
|
|||
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 expectations =
|
||||
this.expectations && this.expectations[method]
|
||||
? this.expectations[method]
|
||||
: [];
|
||||
var currentArgs = args || [];
|
||||
var available;
|
||||
|
||||
var expectationsWithMatchingArgs = filter(expectations, function(expectation) {
|
||||
var expectedArgs = expectation.expectedArguments || [];
|
||||
var expectationsWithMatchingArgs = filter(
|
||||
expectations,
|
||||
function (expectation) {
|
||||
var expectedArgs = expectation.expectedArguments || [];
|
||||
|
||||
return arrayEquals(expectedArgs, currentArgs, expectation.expectsExactArgCount);
|
||||
});
|
||||
return arrayEquals(
|
||||
expectedArgs,
|
||||
currentArgs,
|
||||
expectation.expectsExactArgCount
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
var expectationsToApply = filter(expectationsWithMatchingArgs, function(expectation) {
|
||||
return !expectation.met() && expectation.allowsCall(thisValue, args);
|
||||
});
|
||||
var expectationsToApply = filter(
|
||||
expectationsWithMatchingArgs,
|
||||
function (expectation) {
|
||||
return (
|
||||
!expectation.met() &&
|
||||
expectation.allowsCall(thisValue, args)
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
if (expectationsToApply.length > 0) {
|
||||
return expectationsToApply[0].apply(thisValue, args);
|
||||
|
|
@ -149,7 +165,7 @@ extend(mock, {
|
|||
var messages = [];
|
||||
var exhausted = 0;
|
||||
|
||||
forEach(expectationsWithMatchingArgs, function(expectation) {
|
||||
forEach(expectationsWithMatchingArgs, function (expectation) {
|
||||
if (expectation.allowsCall(thisValue, args)) {
|
||||
available = available || expectation;
|
||||
} else {
|
||||
|
|
@ -161,17 +177,16 @@ extend(mock, {
|
|||
return available.apply(thisValue, args);
|
||||
}
|
||||
|
||||
forEach(expectations, function(expectation) {
|
||||
push(messages, " " + String(expectation));
|
||||
forEach(expectations, function (expectation) {
|
||||
push(messages, ` ${String(expectation)}`);
|
||||
});
|
||||
|
||||
unshift(
|
||||
messages,
|
||||
"Unexpected call: " +
|
||||
proxyCallToString.call({
|
||||
proxy: method,
|
||||
args: args
|
||||
})
|
||||
`Unexpected call: ${proxyCallToString.call({
|
||||
proxy: method,
|
||||
args: args,
|
||||
})}`
|
||||
);
|
||||
|
||||
var err = new Error();
|
||||
|
|
@ -185,16 +200,15 @@ extend(mock, {
|
|||
}
|
||||
push(
|
||||
this.failures,
|
||||
"Unexpected call: " +
|
||||
proxyCallToString.call({
|
||||
proxy: method,
|
||||
args: args,
|
||||
stack: err.stack
|
||||
})
|
||||
`Unexpected call: ${proxyCallToString.call({
|
||||
proxy: method,
|
||||
args: args,
|
||||
stack: err.stack,
|
||||
})}`
|
||||
);
|
||||
|
||||
mockExpectation.fail(join(messages, "\n"));
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
module.exports = mock;
|
||||
|
|
|
|||
84
node_modules/sinon/lib/sinon/promise.js
generated
vendored
Normal file
84
node_modules/sinon/lib/sinon/promise.js
generated
vendored
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
"use strict";
|
||||
|
||||
var fake = require("./fake");
|
||||
var isRestorable = require("./util/core/is-restorable");
|
||||
|
||||
var STATUS_PENDING = "pending";
|
||||
var STATUS_RESOLVED = "resolved";
|
||||
var STATUS_REJECTED = "rejected";
|
||||
|
||||
/**
|
||||
* Returns a fake for a given function or undefined. If no functino is given, a
|
||||
* new fake is returned. If the given function is already a fake, it is
|
||||
* returned as is. Otherwise the given function is wrapped in a new fake.
|
||||
*
|
||||
* @param {Function} [executor] The optional executor function.
|
||||
* @returns {Function}
|
||||
*/
|
||||
function getFakeExecutor(executor) {
|
||||
if (isRestorable(executor)) {
|
||||
return executor;
|
||||
}
|
||||
if (executor) {
|
||||
return fake(executor);
|
||||
}
|
||||
return fake();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new promise that exposes it's internal `status`, `resolvedValue`
|
||||
* and `rejectedValue` and can be resolved or rejected from the outside by
|
||||
* calling `resolve(value)` or `reject(reason)`.
|
||||
*
|
||||
* @param {Function} [executor] The optional executor function.
|
||||
* @returns {Promise}
|
||||
*/
|
||||
function promise(executor) {
|
||||
var fakeExecutor = getFakeExecutor(executor);
|
||||
var sinonPromise = new Promise(fakeExecutor);
|
||||
|
||||
sinonPromise.status = STATUS_PENDING;
|
||||
sinonPromise
|
||||
.then(function (value) {
|
||||
sinonPromise.status = STATUS_RESOLVED;
|
||||
sinonPromise.resolvedValue = value;
|
||||
})
|
||||
.catch(function (reason) {
|
||||
sinonPromise.status = STATUS_REJECTED;
|
||||
sinonPromise.rejectedValue = reason;
|
||||
});
|
||||
|
||||
/**
|
||||
* Resolves or rejects the promise with the given status and value.
|
||||
*
|
||||
* @param {string} status
|
||||
* @param {*} value
|
||||
* @param {Function} callback
|
||||
*/
|
||||
function finalize(status, value, callback) {
|
||||
if (sinonPromise.status !== STATUS_PENDING) {
|
||||
throw new Error(`Promise already ${sinonPromise.status}`);
|
||||
}
|
||||
|
||||
sinonPromise.status = status;
|
||||
callback(value);
|
||||
}
|
||||
|
||||
sinonPromise.resolve = function (value) {
|
||||
finalize(STATUS_RESOLVED, value, fakeExecutor.firstCall.args[0]);
|
||||
// Return the promise so that callers can await it:
|
||||
return sinonPromise;
|
||||
};
|
||||
sinonPromise.reject = function (reason) {
|
||||
finalize(STATUS_REJECTED, reason, fakeExecutor.firstCall.args[1]);
|
||||
// Return a new promise that resolves when the sinon promise was
|
||||
// rejected, so that callers can await it:
|
||||
return new Promise(function (resolve) {
|
||||
sinonPromise.catch(() => resolve());
|
||||
});
|
||||
};
|
||||
|
||||
return sinonPromise;
|
||||
}
|
||||
|
||||
module.exports = promise;
|
||||
7
node_modules/sinon/lib/sinon/proxy-call-util.js
generated
vendored
7
node_modules/sinon/lib/sinon/proxy-call-util.js
generated
vendored
|
|
@ -27,7 +27,7 @@ exports.delegateToCalls = function delegateToCalls(
|
|||
notCalled,
|
||||
totalCallCount
|
||||
) {
|
||||
proxy[method] = function() {
|
||||
proxy[method] = function () {
|
||||
if (!this.called) {
|
||||
if (notCalled) {
|
||||
return notCalled.apply(this, arguments);
|
||||
|
|
@ -45,7 +45,10 @@ exports.delegateToCalls = function delegateToCalls(
|
|||
|
||||
for (var i = 0, l = this.callCount; i < l; i += 1) {
|
||||
currentCall = this.getCall(i);
|
||||
var returnValue = currentCall[actual || method].apply(currentCall, arguments);
|
||||
var returnValue = currentCall[actual || method].apply(
|
||||
currentCall,
|
||||
arguments
|
||||
);
|
||||
push(returnValues, returnValue);
|
||||
if (returnValue) {
|
||||
matches += 1;
|
||||
|
|
|
|||
108
node_modules/sinon/lib/sinon/proxy-call.js
generated
vendored
108
node_modules/sinon/lib/sinon/proxy-call.js
generated
vendored
|
|
@ -17,7 +17,7 @@ var slice = arrayProto.slice;
|
|||
function throwYieldError(proxy, text, args) {
|
||||
var msg = functionName(proxy) + text;
|
||||
if (args.length) {
|
||||
msg += " Received [" + join(slice(args), ", ") + "]";
|
||||
msg += ` Received [${join(slice(args), ", ")}]`;
|
||||
}
|
||||
throw new Error(msg);
|
||||
}
|
||||
|
|
@ -40,7 +40,7 @@ var callProto = {
|
|||
|
||||
return reduce(
|
||||
calledWithArgs,
|
||||
function(prev, arg, i) {
|
||||
function (prev, arg, i) {
|
||||
return prev && deepEqual(self.args[i], arg);
|
||||
},
|
||||
true
|
||||
|
|
@ -57,7 +57,7 @@ var callProto = {
|
|||
|
||||
return reduce(
|
||||
calledWithMatchArgs,
|
||||
function(prev, expectation, i) {
|
||||
function (prev, expectation, i) {
|
||||
var actual = self.args[i];
|
||||
|
||||
return prev && match(expectation).test(actual);
|
||||
|
|
@ -67,7 +67,10 @@ var callProto = {
|
|||
},
|
||||
|
||||
calledWithExactly: function calledWithExactly() {
|
||||
return arguments.length === this.args.length && this.calledWith.apply(this, arguments);
|
||||
return (
|
||||
arguments.length === this.args.length &&
|
||||
this.calledWith.apply(this, arguments)
|
||||
);
|
||||
},
|
||||
|
||||
notCalledWith: function notCalledWith() {
|
||||
|
|
@ -94,74 +97,86 @@ var callProto = {
|
|||
return this.proxy.prototype && this.thisValue instanceof this.proxy;
|
||||
},
|
||||
|
||||
calledBefore: function(other) {
|
||||
calledBefore: function (other) {
|
||||
return this.callId < other.callId;
|
||||
},
|
||||
|
||||
calledAfter: function(other) {
|
||||
calledAfter: function (other) {
|
||||
return this.callId > other.callId;
|
||||
},
|
||||
|
||||
calledImmediatelyBefore: function(other) {
|
||||
calledImmediatelyBefore: function (other) {
|
||||
return this.callId === other.callId - 1;
|
||||
},
|
||||
|
||||
calledImmediatelyAfter: function(other) {
|
||||
calledImmediatelyAfter: function (other) {
|
||||
return this.callId === other.callId + 1;
|
||||
},
|
||||
|
||||
callArg: function(pos) {
|
||||
callArg: function (pos) {
|
||||
this.ensureArgIsAFunction(pos);
|
||||
return this.args[pos]();
|
||||
},
|
||||
|
||||
callArgOn: function(pos, thisValue) {
|
||||
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)));
|
||||
callArgWith: function (pos) {
|
||||
return this.callArgOnWith.apply(
|
||||
this,
|
||||
concat([pos, null], slice(arguments, 1))
|
||||
);
|
||||
},
|
||||
|
||||
callArgOnWith: function(pos, thisValue) {
|
||||
callArgOnWith: function (pos, thisValue) {
|
||||
this.ensureArgIsAFunction(pos);
|
||||
var args = slice(arguments, 2);
|
||||
return this.args[pos].apply(thisValue, args);
|
||||
},
|
||||
|
||||
throwArg: function(pos) {
|
||||
throwArg: function (pos) {
|
||||
if (pos > this.args.length) {
|
||||
throw new TypeError("Not enough arguments: " + pos + " required but only " + this.args.length + " present");
|
||||
throw new TypeError(
|
||||
`Not enough arguments: ${pos} required but only ${this.args.length} present`
|
||||
);
|
||||
}
|
||||
|
||||
throw this.args[pos];
|
||||
},
|
||||
|
||||
yield: function() {
|
||||
yield: function () {
|
||||
return this.yieldOn.apply(this, concat([null], slice(arguments, 0)));
|
||||
},
|
||||
|
||||
yieldOn: function(thisValue) {
|
||||
yieldOn: function (thisValue) {
|
||||
var args = slice(this.args);
|
||||
var yieldFn = filter(args, function(arg) {
|
||||
var yieldFn = filter(args, function (arg) {
|
||||
return typeof arg === "function";
|
||||
})[0];
|
||||
|
||||
if (!yieldFn) {
|
||||
throwYieldError(this.proxy, " cannot yield since no callback was passed.", args);
|
||||
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)));
|
||||
yieldTo: function (prop) {
|
||||
return this.yieldToOn.apply(
|
||||
this,
|
||||
concat([prop, null], slice(arguments, 1))
|
||||
);
|
||||
},
|
||||
|
||||
yieldToOn: function(prop, thisValue) {
|
||||
yieldToOn: function (prop, thisValue) {
|
||||
var args = slice(this.args);
|
||||
var yieldArg = filter(args, function(arg) {
|
||||
var yieldArg = filter(args, function (arg) {
|
||||
return arg && typeof arg[prop] === "function";
|
||||
})[0];
|
||||
var yieldFn = yieldArg && yieldArg[prop];
|
||||
|
|
@ -169,7 +184,9 @@ var callProto = {
|
|||
if (!yieldFn) {
|
||||
throwYieldError(
|
||||
this.proxy,
|
||||
" cannot yield to '" + valueToString(prop) + "' since no callback was passed.",
|
||||
` cannot yield to '${valueToString(
|
||||
prop
|
||||
)}' since no callback was passed.`,
|
||||
args
|
||||
);
|
||||
}
|
||||
|
|
@ -177,58 +194,70 @@ var callProto = {
|
|||
return yieldFn.apply(thisValue, slice(arguments, 2));
|
||||
},
|
||||
|
||||
toString: function() {
|
||||
var callStr = this.proxy ? String(this.proxy) + "(" : "";
|
||||
toString: function () {
|
||||
var callStr = this.proxy ? `${String(this.proxy)}(` : "";
|
||||
var formattedArgs;
|
||||
|
||||
if (!this.args) {
|
||||
return ":(";
|
||||
}
|
||||
|
||||
formattedArgs = map(this.args, function(arg) {
|
||||
formattedArgs = map(this.args, function (arg) {
|
||||
return sinonFormat(arg);
|
||||
});
|
||||
|
||||
callStr = callStr + join(formattedArgs, ", ") + ")";
|
||||
callStr = `${callStr + join(formattedArgs, ", ")})`;
|
||||
|
||||
if (typeof this.returnValue !== "undefined") {
|
||||
callStr += " => " + sinonFormat(this.returnValue);
|
||||
callStr += ` => ${sinonFormat(this.returnValue)}`;
|
||||
}
|
||||
|
||||
if (this.exception) {
|
||||
callStr += " !" + this.exception.name;
|
||||
callStr += ` !${this.exception.name}`;
|
||||
|
||||
if (this.exception.message) {
|
||||
callStr += "(" + 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 ");
|
||||
callStr += (this.stack.split("\n")[3] || "unknown").replace(
|
||||
/^\s*(?:at\s+|@)?/,
|
||||
" at "
|
||||
);
|
||||
}
|
||||
|
||||
return callStr;
|
||||
},
|
||||
|
||||
ensureArgIsAFunction: function(pos) {
|
||||
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]
|
||||
`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() {
|
||||
get: function () {
|
||||
return (this.errorWithCallStack && this.errorWithCallStack.stack) || "";
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
callProto.invokeCallback = callProto.yield;
|
||||
|
||||
function createProxyCall(proxy, thisValue, args, returnValue, exception, id, errorWithCallStack) {
|
||||
function createProxyCall(
|
||||
proxy,
|
||||
thisValue,
|
||||
args,
|
||||
returnValue,
|
||||
exception,
|
||||
id,
|
||||
errorWithCallStack
|
||||
) {
|
||||
if (typeof id !== "number") {
|
||||
throw new TypeError("Call id is not a number");
|
||||
}
|
||||
|
|
@ -241,7 +270,8 @@ function createProxyCall(proxy, thisValue, args, returnValue, exception, id, err
|
|||
}
|
||||
|
||||
var proxyCall = Object.create(callProto);
|
||||
var callback = lastArg && typeof lastArg === "function" ? lastArg : undefined;
|
||||
var callback =
|
||||
lastArg && typeof lastArg === "function" ? lastArg : undefined;
|
||||
|
||||
proxyCall.proxy = proxy;
|
||||
proxyCall.thisValue = thisValue;
|
||||
|
|
|
|||
11
node_modules/sinon/lib/sinon/proxy-invoke.js
generated
vendored
11
node_modules/sinon/lib/sinon/proxy-invoke.js
generated
vendored
|
|
@ -20,7 +20,7 @@ module.exports = function invoke(func, thisValue, args) {
|
|||
push(this.thisValues, thisValue);
|
||||
push(this.args, args);
|
||||
push(this.callIds, currentCallId);
|
||||
forEach(matchings, function(matching) {
|
||||
forEach(matchings, function (matching) {
|
||||
proxyCallUtil.incrementCallCount(matching);
|
||||
push(matching.thisValues, thisValue);
|
||||
push(matching.args, args);
|
||||
|
|
@ -38,7 +38,10 @@ module.exports = function invoke(func, thisValue, args) {
|
|||
|
||||
if (thisCall.calledWithNew()) {
|
||||
// Call through with `new`
|
||||
returnValue = new (bind.apply(this.func || func, concat([thisValue], args)))();
|
||||
returnValue = new (bind.apply(
|
||||
this.func || func,
|
||||
concat([thisValue], args)
|
||||
))();
|
||||
|
||||
if (typeof returnValue !== "object") {
|
||||
returnValue = thisValue;
|
||||
|
|
@ -54,7 +57,7 @@ module.exports = function invoke(func, thisValue, args) {
|
|||
|
||||
push(this.exceptions, exception);
|
||||
push(this.returnValues, returnValue);
|
||||
forEach(matchings, function(matching) {
|
||||
forEach(matchings, function (matching) {
|
||||
push(matching.exceptions, exception);
|
||||
push(matching.returnValues, returnValue);
|
||||
});
|
||||
|
|
@ -69,7 +72,7 @@ module.exports = function invoke(func, thisValue, args) {
|
|||
/* empty */
|
||||
}
|
||||
push(this.errorsWithCallStack, err);
|
||||
forEach(matchings, function(matching) {
|
||||
forEach(matchings, function (matching) {
|
||||
push(matching.errorsWithCallStack, err);
|
||||
});
|
||||
|
||||
|
|
|
|||
90
node_modules/sinon/lib/sinon/proxy.js
generated
vendored
90
node_modules/sinon/lib/sinon/proxy.js
generated
vendored
|
|
@ -36,7 +36,7 @@ var proxyApi = {
|
|||
* Hook for derived implementation to return fake instances matching the
|
||||
* given arguments.
|
||||
*/
|
||||
matchingFakes: function(/*args, strict*/) {
|
||||
matchingFakes: function (/*args, strict*/) {
|
||||
return emptyFakes;
|
||||
},
|
||||
|
||||
|
|
@ -61,7 +61,7 @@ var proxyApi = {
|
|||
);
|
||||
},
|
||||
|
||||
getCalls: function() {
|
||||
getCalls: function () {
|
||||
var calls = [];
|
||||
var i;
|
||||
|
||||
|
|
@ -97,7 +97,10 @@ var proxyApi = {
|
|||
return false;
|
||||
}
|
||||
|
||||
return this.callIds[this.callCount - 1] === proxy.callIds[proxy.callCount - 1] - 1;
|
||||
return (
|
||||
this.callIds[this.callCount - 1] ===
|
||||
proxy.callIds[proxy.callCount - 1] - 1
|
||||
);
|
||||
},
|
||||
|
||||
calledImmediatelyAfter: function calledImmediatelyAfter(proxy) {
|
||||
|
|
@ -105,16 +108,19 @@ var proxyApi = {
|
|||
return false;
|
||||
}
|
||||
|
||||
return this.callIds[this.callCount - 1] === proxy.callIds[proxy.callCount - 1] + 1;
|
||||
return (
|
||||
this.callIds[this.callCount - 1] ===
|
||||
proxy.callIds[proxy.callCount - 1] + 1
|
||||
);
|
||||
},
|
||||
|
||||
formatters: require("./spy-formatters"),
|
||||
printf: function(format) {
|
||||
printf: function (format) {
|
||||
var spyInstance = this;
|
||||
var args = slice(arguments, 1);
|
||||
var formatter;
|
||||
|
||||
return (format || "").replace(/%(.)/g, function(match, specifyer) {
|
||||
return (format || "").replace(/%(.)/g, function (match, specifyer) {
|
||||
formatter = proxyApi.formatters[specifyer];
|
||||
|
||||
if (typeof formatter === "function") {
|
||||
|
|
@ -123,11 +129,11 @@ var proxyApi = {
|
|||
return sinonFormat(args[specifyer - 1]);
|
||||
}
|
||||
|
||||
return "%" + specifyer;
|
||||
return `%${specifyer}`;
|
||||
});
|
||||
},
|
||||
|
||||
resetHistory: function() {
|
||||
resetHistory: function () {
|
||||
if (this.invoking) {
|
||||
var err = new Error(
|
||||
"Cannot reset Sinon function while invoking it. " +
|
||||
|
|
@ -157,32 +163,76 @@ var proxyApi = {
|
|||
this.errorsWithCallStack = [];
|
||||
|
||||
if (this.fakes) {
|
||||
forEach(this.fakes, function(fake) {
|
||||
forEach(this.fakes, function (fake) {
|
||||
fake.resetHistory();
|
||||
});
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
var delegateToCalls = proxyCallUtil.delegateToCalls;
|
||||
delegateToCalls(proxyApi, "calledOn", true);
|
||||
delegateToCalls(proxyApi, "alwaysCalledOn", false, "calledOn");
|
||||
delegateToCalls(proxyApi, "calledWith", true);
|
||||
delegateToCalls(proxyApi, "calledOnceWith", true, "calledWith", false, undefined, 1);
|
||||
delegateToCalls(
|
||||
proxyApi,
|
||||
"calledOnceWith",
|
||||
true,
|
||||
"calledWith",
|
||||
false,
|
||||
undefined,
|
||||
1
|
||||
);
|
||||
delegateToCalls(proxyApi, "calledWithMatch", true);
|
||||
delegateToCalls(proxyApi, "alwaysCalledWith", false, "calledWith");
|
||||
delegateToCalls(proxyApi, "alwaysCalledWithMatch", false, "calledWithMatch");
|
||||
delegateToCalls(proxyApi, "calledWithExactly", true);
|
||||
delegateToCalls(proxyApi, "calledOnceWithExactly", true, "calledWithExactly", false, undefined, 1);
|
||||
delegateToCalls(proxyApi, "alwaysCalledWithExactly", false, "calledWithExactly");
|
||||
delegateToCalls(proxyApi, "neverCalledWith", false, "notCalledWith", false, function() {
|
||||
return true;
|
||||
});
|
||||
delegateToCalls(proxyApi, "neverCalledWithMatch", false, "notCalledWithMatch", false, function() {
|
||||
return true;
|
||||
});
|
||||
delegateToCalls(
|
||||
proxyApi,
|
||||
"calledOnceWithExactly",
|
||||
true,
|
||||
"calledWithExactly",
|
||||
false,
|
||||
undefined,
|
||||
1
|
||||
);
|
||||
delegateToCalls(
|
||||
proxyApi,
|
||||
"calledOnceWithMatch",
|
||||
true,
|
||||
"calledWithMatch",
|
||||
false,
|
||||
undefined,
|
||||
1
|
||||
);
|
||||
delegateToCalls(
|
||||
proxyApi,
|
||||
"alwaysCalledWithExactly",
|
||||
false,
|
||||
"calledWithExactly"
|
||||
);
|
||||
delegateToCalls(
|
||||
proxyApi,
|
||||
"neverCalledWith",
|
||||
false,
|
||||
"notCalledWith",
|
||||
false,
|
||||
function () {
|
||||
return true;
|
||||
}
|
||||
);
|
||||
delegateToCalls(
|
||||
proxyApi,
|
||||
"neverCalledWithMatch",
|
||||
false,
|
||||
"notCalledWithMatch",
|
||||
false,
|
||||
function () {
|
||||
return true;
|
||||
}
|
||||
);
|
||||
delegateToCalls(proxyApi, "threw", true);
|
||||
delegateToCalls(proxyApi, "alwaysThrew", false, "threw");
|
||||
delegateToCalls(proxyApi, "returned", true);
|
||||
|
|
@ -308,7 +358,7 @@ function wrapFunction(func, originalFunc) {
|
|||
thisValues: [],
|
||||
exceptions: [],
|
||||
callIds: [],
|
||||
errorsWithCallStack: []
|
||||
errorsWithCallStack: [],
|
||||
});
|
||||
return p;
|
||||
}
|
||||
|
|
|
|||
146
node_modules/sinon/lib/sinon/sandbox.js
generated
vendored
146
node_modules/sinon/lib/sinon/sandbox.js
generated
vendored
|
|
@ -1,6 +1,7 @@
|
|||
"use strict";
|
||||
|
||||
var arrayProto = require("@sinonjs/commons").prototypes.array;
|
||||
var logger = require("@sinonjs/commons").deprecated;
|
||||
var collectOwnMethods = require("./collect-own-methods");
|
||||
var getPropertyDescriptor = require("./util/core/get-property-descriptor");
|
||||
var isPropertyConfigurable = require("./util/core/is-property-configurable");
|
||||
|
|
@ -16,27 +17,47 @@ var fakeServer = require("nise").fakeServer;
|
|||
var fakeXhr = require("nise").fakeXhr;
|
||||
var usePromiseLibrary = require("./util/core/use-promise-library");
|
||||
|
||||
var DEFAULT_LEAK_THRESHOLD = 10000;
|
||||
|
||||
var filter = arrayProto.filter;
|
||||
var forEach = arrayProto.filter;
|
||||
var forEach = arrayProto.forEach;
|
||||
var push = arrayProto.push;
|
||||
var reverse = arrayProto.reverse;
|
||||
|
||||
function applyOnEach(fakes, method) {
|
||||
var matchingFakes = filter(fakes, function(fake) {
|
||||
var matchingFakes = filter(fakes, function (fake) {
|
||||
return typeof fake[method] === "function";
|
||||
});
|
||||
|
||||
forEach(matchingFakes, function(fake) {
|
||||
forEach(matchingFakes, function (fake) {
|
||||
fake[method]();
|
||||
});
|
||||
}
|
||||
|
||||
function Sandbox() {
|
||||
var sandbox = this;
|
||||
var collection = [];
|
||||
var fakeRestorers = [];
|
||||
var promiseLib;
|
||||
|
||||
var collection = [];
|
||||
var loggedLeakWarning = false;
|
||||
sandbox.leakThreshold = DEFAULT_LEAK_THRESHOLD;
|
||||
|
||||
function addToCollection(object) {
|
||||
if (
|
||||
push(collection, object) > sandbox.leakThreshold &&
|
||||
!loggedLeakWarning
|
||||
) {
|
||||
// eslint-disable-next-line no-console
|
||||
logger.printWarning(
|
||||
"Potential memory leak detected; be sure to call restore() to clean up your sandbox. To suppress this warning, modify the leakThreshold property of your sandbox."
|
||||
);
|
||||
loggedLeakWarning = true;
|
||||
}
|
||||
}
|
||||
|
||||
sandbox.assert = sinonAssert.createAssertObject();
|
||||
|
||||
sandbox.serverPrototype = fakeServer;
|
||||
|
||||
// this is for testing only
|
||||
|
|
@ -45,7 +66,7 @@ function Sandbox() {
|
|||
};
|
||||
|
||||
// this is for testing only
|
||||
sandbox.getRestorers = function() {
|
||||
sandbox.getRestorers = function () {
|
||||
return fakeRestorers;
|
||||
};
|
||||
|
||||
|
|
@ -54,8 +75,8 @@ function Sandbox() {
|
|||
|
||||
var ownMethods = collectOwnMethods(stubbed);
|
||||
|
||||
forEach(ownMethods, function(method) {
|
||||
push(collection, method);
|
||||
forEach(ownMethods, function (method) {
|
||||
addToCollection(method);
|
||||
});
|
||||
|
||||
usePromiseLibrary(promiseLib, ownMethods);
|
||||
|
|
@ -64,35 +85,35 @@ function Sandbox() {
|
|||
};
|
||||
|
||||
sandbox.inject = function inject(obj) {
|
||||
obj.spy = function() {
|
||||
obj.spy = function () {
|
||||
return sandbox.spy.apply(null, arguments);
|
||||
};
|
||||
|
||||
obj.stub = function() {
|
||||
obj.stub = function () {
|
||||
return sandbox.stub.apply(null, arguments);
|
||||
};
|
||||
|
||||
obj.mock = function() {
|
||||
obj.mock = function () {
|
||||
return sandbox.mock.apply(null, arguments);
|
||||
};
|
||||
|
||||
obj.createStubInstance = function() {
|
||||
obj.createStubInstance = function () {
|
||||
return sandbox.createStubInstance.apply(sandbox, arguments);
|
||||
};
|
||||
|
||||
obj.fake = function() {
|
||||
obj.fake = function () {
|
||||
return sandbox.fake.apply(null, arguments);
|
||||
};
|
||||
|
||||
obj.replace = function() {
|
||||
obj.replace = function () {
|
||||
return sandbox.replace.apply(null, arguments);
|
||||
};
|
||||
|
||||
obj.replaceSetter = function() {
|
||||
obj.replaceSetter = function () {
|
||||
return sandbox.replaceSetter.apply(null, arguments);
|
||||
};
|
||||
|
||||
obj.replaceGetter = function() {
|
||||
obj.replaceGetter = function () {
|
||||
return sandbox.replaceGetter.apply(null, arguments);
|
||||
};
|
||||
|
||||
|
|
@ -113,7 +134,7 @@ function Sandbox() {
|
|||
sandbox.mock = function mock() {
|
||||
var m = sinonMock.apply(null, arguments);
|
||||
|
||||
push(collection, m);
|
||||
addToCollection(m);
|
||||
usePromiseLibrary(promiseLib, m);
|
||||
|
||||
return m;
|
||||
|
|
@ -136,7 +157,7 @@ function Sandbox() {
|
|||
}
|
||||
}
|
||||
|
||||
forEach(collection, function(fake) {
|
||||
forEach(collection, function (fake) {
|
||||
if (typeof fake === "function") {
|
||||
privateResetHistory(fake);
|
||||
return;
|
||||
|
|
@ -157,14 +178,16 @@ function Sandbox() {
|
|||
|
||||
sandbox.restore = function restore() {
|
||||
if (arguments.length) {
|
||||
throw new Error("sandbox.restore() does not take any parameters. Perhaps you meant stub.restore()");
|
||||
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) {
|
||||
forEach(fakeRestorers, function (restorer) {
|
||||
restorer();
|
||||
});
|
||||
fakeRestorers = [];
|
||||
|
|
@ -180,7 +203,7 @@ function Sandbox() {
|
|||
return;
|
||||
}
|
||||
|
||||
forEach(injectedKeys, function(injectedKey) {
|
||||
forEach(injectedKeys, function (injectedKey) {
|
||||
delete injectInto[injectedKey];
|
||||
});
|
||||
|
||||
|
|
@ -203,9 +226,14 @@ function Sandbox() {
|
|||
}
|
||||
|
||||
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");
|
||||
forEach(fakeRestorers, function (fakeRestorer) {
|
||||
if (
|
||||
fakeRestorer.object === object &&
|
||||
fakeRestorer.property === property
|
||||
) {
|
||||
throw new TypeError(
|
||||
`Attempted to replace ${property} which is already replaced`
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -214,7 +242,11 @@ function Sandbox() {
|
|||
var descriptor = getPropertyDescriptor(object, property);
|
||||
|
||||
if (typeof descriptor === "undefined") {
|
||||
throw new TypeError("Cannot replace non-existent property " + valueToString(property));
|
||||
throw new TypeError(
|
||||
`Cannot replace non-existent property ${valueToString(
|
||||
property
|
||||
)}`
|
||||
);
|
||||
}
|
||||
|
||||
if (typeof replacement === "undefined") {
|
||||
|
|
@ -230,7 +262,11 @@ function Sandbox() {
|
|||
}
|
||||
|
||||
if (typeof object[property] !== typeof replacement) {
|
||||
throw new TypeError("Cannot replace " + typeof object[property] + " with " + typeof replacement);
|
||||
throw new TypeError(
|
||||
`Cannot replace ${typeof object[
|
||||
property
|
||||
]} with ${typeof replacement}`
|
||||
);
|
||||
}
|
||||
|
||||
verifyNotReplaced(object, property);
|
||||
|
|
@ -243,15 +279,25 @@ function Sandbox() {
|
|||
return replacement;
|
||||
};
|
||||
|
||||
sandbox.replaceGetter = function replaceGetter(object, property, replacement) {
|
||||
sandbox.replaceGetter = function replaceGetter(
|
||||
object,
|
||||
property,
|
||||
replacement
|
||||
) {
|
||||
var descriptor = getPropertyDescriptor(object, property);
|
||||
|
||||
if (typeof descriptor === "undefined") {
|
||||
throw new TypeError("Cannot replace non-existent property " + valueToString(property));
|
||||
throw new TypeError(
|
||||
`Cannot replace non-existent property ${valueToString(
|
||||
property
|
||||
)}`
|
||||
);
|
||||
}
|
||||
|
||||
if (typeof replacement !== "function") {
|
||||
throw new TypeError("Expected replacement argument to be a function");
|
||||
throw new TypeError(
|
||||
"Expected replacement argument to be a function"
|
||||
);
|
||||
}
|
||||
|
||||
if (typeof descriptor.get !== "function") {
|
||||
|
|
@ -265,21 +311,31 @@ function Sandbox() {
|
|||
|
||||
Object.defineProperty(object, property, {
|
||||
get: replacement,
|
||||
configurable: isPropertyConfigurable(object, property)
|
||||
configurable: isPropertyConfigurable(object, property),
|
||||
});
|
||||
|
||||
return replacement;
|
||||
};
|
||||
|
||||
sandbox.replaceSetter = function replaceSetter(object, property, replacement) {
|
||||
sandbox.replaceSetter = function replaceSetter(
|
||||
object,
|
||||
property,
|
||||
replacement
|
||||
) {
|
||||
var descriptor = getPropertyDescriptor(object, property);
|
||||
|
||||
if (typeof descriptor === "undefined") {
|
||||
throw new TypeError("Cannot replace non-existent property " + valueToString(property));
|
||||
throw new TypeError(
|
||||
`Cannot replace non-existent property ${valueToString(
|
||||
property
|
||||
)}`
|
||||
);
|
||||
}
|
||||
|
||||
if (typeof replacement !== "function") {
|
||||
throw new TypeError("Expected replacement argument to be a function");
|
||||
throw new TypeError(
|
||||
"Expected replacement argument to be a function"
|
||||
);
|
||||
}
|
||||
|
||||
if (typeof descriptor.set !== "function") {
|
||||
|
|
@ -294,7 +350,7 @@ function Sandbox() {
|
|||
// eslint-disable-next-line accessor-pairs
|
||||
Object.defineProperty(object, property, {
|
||||
set: replacement,
|
||||
configurable: isPropertyConfigurable(object, property)
|
||||
configurable: isPropertyConfigurable(object, property),
|
||||
});
|
||||
|
||||
return replacement;
|
||||
|
|
@ -304,18 +360,19 @@ function Sandbox() {
|
|||
var object = args[0];
|
||||
var property = args[1];
|
||||
|
||||
var isSpyingOnEntireObject = typeof property === "undefined" && typeof object === "object";
|
||||
var isSpyingOnEntireObject =
|
||||
typeof property === "undefined" && typeof object === "object";
|
||||
|
||||
if (isSpyingOnEntireObject) {
|
||||
var ownMethods = collectOwnMethods(spy);
|
||||
|
||||
forEach(ownMethods, function(method) {
|
||||
push(collection, method);
|
||||
forEach(ownMethods, function (method) {
|
||||
addToCollection(method);
|
||||
});
|
||||
|
||||
usePromiseLibrary(promiseLib, ownMethods);
|
||||
} else {
|
||||
push(collection, spy);
|
||||
addToCollection(spy);
|
||||
usePromiseLibrary(promiseLib, spy);
|
||||
}
|
||||
|
||||
|
|
@ -336,18 +393,18 @@ function Sandbox() {
|
|||
sandbox.fake = function fake(f) {
|
||||
var s = sinonFake.apply(sinonFake, arguments);
|
||||
|
||||
push(collection, s);
|
||||
addToCollection(s);
|
||||
|
||||
return s;
|
||||
};
|
||||
|
||||
forEach(Object.keys(sinonFake), function(key) {
|
||||
forEach(Object.keys(sinonFake), function (key) {
|
||||
var fakeBehavior = sinonFake[key];
|
||||
if (typeof fakeBehavior === "function") {
|
||||
sandbox.fake[key] = function() {
|
||||
sandbox.fake[key] = function () {
|
||||
var s = fakeBehavior.apply(fakeBehavior, arguments);
|
||||
|
||||
push(collection, s);
|
||||
addToCollection(s);
|
||||
|
||||
return s;
|
||||
};
|
||||
|
|
@ -358,7 +415,7 @@ function Sandbox() {
|
|||
var clock = sinonClock.useFakeTimers.call(null, args);
|
||||
|
||||
sandbox.clock = clock;
|
||||
push(collection, clock);
|
||||
addToCollection(clock);
|
||||
|
||||
return clock;
|
||||
};
|
||||
|
|
@ -391,14 +448,14 @@ function Sandbox() {
|
|||
}
|
||||
|
||||
sandbox.server = proto.create();
|
||||
push(collection, sandbox.server);
|
||||
addToCollection(sandbox.server);
|
||||
|
||||
return sandbox.server;
|
||||
};
|
||||
|
||||
sandbox.useFakeXMLHttpRequest = function useFakeXMLHttpRequest() {
|
||||
var xhr = fakeXhr.useFakeXMLHttpRequest();
|
||||
push(collection, xhr);
|
||||
addToCollection(xhr);
|
||||
return xhr;
|
||||
};
|
||||
|
||||
|
|
@ -410,7 +467,6 @@ function Sandbox() {
|
|||
};
|
||||
}
|
||||
|
||||
Sandbox.prototype.assert = sinonAssert;
|
||||
Sandbox.prototype.match = match;
|
||||
|
||||
module.exports = Sandbox;
|
||||
|
|
|
|||
78
node_modules/sinon/lib/sinon/spy-formatters.js
generated
vendored
78
node_modules/sinon/lib/sinon/spy-formatters.js
generated
vendored
|
|
@ -10,6 +10,7 @@ var jsDiff = require("diff");
|
|||
var join = arrayProto.join;
|
||||
var map = arrayProto.map;
|
||||
var push = arrayProto.push;
|
||||
var slice = arrayProto.slice;
|
||||
|
||||
function colorSinonMatchText(matcher, calledArg, calledArgMessage) {
|
||||
var calledArgumentMessage = calledArgMessage;
|
||||
|
|
@ -19,11 +20,11 @@ function colorSinonMatchText(matcher, calledArg, calledArgMessage) {
|
|||
calledArgumentMessage = color.green(calledArgumentMessage);
|
||||
}
|
||||
}
|
||||
return calledArgumentMessage + " " + matcher.message;
|
||||
return `${calledArgumentMessage} ${matcher.message}`;
|
||||
}
|
||||
|
||||
function colorDiffText(diff) {
|
||||
var objects = map(diff, function(part) {
|
||||
var objects = map(diff, function (part) {
|
||||
var text = part.value;
|
||||
if (part.added) {
|
||||
text = color.green(text);
|
||||
|
|
@ -38,33 +39,66 @@ function colorDiffText(diff) {
|
|||
return join(objects, "");
|
||||
}
|
||||
|
||||
function quoteStringValue(value) {
|
||||
if (typeof value === "string") {
|
||||
return JSON.stringify(value);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
c: function(spyInstance) {
|
||||
c: function (spyInstance) {
|
||||
return timesInWords(spyInstance.callCount);
|
||||
},
|
||||
|
||||
n: function(spyInstance) {
|
||||
// eslint-disable-next-line local-rules/no-prototype-methods
|
||||
n: function (spyInstance) {
|
||||
// eslint-disable-next-line @sinonjs/no-prototype-methods/no-prototype-methods
|
||||
return spyInstance.toString();
|
||||
},
|
||||
|
||||
D: function(spyInstance, args) {
|
||||
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) + ":";
|
||||
message += `\nCall ${i + 1}:`;
|
||||
}
|
||||
var calledArgs = spyInstance.getCall(i).args;
|
||||
for (var j = 0; j < calledArgs.length || j < args.length; ++j) {
|
||||
var expectedArgs = slice(args);
|
||||
|
||||
for (
|
||||
var j = 0;
|
||||
j < calledArgs.length || j < expectedArgs.length;
|
||||
++j
|
||||
) {
|
||||
if (calledArgs[j]) {
|
||||
calledArgs[j] = quoteStringValue(calledArgs[j]);
|
||||
}
|
||||
|
||||
if (expectedArgs[j]) {
|
||||
expectedArgs[j] = quoteStringValue(expectedArgs[j]);
|
||||
}
|
||||
|
||||
message += "\n";
|
||||
var calledArgMessage = j < calledArgs.length ? sinonFormat(calledArgs[j]) : "";
|
||||
if (match.isMatcher(args[j])) {
|
||||
message += colorSinonMatchText(args[j], calledArgs[j], calledArgMessage);
|
||||
|
||||
var calledArgMessage =
|
||||
j < calledArgs.length ? sinonFormat(calledArgs[j]) : "";
|
||||
if (match.isMatcher(expectedArgs[j])) {
|
||||
message += colorSinonMatchText(
|
||||
expectedArgs[j],
|
||||
calledArgs[j],
|
||||
calledArgMessage
|
||||
);
|
||||
} else {
|
||||
var expectedArgMessage = j < args.length ? sinonFormat(args[j]) : "";
|
||||
var diff = jsDiff.diffJson(calledArgMessage, expectedArgMessage);
|
||||
var expectedArgMessage =
|
||||
j < expectedArgs.length
|
||||
? sinonFormat(expectedArgs[j])
|
||||
: "";
|
||||
var diff = jsDiff.diffJson(
|
||||
calledArgMessage,
|
||||
expectedArgMessage
|
||||
);
|
||||
message += colorDiffText(diff);
|
||||
}
|
||||
}
|
||||
|
|
@ -73,22 +107,22 @@ module.exports = {
|
|||
return message;
|
||||
},
|
||||
|
||||
C: function(spyInstance) {
|
||||
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();
|
||||
// eslint-disable-next-line @sinonjs/no-prototype-methods/no-prototype-methods
|
||||
var stringifiedCall = ` ${spyInstance.getCall(i).toString()}`;
|
||||
if (/\n/.test(calls[i - 1])) {
|
||||
stringifiedCall = "\n" + stringifiedCall;
|
||||
stringifiedCall = `\n${stringifiedCall}`;
|
||||
}
|
||||
push(calls, stringifiedCall);
|
||||
}
|
||||
|
||||
return calls.length > 0 ? "\n" + join(calls, "\n") : "";
|
||||
return calls.length > 0 ? `\n${join(calls, "\n")}` : "";
|
||||
},
|
||||
|
||||
t: function(spyInstance) {
|
||||
t: function (spyInstance) {
|
||||
var objects = [];
|
||||
|
||||
for (var i = 0, l = spyInstance.callCount; i < l; ++i) {
|
||||
|
|
@ -98,12 +132,12 @@ module.exports = {
|
|||
return join(objects, ", ");
|
||||
},
|
||||
|
||||
"*": function(spyInstance, args) {
|
||||
"*": function (spyInstance, args) {
|
||||
return join(
|
||||
map(args, function(arg) {
|
||||
map(args, function (arg) {
|
||||
return sinonFormat(arg);
|
||||
}),
|
||||
", "
|
||||
);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
|||
79
node_modules/sinon/lib/sinon/spy.js
generated
vendored
79
node_modules/sinon/lib/sinon/spy.js
generated
vendored
|
|
@ -23,7 +23,10 @@ var uuid = 0;
|
|||
|
||||
function matches(fake, args, strict) {
|
||||
var margs = fake.matchingArguments;
|
||||
if (margs.length <= args.length && deepEqual(slice(args, 0, margs.length), margs)) {
|
||||
if (
|
||||
margs.length <= args.length &&
|
||||
deepEqual(slice(args, 0, margs.length), margs)
|
||||
) {
|
||||
return !strict || margs.length === args.length;
|
||||
}
|
||||
return false;
|
||||
|
|
@ -31,7 +34,7 @@ function matches(fake, args, strict) {
|
|||
|
||||
// Public API
|
||||
var spyApi = {
|
||||
withArgs: function() {
|
||||
withArgs: function () {
|
||||
var args = slice(arguments);
|
||||
var matching = pop(this.matchingFakes(args, true));
|
||||
if (matching) {
|
||||
|
|
@ -44,11 +47,11 @@ var spyApi = {
|
|||
fake.parent = this;
|
||||
push(this.fakes, fake);
|
||||
|
||||
fake.withArgs = function() {
|
||||
fake.withArgs = function () {
|
||||
return original.withArgs.apply(original, arguments);
|
||||
};
|
||||
|
||||
forEach(original.args, function(arg, i) {
|
||||
forEach(original.args, function (arg, i) {
|
||||
if (!matches(fake, arg)) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -67,52 +70,72 @@ var spyApi = {
|
|||
},
|
||||
|
||||
// Override proxy default implementation
|
||||
matchingFakes: function(args, strict) {
|
||||
return filter.call(this.fakes, function(fake) {
|
||||
matchingFakes: function (args, strict) {
|
||||
return filter.call(this.fakes, function (fake) {
|
||||
return matches(fake, args, strict);
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
/* eslint-disable local-rules/no-prototype-methods */
|
||||
/* eslint-disable @sinonjs/no-prototype-methods/no-prototype-methods */
|
||||
var delegateToCalls = proxyCallUtil.delegateToCalls;
|
||||
delegateToCalls(spyApi, "callArg", false, "callArgWith", true, function() {
|
||||
throw new Error(this.toString() + " cannot call arg since it was not yet invoked.");
|
||||
delegateToCalls(spyApi, "callArg", false, "callArgWith", true, function () {
|
||||
throw new Error(
|
||||
`${this.toString()} cannot call arg since it was not yet invoked.`
|
||||
);
|
||||
});
|
||||
spyApi.callArgWith = spyApi.callArg;
|
||||
delegateToCalls(spyApi, "callArgOn", false, "callArgOnWith", true, function() {
|
||||
throw new Error(this.toString() + " cannot call arg since it was not yet invoked.");
|
||||
delegateToCalls(spyApi, "callArgOn", false, "callArgOnWith", true, function () {
|
||||
throw new Error(
|
||||
`${this.toString()} cannot call arg since it was not yet invoked.`
|
||||
);
|
||||
});
|
||||
spyApi.callArgOnWith = spyApi.callArgOn;
|
||||
delegateToCalls(spyApi, "throwArg", false, "throwArg", false, function() {
|
||||
throw new Error(this.toString() + " cannot throw arg since it was not yet invoked.");
|
||||
delegateToCalls(spyApi, "throwArg", false, "throwArg", false, function () {
|
||||
throw new Error(
|
||||
`${this.toString()} cannot throw arg since it was not yet invoked.`
|
||||
);
|
||||
});
|
||||
delegateToCalls(spyApi, "yield", false, "yield", true, function() {
|
||||
throw new Error(this.toString() + " cannot yield since it was not yet invoked.");
|
||||
delegateToCalls(spyApi, "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(spyApi, "yieldOn", false, "yieldOn", true, function() {
|
||||
throw new Error(this.toString() + " cannot yield since it was not yet invoked.");
|
||||
});
|
||||
delegateToCalls(spyApi, "yieldTo", false, "yieldTo", true, function(property) {
|
||||
delegateToCalls(spyApi, "yieldOn", false, "yieldOn", true, function () {
|
||||
throw new Error(
|
||||
this.toString() + " cannot yield to '" + valueToString(property) + "' since it was not yet invoked."
|
||||
`${this.toString()} cannot yield since it was not yet invoked.`
|
||||
);
|
||||
});
|
||||
delegateToCalls(spyApi, "yieldToOn", false, "yieldToOn", true, function(property) {
|
||||
delegateToCalls(spyApi, "yieldTo", false, "yieldTo", true, function (property) {
|
||||
throw new Error(
|
||||
this.toString() + " cannot yield to '" + valueToString(property) + "' since it was not yet invoked."
|
||||
`${this.toString()} cannot yield to '${valueToString(
|
||||
property
|
||||
)}' since it was not yet invoked.`
|
||||
);
|
||||
});
|
||||
/* eslint-enable local-rules/no-prototype-methods */
|
||||
delegateToCalls(
|
||||
spyApi,
|
||||
"yieldToOn",
|
||||
false,
|
||||
"yieldToOn",
|
||||
true,
|
||||
function (property) {
|
||||
throw new Error(
|
||||
`${this.toString()} cannot yield to '${valueToString(
|
||||
property
|
||||
)}' since it was not yet invoked.`
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
function createSpy(func) {
|
||||
var name;
|
||||
var funk = func;
|
||||
|
||||
if (typeof funk !== "function") {
|
||||
funk = function() {
|
||||
funk = function () {
|
||||
return;
|
||||
};
|
||||
} else {
|
||||
|
|
@ -127,7 +150,7 @@ function createSpy(func) {
|
|||
displayName: name || "spy",
|
||||
fakes: [],
|
||||
instantiateFake: createSpy,
|
||||
id: "spy#" + uuid++
|
||||
id: `spy#${uuid++}`,
|
||||
});
|
||||
return proxy;
|
||||
}
|
||||
|
|
@ -148,7 +171,7 @@ function spy(object, property, types) {
|
|||
}
|
||||
|
||||
if (!object && !property) {
|
||||
return createSpy(function() {
|
||||
return createSpy(function () {
|
||||
return;
|
||||
});
|
||||
}
|
||||
|
|
@ -160,7 +183,7 @@ function spy(object, property, types) {
|
|||
descriptor = {};
|
||||
methodDesc = getPropertyDescriptor(object, property);
|
||||
|
||||
forEach(types, function(type) {
|
||||
forEach(types, function (type) {
|
||||
descriptor[type] = createSpy(methodDesc[type]);
|
||||
});
|
||||
|
||||
|
|
|
|||
72
node_modules/sinon/lib/sinon/stub.js
generated
vendored
72
node_modules/sinon/lib/sinon/stub.js
generated
vendored
|
|
@ -5,7 +5,8 @@ var behavior = require("./behavior");
|
|||
var behaviors = require("./default-behaviors");
|
||||
var createProxy = require("./proxy");
|
||||
var functionName = require("@sinonjs/commons").functionName;
|
||||
var hasOwnProperty = require("@sinonjs/commons").prototypes.object.hasOwnProperty;
|
||||
var hasOwnProperty =
|
||||
require("@sinonjs/commons").prototypes.object.hasOwnProperty;
|
||||
var isNonExistentProperty = require("./util/core/is-non-existent-property");
|
||||
var spy = require("./spy");
|
||||
var extend = require("./util/core/extend");
|
||||
|
|
@ -32,8 +33,10 @@ function createStub(originalFunc) {
|
|||
|
||||
var fnStub =
|
||||
pop(
|
||||
sort(matchings, function(a, b) {
|
||||
return a.matchingArguments.length - b.matchingArguments.length;
|
||||
sort(matchings, function (a, b) {
|
||||
return (
|
||||
a.matchingArguments.length - b.matchingArguments.length
|
||||
);
|
||||
})
|
||||
) || proxy;
|
||||
return getCurrentBehavior(fnStub).invoke(this, arguments);
|
||||
|
|
@ -52,7 +55,7 @@ function createStub(originalFunc) {
|
|||
displayName: name || "stub",
|
||||
defaultBehavior: null,
|
||||
behaviors: [],
|
||||
id: "stub#" + uuid++
|
||||
id: `stub#${uuid++}`,
|
||||
});
|
||||
|
||||
return proxy;
|
||||
|
|
@ -60,7 +63,9 @@ function createStub(originalFunc) {
|
|||
|
||||
function stub(object, property) {
|
||||
if (arguments.length > 2) {
|
||||
throw new TypeError("stub(obj, 'meth', fn) has been removed, see documentation");
|
||||
throw new TypeError(
|
||||
"stub(obj, 'meth', fn) has been removed, see documentation"
|
||||
);
|
||||
}
|
||||
|
||||
if (isEsModule(object)) {
|
||||
|
|
@ -70,18 +75,22 @@ function stub(object, property) {
|
|||
throwOnFalsyObject.apply(null, arguments);
|
||||
|
||||
if (isNonExistentProperty(object, property)) {
|
||||
throw new TypeError("Cannot stub non-existent property " + valueToString(property));
|
||||
throw new TypeError(
|
||||
`Cannot stub non-existent property ${valueToString(property)}`
|
||||
);
|
||||
}
|
||||
|
||||
var actualDescriptor = getPropertyDescriptor(object, property);
|
||||
var isObjectOrFunction = typeof object === "object" || typeof object === "function";
|
||||
var isStubbingEntireObject = typeof property === "undefined" && isObjectOrFunction;
|
||||
var isObjectOrFunction =
|
||||
typeof object === "object" || typeof object === "function";
|
||||
var isStubbingEntireObject =
|
||||
typeof property === "undefined" && isObjectOrFunction;
|
||||
var isCreatingNewStub = !object && typeof property === "undefined";
|
||||
var isStubbingNonFuncProperty =
|
||||
isObjectOrFunction &&
|
||||
typeof property !== "undefined" &&
|
||||
(typeof actualDescriptor === "undefined" || typeof actualDescriptor.value !== "function") &&
|
||||
typeof descriptor === "undefined";
|
||||
(typeof actualDescriptor === "undefined" ||
|
||||
typeof actualDescriptor.value !== "function");
|
||||
|
||||
if (isStubbingEntireObject) {
|
||||
return walkObject(stub, object);
|
||||
|
|
@ -91,7 +100,10 @@ function stub(object, property) {
|
|||
return createStub();
|
||||
}
|
||||
|
||||
var func = typeof actualDescriptor.value === "function" ? actualDescriptor.value : null;
|
||||
var func =
|
||||
typeof actualDescriptor.value === "function"
|
||||
? actualDescriptor.value
|
||||
: null;
|
||||
var s = createStub(func);
|
||||
|
||||
extend.nonEnum(s, {
|
||||
|
|
@ -105,20 +117,20 @@ function stub(object, property) {
|
|||
}
|
||||
|
||||
delete object[property];
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
return isStubbingNonFuncProperty ? s : wrapMethod(object, property, s);
|
||||
}
|
||||
|
||||
stub.createStubInstance = function(constructor, overrides) {
|
||||
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) {
|
||||
forEach(Object.keys(overrides || {}), function (propertyName) {
|
||||
if (propertyName in stubbedObject) {
|
||||
var value = overrides[propertyName];
|
||||
if (value && value.createStubInstance) {
|
||||
|
|
@ -127,7 +139,9 @@ stub.createStubInstance = function(constructor, overrides) {
|
|||
stubbedObject[propertyName].returns(value);
|
||||
}
|
||||
} else {
|
||||
throw new Error("Cannot stub " + propertyName + ". Property does not exist!");
|
||||
throw new Error(
|
||||
`Cannot stub ${propertyName}. Property does not exist!`
|
||||
);
|
||||
}
|
||||
});
|
||||
return stubbedObject;
|
||||
|
|
@ -139,17 +153,23 @@ function getParentBehaviour(stubInstance) {
|
|||
}
|
||||
|
||||
function getDefaultBehavior(stubInstance) {
|
||||
return stubInstance.defaultBehavior || getParentBehaviour(stubInstance) || behavior.create(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);
|
||||
return currentBehavior && currentBehavior.isPresent()
|
||||
? currentBehavior
|
||||
: getDefaultBehavior(stubInstance);
|
||||
}
|
||||
/*eslint-enable no-use-before-define*/
|
||||
|
||||
var proto = {
|
||||
resetBehavior: function() {
|
||||
resetBehavior: function () {
|
||||
this.defaultBehavior = null;
|
||||
this.behaviors = [];
|
||||
|
||||
|
|
@ -161,12 +181,12 @@ var proto = {
|
|||
this.returnThis = false;
|
||||
this.resolveThis = false;
|
||||
|
||||
forEach(this.fakes, function(fake) {
|
||||
forEach(this.fakes, function (fake) {
|
||||
fake.resetBehavior();
|
||||
});
|
||||
},
|
||||
|
||||
reset: function() {
|
||||
reset: function () {
|
||||
this.resetHistory();
|
||||
this.resetBehavior();
|
||||
},
|
||||
|
|
@ -194,14 +214,16 @@ var proto = {
|
|||
withArgs: function withArgs() {
|
||||
var fake = spy.withArgs.apply(this, arguments);
|
||||
if (this.defaultBehavior && this.defaultBehavior.promiseLibrary) {
|
||||
fake.defaultBehavior = fake.defaultBehavior || behavior.create(fake);
|
||||
fake.defaultBehavior.promiseLibrary = this.defaultBehavior.promiseLibrary;
|
||||
fake.defaultBehavior =
|
||||
fake.defaultBehavior || behavior.create(fake);
|
||||
fake.defaultBehavior.promiseLibrary =
|
||||
this.defaultBehavior.promiseLibrary;
|
||||
}
|
||||
return fake;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
forEach(Object.keys(behavior), function(method) {
|
||||
forEach(Object.keys(behavior), function (method) {
|
||||
if (
|
||||
hasOwnProperty(behavior, method) &&
|
||||
!hasOwnProperty(proto, method) &&
|
||||
|
|
@ -212,7 +234,7 @@ forEach(Object.keys(behavior), function(method) {
|
|||
}
|
||||
});
|
||||
|
||||
forEach(Object.keys(behaviors), function(method) {
|
||||
forEach(Object.keys(behaviors), function (method) {
|
||||
if (hasOwnProperty(behaviors, method) && !hasOwnProperty(proto, method)) {
|
||||
behavior.addBehavior(stub, method, behaviors[method]);
|
||||
}
|
||||
|
|
|
|||
4
node_modules/sinon/lib/sinon/throw-on-falsy-object.js
generated
vendored
4
node_modules/sinon/lib/sinon/throw-on-falsy-object.js
generated
vendored
|
|
@ -4,7 +4,9 @@ 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);
|
||||
throw new Error(
|
||||
`Trying to stub property '${valueToString(property)}' of ${type}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
4
node_modules/sinon/lib/sinon/util/core/default-config.js
generated
vendored
4
node_modules/sinon/lib/sinon/util/core/default-config.js
generated
vendored
|
|
@ -13,8 +13,8 @@ module.exports = {
|
|||
"replace",
|
||||
"replaceSetter",
|
||||
"replaceGetter",
|
||||
"createStubInstance"
|
||||
"createStubInstance",
|
||||
],
|
||||
useFakeTimers: true,
|
||||
useFakeServer: true
|
||||
useFakeServer: true,
|
||||
};
|
||||
|
|
|
|||
4
node_modules/sinon/lib/sinon/util/core/export-async-behaviors.js
generated
vendored
4
node_modules/sinon/lib/sinon/util/core/export-async-behaviors.js
generated
vendored
|
|
@ -6,10 +6,10 @@ var reduce = arrayProto.reduce;
|
|||
module.exports = function exportAsyncBehaviors(behaviorMethods) {
|
||||
return reduce(
|
||||
Object.keys(behaviorMethods),
|
||||
function(acc, method) {
|
||||
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() {
|
||||
acc[`${method}Async`] = function () {
|
||||
var result = behaviorMethods[method].apply(this, arguments);
|
||||
this.callbackAsync = true;
|
||||
return result;
|
||||
|
|
|
|||
121
node_modules/sinon/lib/sinon/util/core/extend.js
generated
vendored
121
node_modules/sinon/lib/sinon/util/core/extend.js
generated
vendored
|
|
@ -1,45 +1,45 @@
|
|||
"use strict";
|
||||
|
||||
var arrayProto = require("@sinonjs/commons").prototypes.array;
|
||||
var hasOwnProperty = require("@sinonjs/commons").prototypes.object.hasOwnProperty;
|
||||
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 hasDontEnumBug = (function () {
|
||||
var obj = {
|
||||
constructor: function() {
|
||||
constructor: function () {
|
||||
return "0";
|
||||
},
|
||||
toString: function() {
|
||||
toString: function () {
|
||||
return "1";
|
||||
},
|
||||
valueOf: function() {
|
||||
valueOf: function () {
|
||||
return "2";
|
||||
},
|
||||
toLocaleString: function() {
|
||||
toLocaleString: function () {
|
||||
return "3";
|
||||
},
|
||||
prototype: function() {
|
||||
prototype: function () {
|
||||
return "4";
|
||||
},
|
||||
isPrototypeOf: function() {
|
||||
isPrototypeOf: function () {
|
||||
return "5";
|
||||
},
|
||||
propertyIsEnumerable: function() {
|
||||
propertyIsEnumerable: function () {
|
||||
return "6";
|
||||
},
|
||||
hasOwnProperty: function() {
|
||||
hasOwnProperty: function () {
|
||||
return "7";
|
||||
},
|
||||
length: function() {
|
||||
length: function () {
|
||||
return "8";
|
||||
},
|
||||
unique: function() {
|
||||
unique: function () {
|
||||
return "9";
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
var result = [];
|
||||
|
|
@ -65,7 +65,11 @@ function extendCommon(target, sources, doCopy) {
|
|||
|
||||
// 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) {
|
||||
if (
|
||||
hasDontEnumBug &&
|
||||
hasOwnProperty(source, "toString") &&
|
||||
source.toString !== target.toString
|
||||
) {
|
||||
target.toString = source.toString;
|
||||
}
|
||||
}
|
||||
|
|
@ -73,39 +77,78 @@ function extendCommon(target, sources, doCopy) {
|
|||
return target;
|
||||
}
|
||||
|
||||
/** Public: Extend target in place with all (own) properties from sources in-order. Thus, last source will
|
||||
* override properties in previous sources.
|
||||
/** Public: Extend target in place with all (own) properties, except 'name' when [[writable]] is false,
|
||||
* 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.
|
||||
* @param {object} target - The Object to extend
|
||||
* @param {object[]} sources - Objects to copy properties from.
|
||||
*
|
||||
* @returns {Object} the extended target
|
||||
* @returns {object} the extended target
|
||||
*/
|
||||
module.exports = function extend(target /*, sources */) {
|
||||
var sources = slice(arguments, 1);
|
||||
module.exports = function extend(target, ...sources) {
|
||||
return extendCommon(
|
||||
target,
|
||||
sources,
|
||||
function copyValue(dest, source, prop) {
|
||||
var destOwnPropertyDescriptor = Object.getOwnPropertyDescriptor(
|
||||
dest,
|
||||
prop
|
||||
);
|
||||
var sourceOwnPropertyDescriptor = Object.getOwnPropertyDescriptor(
|
||||
source,
|
||||
prop
|
||||
);
|
||||
|
||||
return extendCommon(target, sources, function copyValue(dest, source, prop) {
|
||||
dest[prop] = source[prop];
|
||||
});
|
||||
if (prop === "name" && !destOwnPropertyDescriptor.writable) {
|
||||
return;
|
||||
}
|
||||
const descriptors = {
|
||||
configurable: sourceOwnPropertyDescriptor.configurable,
|
||||
enumerable: sourceOwnPropertyDescriptor.enumerable,
|
||||
};
|
||||
/*
|
||||
if the sorce has an Accessor property copy over the accessor functions (get and set)
|
||||
data properties has writable attribute where as acessor property don't
|
||||
REF: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#properties
|
||||
*/
|
||||
|
||||
if (hasOwnProperty(sourceOwnPropertyDescriptor, "writable")) {
|
||||
descriptors.writable = sourceOwnPropertyDescriptor.writable;
|
||||
descriptors.value = sourceOwnPropertyDescriptor.value;
|
||||
} else {
|
||||
if (sourceOwnPropertyDescriptor.get) {
|
||||
descriptors.get =
|
||||
sourceOwnPropertyDescriptor.get.bind(dest);
|
||||
}
|
||||
if (sourceOwnPropertyDescriptor.set) {
|
||||
descriptors.set =
|
||||
sourceOwnPropertyDescriptor.set.bind(dest);
|
||||
}
|
||||
}
|
||||
Object.defineProperty(dest, prop, descriptors);
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
/** 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.
|
||||
* @param {object} target - The Object to extend
|
||||
* @param {object[]} sources - Objects to copy properties from.
|
||||
*
|
||||
* @returns {Object} the extended target
|
||||
* @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
|
||||
});
|
||||
});
|
||||
module.exports.nonEnum = function extendNonEnum(target, ...sources) {
|
||||
return extendCommon(
|
||||
target,
|
||||
sources,
|
||||
function copyProperty(dest, source, prop) {
|
||||
Object.defineProperty(dest, prop, {
|
||||
value: source[prop],
|
||||
enumerable: false,
|
||||
configurable: true,
|
||||
writable: true,
|
||||
});
|
||||
}
|
||||
);
|
||||
};
|
||||
|
|
|
|||
12
node_modules/sinon/lib/sinon/util/core/format.js
generated
vendored
12
node_modules/sinon/lib/sinon/util/core/format.js
generated
vendored
|
|
@ -1,12 +1,6 @@
|
|||
"use strict";
|
||||
|
||||
var formatio = require("@sinonjs/formatio");
|
||||
|
||||
var formatter = formatio.configure({
|
||||
quoteStrings: false,
|
||||
limitChildrenCount: 250
|
||||
});
|
||||
|
||||
var inspect = require("util").inspect;
|
||||
var customFormatter;
|
||||
|
||||
function format() {
|
||||
|
|
@ -14,10 +8,10 @@ function format() {
|
|||
return customFormatter.apply(null, arguments);
|
||||
}
|
||||
|
||||
return formatter.ascii.apply(formatter, arguments);
|
||||
return inspect.apply(inspect, arguments);
|
||||
}
|
||||
|
||||
format.setFormatter = function(aCustomFormatter) {
|
||||
format.setFormatter = function (aCustomFormatter) {
|
||||
if (typeof aCustomFormatter !== "function") {
|
||||
throw new Error("format.setFormatter must be called with a function");
|
||||
}
|
||||
|
|
|
|||
7
node_modules/sinon/lib/sinon/util/core/get-config.js
generated
vendored
7
node_modules/sinon/lib/sinon/util/core/get-config.js
generated
vendored
|
|
@ -1,7 +1,8 @@
|
|||
"use strict";
|
||||
|
||||
var defaultConfig = require("./default-config");
|
||||
var hasOwnProperty = require("@sinonjs/commons").prototypes.object.hasOwnProperty;
|
||||
var hasOwnProperty =
|
||||
require("@sinonjs/commons").prototypes.object.hasOwnProperty;
|
||||
|
||||
module.exports = function getConfig(custom) {
|
||||
var config = {};
|
||||
|
|
@ -10,7 +11,9 @@ module.exports = function getConfig(custom) {
|
|||
|
||||
for (prop in defaultConfig) {
|
||||
if (hasOwnProperty(defaultConfig, prop)) {
|
||||
config[prop] = hasOwnProperty(kustom, prop) ? kustom[prop] : defaultConfig[prop];
|
||||
config[prop] = hasOwnProperty(kustom, prop)
|
||||
? kustom[prop]
|
||||
: defaultConfig[prop];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
9
node_modules/sinon/lib/sinon/util/core/get-property-descriptor.js
generated
vendored
9
node_modules/sinon/lib/sinon/util/core/get-property-descriptor.js
generated
vendored
|
|
@ -3,9 +3,14 @@
|
|||
module.exports = function getPropertyDescriptor(object, property) {
|
||||
var proto = object;
|
||||
var descriptor;
|
||||
var isOwn = Boolean(object && Object.getOwnPropertyDescriptor(object, property));
|
||||
var isOwn = Boolean(
|
||||
object && Object.getOwnPropertyDescriptor(object, property)
|
||||
);
|
||||
|
||||
while (proto && !(descriptor = Object.getOwnPropertyDescriptor(proto, property))) {
|
||||
while (
|
||||
proto &&
|
||||
!(descriptor = Object.getOwnPropertyDescriptor(proto, property))
|
||||
) {
|
||||
proto = Object.getPrototypeOf(proto);
|
||||
}
|
||||
|
||||
|
|
|
|||
11
node_modules/sinon/lib/sinon/util/core/is-es-module.js
generated
vendored
11
node_modules/sinon/lib/sinon/util/core/is-es-module.js
generated
vendored
|
|
@ -7,12 +7,15 @@
|
|||
* using spies or stubs. Let the consumer know this to avoid bug reports
|
||||
* on weird error messages.
|
||||
*
|
||||
* @param {Object} object The object to examine
|
||||
* @param {object} object The object to examine
|
||||
*
|
||||
* @returns {Boolean} true when the object is a module
|
||||
* @returns {boolean} true when the object is a module
|
||||
*/
|
||||
module.exports = function(object) {
|
||||
module.exports = function (object) {
|
||||
return (
|
||||
object && typeof Symbol !== "undefined" && object[Symbol.toStringTag] === "Module" && Object.isSealed(object)
|
||||
object &&
|
||||
typeof Symbol !== "undefined" &&
|
||||
object[Symbol.toStringTag] === "Module" &&
|
||||
Object.isSealed(object)
|
||||
);
|
||||
};
|
||||
|
|
|
|||
8
node_modules/sinon/lib/sinon/util/core/is-non-existent-property.js
generated
vendored
8
node_modules/sinon/lib/sinon/util/core/is-non-existent-property.js
generated
vendored
|
|
@ -2,11 +2,13 @@
|
|||
|
||||
/**
|
||||
* @param {*} object
|
||||
* @param {String} property
|
||||
* @returns whether a prop exists in the prototype chain
|
||||
* @param {string} property
|
||||
* @returns {boolean} whether a prop exists in the prototype chain
|
||||
*/
|
||||
function isNonExistentProperty(object, property) {
|
||||
return object && typeof property !== "undefined" && !(property in object);
|
||||
return Boolean(
|
||||
object && typeof property !== "undefined" && !(property in object)
|
||||
);
|
||||
}
|
||||
|
||||
module.exports = isNonExistentProperty;
|
||||
|
|
|
|||
6
node_modules/sinon/lib/sinon/util/core/is-restorable.js
generated
vendored
6
node_modules/sinon/lib/sinon/util/core/is-restorable.js
generated
vendored
|
|
@ -1,7 +1,11 @@
|
|||
"use strict";
|
||||
|
||||
function isRestorable(obj) {
|
||||
return typeof obj === "function" && typeof obj.restore === "function" && obj.restore.sinon;
|
||||
return (
|
||||
typeof obj === "function" &&
|
||||
typeof obj.restore === "function" &&
|
||||
obj.restore.sinon
|
||||
);
|
||||
}
|
||||
|
||||
module.exports = isRestorable;
|
||||
|
|
|
|||
2
node_modules/sinon/lib/sinon/util/core/restore.js
generated
vendored
2
node_modules/sinon/lib/sinon/util/core/restore.js
generated
vendored
|
|
@ -5,7 +5,7 @@ var walk = require("./walk");
|
|||
|
||||
module.exports = function restore(object) {
|
||||
if (object !== null && typeof object === "object") {
|
||||
walk(object, function(prop) {
|
||||
walk(object, function (prop) {
|
||||
if (isRestorable(object[prop])) {
|
||||
object[prop].restore();
|
||||
}
|
||||
|
|
|
|||
2
node_modules/sinon/lib/sinon/util/core/times-in-words.js
generated
vendored
2
node_modules/sinon/lib/sinon/util/core/times-in-words.js
generated
vendored
|
|
@ -3,5 +3,5 @@
|
|||
var array = [null, "once", "twice", "thrice"];
|
||||
|
||||
module.exports = function timesInWords(count) {
|
||||
return array[count] || (count || 0) + " times";
|
||||
return array[count] || `${count || 0} times`;
|
||||
};
|
||||
|
|
|
|||
8
node_modules/sinon/lib/sinon/util/core/walk-object.js
generated
vendored
8
node_modules/sinon/lib/sinon/util/core/walk-object.js
generated
vendored
|
|
@ -10,10 +10,12 @@ function walkObject(predicate, object, filter) {
|
|||
var name = functionName(predicate);
|
||||
|
||||
if (!object) {
|
||||
throw new Error("Trying to " + name + " object but received " + String(object));
|
||||
throw new Error(
|
||||
`Trying to ${name} object but received ${String(object)}`
|
||||
);
|
||||
}
|
||||
|
||||
walk(object, function(prop, propOwner) {
|
||||
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 (
|
||||
|
|
@ -34,7 +36,7 @@ function walkObject(predicate, object, filter) {
|
|||
});
|
||||
|
||||
if (!called) {
|
||||
throw new Error("Expected to " + name + " methods on object but found none");
|
||||
throw new Error(`Expected to ${name} methods on object but found none`);
|
||||
}
|
||||
|
||||
return object;
|
||||
|
|
|
|||
8
node_modules/sinon/lib/sinon/util/core/walk.js
generated
vendored
8
node_modules/sinon/lib/sinon/util/core/walk.js
generated
vendored
|
|
@ -16,10 +16,14 @@ function walkInternal(obj, iterator, context, originalObj, seen) {
|
|||
return;
|
||||
}
|
||||
|
||||
forEach(Object.getOwnPropertyNames(obj), function(k) {
|
||||
forEach(Object.getOwnPropertyNames(obj), function (k) {
|
||||
if (seen[k] !== true) {
|
||||
seen[k] = true;
|
||||
var target = typeof Object.getOwnPropertyDescriptor(obj, k).get === "function" ? originalObj : obj;
|
||||
var target =
|
||||
typeof Object.getOwnPropertyDescriptor(obj, k).get ===
|
||||
"function"
|
||||
? originalObj
|
||||
: obj;
|
||||
iterator.call(context, k, target);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
161
node_modules/sinon/lib/sinon/util/core/wrap-method.js
generated
vendored
161
node_modules/sinon/lib/sinon/util/core/wrap-method.js
generated
vendored
|
|
@ -2,11 +2,16 @@
|
|||
|
||||
var getPropertyDescriptor = require("./get-property-descriptor");
|
||||
var extend = require("./extend");
|
||||
var hasOwnProperty = require("@sinonjs/commons").prototypes.object.hasOwnProperty;
|
||||
var hasOwnProperty =
|
||||
require("@sinonjs/commons").prototypes.object.hasOwnProperty;
|
||||
var valueToString = require("@sinonjs/commons").valueToString;
|
||||
var push = require("@sinonjs/commons").prototypes.array.push;
|
||||
|
||||
function isFunction(obj) {
|
||||
return typeof obj === "function" || Boolean(obj && obj.constructor && obj.call && obj.apply);
|
||||
return (
|
||||
typeof obj === "function" ||
|
||||
Boolean(obj && obj.constructor && obj.call && obj.apply)
|
||||
);
|
||||
}
|
||||
|
||||
function mirrorProperties(target, source) {
|
||||
|
|
@ -17,6 +22,21 @@ function mirrorProperties(target, source) {
|
|||
}
|
||||
}
|
||||
|
||||
function getAccessor(object, property, method) {
|
||||
var accessors = ["get", "set"];
|
||||
var descriptor = getPropertyDescriptor(object, property);
|
||||
|
||||
for (var i = 0; i < accessors.length; i++) {
|
||||
if (
|
||||
descriptor[accessors[i]] &&
|
||||
descriptor[accessors[i]].name === method.name
|
||||
) {
|
||||
return accessors[i];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Cheap way to detect if we have ES5 support.
|
||||
var hasES5Support = "keys" in Object;
|
||||
|
||||
|
|
@ -26,7 +46,9 @@ module.exports = function wrapMethod(object, property, method) {
|
|||
}
|
||||
|
||||
if (typeof method !== "function" && typeof method !== "object") {
|
||||
throw new TypeError("Method wrapper should be a function or a property descriptor");
|
||||
throw new TypeError(
|
||||
"Method wrapper should be a function or a property descriptor"
|
||||
);
|
||||
}
|
||||
|
||||
function checkWrappedMethod(wrappedMethod) {
|
||||
|
|
@ -34,24 +56,42 @@ module.exports = function wrapMethod(object, property, method) {
|
|||
|
||||
if (!isFunction(wrappedMethod)) {
|
||||
error = new TypeError(
|
||||
"Attempted to wrap " + typeof wrappedMethod + " property " + valueToString(property) + " as function"
|
||||
`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");
|
||||
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);
|
||||
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;
|
||||
error.stack += `\n--------------\n${wrappedMethod.stackTraceError.stack}`;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
var error, wrappedMethod, i, wrappedMethodDesc;
|
||||
var error,
|
||||
wrappedMethods,
|
||||
wrappedMethod,
|
||||
i,
|
||||
wrappedMethodDesc,
|
||||
target,
|
||||
accessor;
|
||||
|
||||
wrappedMethods = [];
|
||||
|
||||
function simplePropertyAssignment() {
|
||||
wrappedMethod = object[property];
|
||||
|
|
@ -61,23 +101,30 @@ module.exports = function wrapMethod(object, property, method) {
|
|||
}
|
||||
|
||||
// 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);
|
||||
var owned = object.hasOwnProperty
|
||||
? object.hasOwnProperty(property) // eslint-disable-line @sinonjs/no-prototype-methods/no-prototype-methods
|
||||
: hasOwnProperty(object, property);
|
||||
|
||||
if (hasES5Support) {
|
||||
var methodDesc = typeof method === "function" ? { value: method } : method;
|
||||
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"
|
||||
`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`
|
||||
);
|
||||
} 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;
|
||||
error.stack += `\n--------------\n${wrappedMethodDesc.stackTraceError.stack}`;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
|
|
@ -86,6 +133,7 @@ module.exports = function wrapMethod(object, property, method) {
|
|||
for (i = 0; i < types.length; i++) {
|
||||
wrappedMethod = wrappedMethodDesc[types[i]];
|
||||
checkWrappedMethod(wrappedMethod);
|
||||
push(wrappedMethods, wrappedMethod);
|
||||
}
|
||||
|
||||
mirrorProperties(methodDesc, wrappedMethodDesc);
|
||||
|
|
@ -106,49 +154,82 @@ module.exports = function wrapMethod(object, property, method) {
|
|||
simplePropertyAssignment();
|
||||
}
|
||||
|
||||
extend.nonEnum(method, {
|
||||
displayName: property,
|
||||
extendObjectWithWrappedMethods();
|
||||
|
||||
wrappedMethod: wrappedMethod,
|
||||
function extendObjectWithWrappedMethods() {
|
||||
for (i = 0; i < wrappedMethods.length; i++) {
|
||||
accessor = getAccessor(object, property, wrappedMethods[i]);
|
||||
target = accessor ? method[accessor] : method;
|
||||
extend.nonEnum(target, {
|
||||
displayName: property,
|
||||
wrappedMethod: wrappedMethods[i],
|
||||
|
||||
// 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"),
|
||||
// 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.
|
||||
restore: restore,
|
||||
});
|
||||
|
||||
target.restore.sinon = true;
|
||||
if (!hasES5Support) {
|
||||
mirrorProperties(target, wrappedMethod);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function restore() {
|
||||
accessor = getAccessor(object, property, this.wrappedMethod);
|
||||
var descriptor;
|
||||
// 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 (accessor) {
|
||||
if (!owned) {
|
||||
// In some cases `delete` may throw an error
|
||||
try {
|
||||
delete object[property];
|
||||
// In some cases `delete` may throw an error
|
||||
delete object[property][accessor];
|
||||
} 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) {
|
||||
descriptor = getPropertyDescriptor(object, property);
|
||||
descriptor[accessor] = wrappedMethodDesc[accessor];
|
||||
Object.defineProperty(object, property, descriptor);
|
||||
}
|
||||
|
||||
if (hasES5Support) {
|
||||
descriptor = getPropertyDescriptor(object, property);
|
||||
if (descriptor && descriptor.value === target) {
|
||||
object[property][accessor] = this.wrappedMethod;
|
||||
}
|
||||
} else {
|
||||
// Use strict equality comparison to check failures then force a reset
|
||||
// via direct assignment.
|
||||
if (object[property][accessor] === target) {
|
||||
object[property][accessor] = this.wrappedMethod;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!owned) {
|
||||
try {
|
||||
delete object[property];
|
||||
} catch (e) {} // eslint-disable-line no-empty
|
||||
} else if (hasES5Support) {
|
||||
Object.defineProperty(object, property, wrappedMethodDesc);
|
||||
}
|
||||
|
||||
if (hasES5Support) {
|
||||
var descriptor = getPropertyDescriptor(object, property);
|
||||
if (descriptor && descriptor.value === method) {
|
||||
object[property] = wrappedMethod;
|
||||
descriptor = getPropertyDescriptor(object, property);
|
||||
if (descriptor && descriptor.value === target) {
|
||||
object[property] = this.wrappedMethod;
|
||||
}
|
||||
} else {
|
||||
// Use strict equality comparison to check failures then force a reset
|
||||
// via direct assignment.
|
||||
if (object[property] === method) {
|
||||
object[property] = wrappedMethod;
|
||||
if (object[property] === target) {
|
||||
object[property] = this.wrappedMethod;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
method.restore.sinon = true;
|
||||
|
||||
if (!hasES5Support) {
|
||||
mirrorProperties(method, wrappedMethod);
|
||||
}
|
||||
|
||||
return method;
|
||||
|
|
|
|||
28
node_modules/sinon/lib/sinon/util/fake-timers.js
generated
vendored
28
node_modules/sinon/lib/sinon/util/fake-timers.js
generated
vendored
|
|
@ -22,24 +22,28 @@ function addIfDefined(obj, globalPropName) {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param {number|Date|Object} dateOrConfig The unix epoch value to install with (default 0)
|
||||
* @returns {Object} Returns a lolex clock instance
|
||||
* @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) {
|
||||
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;
|
||||
(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
|
||||
now: 0,
|
||||
});
|
||||
}
|
||||
|
||||
if (argumentIsDateLike) {
|
||||
return createClock({
|
||||
now: dateOrConfig
|
||||
now: dateOrConfig,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -50,13 +54,15 @@ exports.useFakeTimers = function(dateOrConfig) {
|
|||
return createClock(config, globalCtx);
|
||||
}
|
||||
|
||||
throw new TypeError("useFakeTimers expected epoch or config object. See https://github.com/sinonjs/sinon");
|
||||
throw new TypeError(
|
||||
"useFakeTimers expected epoch or config object. See https://github.com/sinonjs/sinon"
|
||||
);
|
||||
};
|
||||
|
||||
exports.clock = {
|
||||
create: function(now) {
|
||||
create: function (now) {
|
||||
return FakeTimers.createClock(now);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
var timers = {
|
||||
|
|
@ -64,7 +70,7 @@ var timers = {
|
|||
clearTimeout: clearTimeout,
|
||||
setInterval: setInterval,
|
||||
clearInterval: clearInterval,
|
||||
Date: Date
|
||||
Date: Date,
|
||||
};
|
||||
addIfDefined(timers, "setImmediate");
|
||||
addIfDefined(timers, "clearImmediate");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue