Socket
Socket
Sign inDemoInstall

sinon

Package Overview
Dependencies
Maintainers
4
Versions
208
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sinon - npm Package Compare versions

Comparing version 15.2.0 to 17.0.0

18

CONTRIBUTING.md

@@ -107,2 +107,18 @@ # Contributing to Sinon.JS

### Tooling
To transparently handle all issues with different tool versions we recommend using [_ASDF: The Multiple Runtime Manager_][asdf]. You would then need the Ruby and Node plugins.
<details>
```
asdf plugin add ruby
asdf plugin add nodejs
asdf install
```
</details>
[asdf]: https://asdf-vm.com
### Run the tests

@@ -137,2 +153,2 @@

$ node build.js
$ node build.cjs

67

lib/sinon.js

@@ -12,38 +12,51 @@ "use strict";

const apiMethods = {
createSandbox: createSandbox,
assert: require("./sinon/assert"),
match: require("@sinonjs/samsam").createMatcher,
restoreObject: require("./sinon/restore-object"),
/**
* @param {object} opts injection point to override the default XHR lib in testing
* @param {object} opts.sinonXhrLib
* @returns {object} a configured sandbox
*/
function createApi({ sinonXhrLib }) {
const apiMethods = {
createSandbox: createSandbox,
assert: require("./sinon/assert"),
match: require("@sinonjs/samsam").createMatcher,
restoreObject: require("./sinon/restore-object"),
expectation: require("./sinon/mock-expectation"),
defaultConfig: require("./sinon/util/core/default-config"),
expectation: require("./sinon/mock-expectation"),
defaultConfig: require("./sinon/util/core/default-config"),
// fake timers
timers: fakeTimers.timers,
// fake timers
timers: fakeTimers.timers,
// fake XHR
xhr: nise.fakeXhr.xhr,
FakeXMLHttpRequest: nise.fakeXhr.FakeXMLHttpRequest,
// fake XHR
xhr: sinonXhrLib.fakeXhr.xhr,
FakeXMLHttpRequest: sinonXhrLib.fakeXhr.FakeXMLHttpRequest,
// fake server
fakeServer: nise.fakeServer,
fakeServerWithClock: nise.fakeServerWithClock,
createFakeServer: nise.fakeServer.create.bind(nise.fakeServer),
createFakeServerWithClock: nise.fakeServerWithClock.create.bind(
nise.fakeServerWithClock
),
// fake server
fakeServer: sinonXhrLib.fakeServer,
fakeServerWithClock: sinonXhrLib.fakeServerWithClock,
createFakeServer: sinonXhrLib.fakeServer.create.bind(
sinonXhrLib.fakeServer,
),
createFakeServerWithClock: sinonXhrLib.fakeServerWithClock.create.bind(
sinonXhrLib.fakeServerWithClock,
),
addBehavior: function (name, fn) {
behavior.addBehavior(stub, name, fn);
},
addBehavior: function (name, fn) {
behavior.addBehavior(stub, name, fn);
},
// fake promise
promise: promise,
};
// fake promise
promise: promise,
};
const sandbox = new Sandbox();
const sandbox = new Sandbox();
return extend(sandbox, apiMethods);
}
const api = extend(sandbox, apiMethods);
const api = createApi({ sinonXhrLib: nise });
module.exports = api;
// solely exposed for easier testing
module.exports.createApi = createApi;

@@ -55,3 +55,3 @@ "use strict";

this,
`expected ${expected} to be called in order but were called as ${actual}`
`expected ${expected} to be called in order but were called as ${actual}`,
);

@@ -155,3 +155,3 @@ } else {

assertionArgs.length + 1
} arguments`
} arguments`,
);

@@ -201,4 +201,4 @@ }

fake,
concat([msg], args)
)
concat([msg], args),
),
);

@@ -221,3 +221,3 @@ } else {

"called",
"expected %n to have been called at least once but was never called"
"expected %n to have been called at least once but was never called",
);

@@ -229,23 +229,23 @@ mirrorPropAsAssertion(

},
"expected %n to not have been called but was called %c%C"
"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"
"expected %n to be called once but was called %c%C",
);
mirrorPropAsAssertion(
"calledTwice",
"expected %n to be called twice but was called %c%C"
"expected %n to be called twice but was called %c%C",
);
mirrorPropAsAssertion(
"calledThrice",
"expected %n to be called thrice but was called %c%C"
"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"
"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"
"expected %n to always be called with %1 as this but was called with %t",
);

@@ -255,43 +255,43 @@ mirrorPropAsAssertion("calledWithNew", "expected %n to be called with new");

"alwaysCalledWithNew",
"expected %n to always be called with new"
"expected %n to always be called with new",
);
mirrorPropAsAssertion(
"calledWith",
"expected %n to be called with arguments %D"
"expected %n to be called with arguments %D",
);
mirrorPropAsAssertion(
"calledWithMatch",
"expected %n to be called with match %D"
"expected %n to be called with match %D",
);
mirrorPropAsAssertion(
"alwaysCalledWith",
"expected %n to always be called with arguments %D"
"expected %n to always be called with arguments %D",
);
mirrorPropAsAssertion(
"alwaysCalledWithMatch",
"expected %n to always be called with match %D"
"expected %n to always be called with match %D",
);
mirrorPropAsAssertion(
"calledWithExactly",
"expected %n to be called with exact arguments %D"
"expected %n to be called with exact arguments %D",
);
mirrorPropAsAssertion(
"calledOnceWithExactly",
"expected %n to be called once and with exact arguments %D"
"expected %n to be called once and with exact arguments %D",
);
mirrorPropAsAssertion(
"calledOnceWithMatch",
"expected %n to be called once and with match %D"
"expected %n to be called once and with match %D",
);
mirrorPropAsAssertion(
"alwaysCalledWithExactly",
"expected %n to always be called with exact arguments %D"
"expected %n to always be called with exact arguments %D",
);
mirrorPropAsAssertion(
"neverCalledWith",
"expected %n to never be called with arguments %*%C"
"expected %n to never be called with arguments %*%C",
);
mirrorPropAsAssertion(
"neverCalledWithMatch",
"expected %n to never be called with match %*%C"
"expected %n to never be called with match %*%C",
);

@@ -298,0 +298,0 @@ mirrorPropAsAssertion("threw", "%n did not throw exception%C");

@@ -60,9 +60,9 @@ "use strict";

msg = `${functionName(
behavior.stub
behavior.stub,
)} expected to yield to '${valueToString(
behavior.callArgProp
behavior.callArgProp,
)}', but no object with such a property was passed.`;
} else {
msg = `${functionName(
behavior.stub
behavior.stub,
)} expected to yield, but no callback was passed.`;

@@ -91,3 +91,3 @@ }

args.length
} present`
} present`,
);

@@ -110,3 +110,3 @@ }

behavior.callbackContext,
behavior.callbackArguments
behavior.callbackArguments,
);

@@ -117,3 +117,3 @@ });

behavior.callbackContext,
behavior.callbackArguments
behavior.callbackArguments,
);

@@ -185,3 +185,3 @@ }

return (this.promiseLibrary || Promise).resolve(
args[this.resolveArgAt]
args[this.resolveArgAt],
);

@@ -206,3 +206,3 @@ } else if (this.resolveThis) {

WrappedClass,
concat([null], argsArray)
concat([null], argsArray),
);

@@ -248,3 +248,3 @@ return new F();

'is not supported. Use "stub.withArgs(...).onCall(...)" ' +
"to define sequential behavior for calls with certain arguments."
"to define sequential behavior for calls with certain arguments.",
);

@@ -259,3 +259,3 @@ },

this.defaultBehavior,
arguments
arguments,
);

@@ -262,0 +262,0 @@ return this;

"use strict";
const supportsColor = require("supports-color");
module.exports = class Colorizer {
constructor(supportsColor = require("supports-color")) {
this.supportsColor = supportsColor;
}
function colorize(str, color) {
if (supportsColor.stdout === false) {
return str;
colorize(str, color) {
if (this.supportsColor.stdout === false) {
return str;
}
return `\x1b[${color}m${str}\x1b[0m`;
}
return `\x1b[${color}m${str}\x1b[0m`;
}
red(str) {
return this.colorize(str, 31);
}
exports.red = function (str) {
return colorize(str, 31);
};
green(str) {
return this.colorize(str, 32);
}
exports.green = function (str) {
return colorize(str, 32);
};
cyan(str) {
return this.colorize(str, 96);
}
exports.cyan = function (str) {
return colorize(str, 96);
};
white(str) {
return this.colorize(str, 39);
}
exports.white = function (str) {
return colorize(str, 39);
bold(str) {
return this.colorize(str, 1);
}
};
exports.bold = function (str) {
return colorize(str, 1);
};

@@ -31,3 +31,3 @@ "use strict";

throw new Error(
`Cannot stub ${propertyName}. Property does not exist!`
`Cannot stub ${propertyName}. Property does not exist!`,
);

@@ -34,0 +34,0 @@ }

@@ -18,3 +18,5 @@ "use strict";

fake.exceptionCreator = function () {
const newException = new Error(message || "");
const newException = new Error(
message || `Sinon-provided ${error}`,
);
newException.name = error;

@@ -243,3 +245,3 @@ return newException;

rootStub.rootObj,
rootStub.propName
rootStub.propName,
),

@@ -262,5 +264,5 @@ });

rootStub.rootObj,
rootStub.propName
rootStub.propName,
),
}
},
);

@@ -267,0 +269,0 @@

@@ -151,3 +151,3 @@ "use strict";

mockExpectation.fail(
`${this.method} already called ${timesInWords(this.maxCalls)}`
`${this.method} already called ${timesInWords(this.maxCalls)}`,
);

@@ -159,4 +159,4 @@ }

`${this.method} called with ${valueToString(
thisValue
)} as thisValue, expected ${valueToString(this.expectedThis)}`
thisValue,
)} as thisValue, expected ${valueToString(this.expectedThis)}`,
);

@@ -172,4 +172,4 @@ }

`${this.method} received no arguments, expected ${inspect(
expectedArguments
)}`
expectedArguments,
)}`,
);

@@ -181,4 +181,4 @@ }

`${this.method} received too few arguments (${inspect(
args
)}), expected ${inspect(expectedArguments)}`
args,
)}), expected ${inspect(expectedArguments)}`,
);

@@ -193,4 +193,4 @@ }

`${this.method} received too many arguments (${inspect(
args
)}), expected ${inspect(expectedArguments)}`
args,
)}), expected ${inspect(expectedArguments)}`,
);

@@ -205,4 +205,4 @@ }

`${this.method} received wrong arguments ${inspect(
args
)}, didn't match ${String(expectedArguments)}`
args,
)}, didn't match ${String(expectedArguments)}`,
);

@@ -214,8 +214,8 @@ }

`${this.method} received wrong arguments ${inspect(
args
)}, expected ${inspect(expectedArguments)}`
args,
)}, expected ${inspect(expectedArguments)}`,
);
}
},
this
this,
);

@@ -296,3 +296,3 @@ },

", [...",
"[, ..."
"[, ...",
)} ${expectedCallCountInWords(this)}`;

@@ -299,0 +299,0 @@

@@ -146,5 +146,5 @@ "use strict";

currentArgs,
expectation.expectsExactArgCount
expectation.expectsExactArgCount,
);
}
},
);

@@ -159,3 +159,3 @@

);
}
},
);

@@ -191,3 +191,3 @@

args: args,
})}`
})}`,
);

@@ -210,3 +210,3 @@

stack: err.stack,
})}`
})}`,
);

@@ -213,0 +213,0 @@

@@ -28,3 +28,3 @@ "use strict";

notCalled,
totalCallCount
totalCallCount,
) {

@@ -51,3 +51,3 @@ proxy[method] = function () {

currentCall,
arguments
arguments,
);

@@ -54,0 +54,0 @@ push(returnValues, returnValue);

@@ -51,3 +51,3 @@ "use strict";

},
true
true,
);

@@ -71,3 +71,3 @@ },

},
true
true,
);

@@ -136,3 +136,3 @@ },

this,
concat([pos, null], slice(arguments, 1))
concat([pos, null], slice(arguments, 1)),
);

@@ -150,3 +150,3 @@ },

throw new TypeError(
`Not enough arguments: ${pos} required but only ${this.args.length} present`
`Not enough arguments: ${pos} required but only ${this.args.length} present`,
);

@@ -172,3 +172,3 @@ }

" cannot yield since no callback was passed.",
args
args,
);

@@ -183,3 +183,3 @@ }

this,
concat([prop, null], slice(arguments, 1))
concat([prop, null], slice(arguments, 1)),
);

@@ -199,5 +199,5 @@ },

` cannot yield to '${valueToString(
prop
prop,
)}' since no callback was passed.`,
args
args,
);

@@ -237,3 +237,3 @@ }

/^\s*(?:at\s+|@)?/,
" at "
" at ",
);

@@ -249,3 +249,3 @@ }

`Expected argument at position ${pos} to be a Function, but was ${typeof this
.args[pos]}`
.args[pos]}`,
);

@@ -273,2 +273,4 @@ }

* @param errorWithCallStack
*
* @returns {object} proxyCall
*/

@@ -282,3 +284,3 @@ function createProxyCall(

id,
errorWithCallStack
errorWithCallStack,
) {

@@ -285,0 +287,0 @@ if (typeof id !== "number") {

@@ -43,3 +43,3 @@ "use strict";

this.func || func,
concat([thisValue], args)
concat([thisValue], args),
))();

@@ -46,0 +46,0 @@

@@ -60,3 +60,3 @@ "use strict";

this.callIds[i],
this.errorsWithCallStack[i]
this.errorsWithCallStack[i],
);

@@ -141,3 +141,3 @@ },

"Cannot reset Sinon function while invoking it. " +
"Move the call to .resetHistory outside of the callback."
"Move the call to .resetHistory outside of the callback.",
);

@@ -188,3 +188,3 @@ err.name = "InvalidResetException";

undefined,
1
1,
);

@@ -202,3 +202,3 @@ delegateToCalls(proxyApi, "calledWithMatch", true);

undefined,
1
1,
);

@@ -212,3 +212,3 @@ delegateToCalls(

undefined,
1
1,
);

@@ -219,3 +219,3 @@ delegateToCalls(

false,
"calledWithExactly"
"calledWithExactly",
);

@@ -230,3 +230,3 @@ delegateToCalls(

return true;
}
},
);

@@ -241,3 +241,3 @@ delegateToCalls(

return true;
}
},
);

@@ -345,3 +345,3 @@ delegateToCalls(proxyApi, "threw", true);

originalFunc,
"name"
"name",
);

@@ -348,0 +348,0 @@ if (nameDescriptor && nameDescriptor.configurable) {

@@ -38,2 +38,36 @@ "use strict";

function throwOnAccessors(descriptor) {
if (typeof descriptor.get === "function") {
throw new Error("Use sandbox.replaceGetter for replacing getters");
}
if (typeof descriptor.set === "function") {
throw new Error("Use sandbox.replaceSetter for replacing setters");
}
}
function verifySameType(object, property, replacement) {
if (typeof object[property] !== typeof replacement) {
throw new TypeError(
`Cannot replace ${typeof object[
property
]} with ${typeof replacement}`,
);
}
}
function checkForValidArguments(descriptor, property, replacement) {
if (typeof descriptor === "undefined") {
throw new TypeError(
`Cannot replace non-existent property ${valueToString(
property,
)}. Perhaps you meant sandbox.define()?`,
);
}
if (typeof replacement === "undefined") {
throw new TypeError("Expected replacement argument to be defined");
}
}
function Sandbox() {

@@ -55,3 +89,3 @@ const sandbox = this;

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."
"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.",
);

@@ -71,7 +105,2 @@ loggedLeakWarning = true;

// this is for testing only
sandbox.getRestorers = function () {
return fakeRestorers;
};
sandbox.createStubInstance = function createStubInstance() {

@@ -112,2 +141,6 @@ const stubbed = sinonCreateStubInstance.apply(null, arguments);

obj.define = function () {
return sandbox.define.apply(null, arguments);
};
obj.replace = function () {

@@ -165,19 +198,3 @@ return sandbox.replace.apply(null, arguments);

forEach(collection, function (fake) {
if (typeof fake === "function") {
privateResetHistory(fake);
return;
}
const methods = [];
if (fake.get) {
push(methods, fake.get);
}
if (fake.set) {
push(methods, fake.set);
}
forEach(methods, privateResetHistory);
});
forEach(collection, privateResetHistory);
};

@@ -188,3 +205,3 @@

throw new Error(
"sandbox.restore() does not take any parameters. Perhaps you meant stub.restore()"
"sandbox.restore() does not take any parameters. Perhaps you meant stub.restore()",
);

@@ -206,21 +223,29 @@ }

sandbox.restoreContext = function restoreContext() {
let injectedKeys = sandbox.injectedKeys;
const injectInto = sandbox.injectInto;
if (!injectedKeys) {
if (!sandbox.injectedKeys) {
return;
}
forEach(injectedKeys, function (injectedKey) {
delete injectInto[injectedKey];
forEach(sandbox.injectedKeys, function (injectedKey) {
delete sandbox.injectInto[injectedKey];
});
injectedKeys = [];
sandbox.injectedKeys.length = 0;
};
function getFakeRestorer(object, property) {
/**
* Creates a restorer function for the property
*
* @param {object|Function} object
* @param {string} property
* @param {boolean} forceAssignment
* @returns {Function} restorer function
*/
function getFakeRestorer(object, property, forceAssignment = false) {
const descriptor = getPropertyDescriptor(object, property);
const value = object[property];
function restorer() {
if (descriptor.isOwn) {
if (forceAssignment) {
object[property] = value;
} else if (descriptor?.isOwn) {
Object.defineProperty(object, property, descriptor);

@@ -231,2 +256,3 @@ } else {

}
restorer.object = object;

@@ -244,3 +270,3 @@ restorer.property = property;

throw new TypeError(
`Attempted to replace ${property} which is already replaced`
`Attempted to replace ${property} which is already replaced`,
);

@@ -251,41 +277,68 @@ }

/**
* Replace an existing property
*
* @param {object|Function} object
* @param {string} property
* @param {*} replacement a fake, stub, spy or any other value
* @returns {*}
*/
sandbox.replace = function replace(object, property, replacement) {
const descriptor = getPropertyDescriptor(object, property);
checkForValidArguments(descriptor, property, replacement);
throwOnAccessors(descriptor);
verifySameType(object, property, replacement);
if (typeof descriptor === "undefined") {
throw new TypeError(
`Cannot replace non-existent property ${valueToString(
property
)}`
);
}
verifyNotReplaced(object, property);
if (typeof replacement === "undefined") {
throw new TypeError("Expected replacement argument to be defined");
}
// store a function for restoring the replaced property
push(fakeRestorers, getFakeRestorer(object, property));
if (typeof descriptor.get === "function") {
throw new Error("Use sandbox.replaceGetter for replacing getters");
}
object[property] = replacement;
if (typeof descriptor.set === "function") {
throw new Error("Use sandbox.replaceSetter for replacing setters");
}
return replacement;
};
if (typeof object[property] !== typeof replacement) {
sandbox.replace.usingAccessor = function replaceUsingAccessor(
object,
property,
replacement,
) {
const descriptor = getPropertyDescriptor(object, property);
checkForValidArguments(descriptor, property, replacement);
verifySameType(object, property, replacement);
verifyNotReplaced(object, property);
// store a function for restoring the replaced property
push(fakeRestorers, getFakeRestorer(object, property, true));
object[property] = replacement;
return replacement;
};
sandbox.define = function define(object, property, value) {
const descriptor = getPropertyDescriptor(object, property);
if (descriptor) {
throw new TypeError(
`Cannot replace ${typeof object[
property
]} with ${typeof replacement}`
`Cannot define the already existing property ${valueToString(
property,
)}. Perhaps you meant sandbox.replace()?`,
);
}
if (typeof value === "undefined") {
throw new TypeError("Expected value argument to be defined");
}
verifyNotReplaced(object, property);
// store a function for restoring the replaced property
// store a function for restoring the defined property
push(fakeRestorers, getFakeRestorer(object, property));
object[property] = replacement;
object[property] = value;
return replacement;
return value;
};

@@ -296,3 +349,3 @@

property,
replacement
replacement,
) {

@@ -304,4 +357,4 @@ const descriptor = getPropertyDescriptor(object, property);

`Cannot replace non-existent property ${valueToString(
property
)}`
property,
)}`,
);

@@ -312,3 +365,3 @@ }

throw new TypeError(
"Expected replacement argument to be a function"
"Expected replacement argument to be a function",
);

@@ -337,3 +390,3 @@ }

property,
replacement
replacement,
) {

@@ -345,4 +398,4 @@ const descriptor = getPropertyDescriptor(object, property);

`Cannot replace non-existent property ${valueToString(
property
)}`
property,
)}`,
);

@@ -353,3 +406,3 @@ }

throw new TypeError(
"Expected replacement argument to be a function"
"Expected replacement argument to be a function",
);

@@ -377,4 +430,3 @@ }

function commonPostInitSetup(args, spy) {
const object = args[0];
const property = args[1];
const [object, property, types] = args;

@@ -392,2 +444,7 @@ const isSpyingOnEntireObject =

usePromiseLibrary(promiseLib, ownMethods);
} else if (Array.isArray(types)) {
for (const accessorType of types) {
addToCollection(spy[accessorType]);
usePromiseLibrary(promiseLib, spy[accessorType]);
}
} else {

@@ -394,0 +451,0 @@ addToCollection(spy);

"use strict";
const arrayProto = require("@sinonjs/commons").prototypes.array;
const color = require("./color");
const Colorizer = require("./color");
const color = new Colorizer();
const match = require("@sinonjs/samsam").createMatcher;

@@ -15,2 +16,10 @@ const timesInWords = require("./util/core/times-in-words");

/**
*
* @param matcher
* @param calledArg
* @param calledArgMessage
*
* @returns {string} the colored text
*/
function colorSinonMatchText(matcher, calledArg, calledArgMessage) {

@@ -28,2 +37,7 @@ let calledArgumentMessage = calledArgMessage;

/**
* @param diff
*
* @returns {string} the colored diff
*/
function colorDiffText(diff) {

@@ -45,2 +59,7 @@ const objects = map(diff, function (part) {

/**
*
* @param value
* @returns {string} a quoted string
*/
function quoteStringValue(value) {

@@ -97,3 +116,3 @@ if (typeof value === "string") {

calledArg,
calledArgMessage
calledArgMessage,
);

@@ -105,3 +124,3 @@ } else {

calledArgMessage,
expectedArgMessage
expectedArgMessage,
);

@@ -146,5 +165,5 @@ message += colorDiffText(diff);

}),
", "
", ",
);
},
};

@@ -84,3 +84,3 @@ "use strict";

throw new Error(
`${this.toString()} cannot call arg since it was not yet invoked.`
`${this.toString()} cannot call arg since it was not yet invoked.`,
);

@@ -91,3 +91,3 @@ });

throw new Error(
`${this.toString()} cannot call arg since it was not yet invoked.`
`${this.toString()} cannot call arg since it was not yet invoked.`,
);

@@ -98,3 +98,3 @@ });

throw new Error(
`${this.toString()} cannot throw arg since it was not yet invoked.`
`${this.toString()} cannot throw arg since it was not yet invoked.`,
);

@@ -104,3 +104,3 @@ });

throw new Error(
`${this.toString()} cannot yield since it was not yet invoked.`
`${this.toString()} cannot yield since it was not yet invoked.`,
);

@@ -112,3 +112,3 @@ });

throw new Error(
`${this.toString()} cannot yield since it was not yet invoked.`
`${this.toString()} cannot yield since it was not yet invoked.`,
);

@@ -119,4 +119,4 @@ });

`${this.toString()} cannot yield to '${valueToString(
property
)}' since it was not yet invoked.`
property,
)}' since it was not yet invoked.`,
);

@@ -133,6 +133,6 @@ });

`${this.toString()} cannot yield to '${valueToString(
property
)}' since it was not yet invoked.`
property,
)}' since it was not yet invoked.`,
);
}
},
);

@@ -139,0 +139,0 @@

@@ -42,3 +42,3 @@ "use strict";

);
})
}),
) || proxy;

@@ -72,3 +72,3 @@ return getCurrentBehavior(fnStub).invoke(this, arguments);

throw new TypeError(
"stub(obj, 'meth', fn) has been removed, see documentation"
"stub(obj, 'meth', fn) has been removed, see documentation",
);

@@ -85,3 +85,3 @@ }

throw new TypeError(
`Cannot stub non-existent property ${valueToString(property)}`
`Cannot stub non-existent property ${valueToString(property)}`,
);

@@ -142,3 +142,3 @@ }

throw new TypeError(
`Descriptor for property ${property} is non-configurable and non-writable`
`Descriptor for property ${property} is non-configurable and non-writable`,
);

@@ -148,3 +148,3 @@ }

throw new TypeError(
`Descriptor for accessor property ${property} is non-configurable`
`Descriptor for accessor property ${property} is non-configurable`,
);

@@ -154,3 +154,3 @@ }

throw new TypeError(
`Descriptor for data property ${property} is non-writable`
`Descriptor for data property ${property} is non-writable`,
);

@@ -157,0 +157,0 @@ }

@@ -8,3 +8,3 @@ "use strict";

throw new Error(
`Trying to stub property '${valueToString(property)}' of ${type}`
`Trying to stub property '${valueToString(property)}' of ${type}`,
);

@@ -11,0 +11,0 @@ }

@@ -13,2 +13,3 @@ "use strict";

"fake",
"define",
"replace",

@@ -15,0 +16,0 @@ "replaceSetter",

@@ -15,3 +15,3 @@ "use strict";

this,
arguments
arguments,
);

@@ -24,4 +24,4 @@ this.callbackAsync = true;

},
{}
{},
);
};

@@ -102,7 +102,7 @@ "use strict";

dest,
prop
prop,
);
const sourceOwnPropertyDescriptor = Object.getOwnPropertyDescriptor(
source,
prop
prop,
);

@@ -137,3 +137,3 @@

Object.defineProperty(dest, prop, descriptors);
}
},
);

@@ -161,4 +161,4 @@ };

});
}
},
);
};
"use strict";
module.exports = function getPropertyDescriptor(object, property) {
/* eslint-disable jsdoc/valid-types */
/*
* The following type def is strictly an illegal JSDoc, but the expression forms a
* legal Typescript union type and is understood by Visual Studio and the IntelliJ
* family of editors. The "TS" flavor of JSDoc is becoming the de-facto standard these
* days for that reason (and the fact that JSDoc is essentially unmaintained)
*/
/**
* @typedef {{isOwn: boolean} & PropertyDescriptor} SinonPropertyDescriptor
* a slightly enriched property descriptor
* @property {boolean} isOwn true if the descriptor is owned by this object, false if it comes from the prototype
*/
/* eslint-enable jsdoc/valid-types */
/**
* Returns a slightly modified property descriptor that one can tell is from the object or the prototype
*
* @param {*} object
* @param {string} property
* @returns {SinonPropertyDescriptor}
*/
function getPropertyDescriptor(object, property) {
let proto = object;
let descriptor;
const isOwn = Boolean(
object && Object.getOwnPropertyDescriptor(object, property)
object && Object.getOwnPropertyDescriptor(object, property),
);

@@ -22,2 +44,4 @@

return descriptor;
};
}
module.exports = getPropertyDescriptor;

@@ -10,3 +10,3 @@ "use strict";

return Boolean(
object && typeof property !== "undefined" && !(property in object)
object && typeof property !== "undefined" && !(property in object),
);

@@ -13,0 +13,0 @@ }

@@ -22,3 +22,3 @@ "use strict";

throw new Error(
`Trying to ${name} object but received ${String(object)}`
`Trying to ${name} object but received ${String(object)}`,
);

@@ -49,3 +49,3 @@ }

throw new Error(
`Found no methods on object to which we could apply mutations`
`Found no methods on object to which we could apply mutations`,
);

@@ -52,0 +52,0 @@ }

@@ -53,3 +53,3 @@ "use strict";

throw new TypeError(
"Method wrapper should be a function or a property descriptor"
"Method wrapper should be a function or a property descriptor",
);

@@ -64,4 +64,4 @@ }

`Attempted to wrap ${typeof wrappedMethod} property ${valueToString(
property
)} as function`
property,
)} as function`,
);

@@ -71,4 +71,4 @@ } else if (wrappedMethod.restore && wrappedMethod.restore.sinon) {

`Attempted to wrap ${valueToString(
property
)} which is already wrapped`
property,
)} which is already wrapped`,
);

@@ -79,4 +79,4 @@ } else if (wrappedMethod.calledBefore) {

`Attempted to wrap ${valueToString(
property
)} which is already ${verb}`
property,
)} which is already ${verb}`,
);

@@ -116,3 +116,3 @@ }

error = new TypeError(
`Attempted to wrap ${typeof wrappedMethod} property ${property} as function`
`Attempted to wrap ${typeof wrappedMethod} property ${property} as function`,
);

@@ -124,3 +124,3 @@ } else if (

error = new TypeError(
`Attempted to wrap ${property} which is already wrapped`
`Attempted to wrap ${property} which is already wrapped`,
);

@@ -127,0 +127,0 @@ }

@@ -11,2 +11,4 @@ "use strict";

* @param globalCtx
*
* @returns {object} the clock, after installing it on the global context, if given
*/

@@ -69,3 +71,3 @@ function createClock(config, globalCtx) {

throw new TypeError(
"useFakeTimers expected epoch or config object. See https://github.com/sinonjs/sinon"
"useFakeTimers expected epoch or config object. See https://github.com/sinonjs/sinon",
);

@@ -72,0 +74,0 @@ };

@@ -18,3 +18,3 @@ {

],
"version": "15.2.0",
"version": "17.0.0",
"homepage": "https://sinonjs.org/",

@@ -37,3 +37,3 @@ "author": "Christian Johansen",

"test-dev": "npm run test-node -- --watch -R min",
"test-headless": "mochify --no-detect-globals --recursive -R dot --grep WebWorker --invert --plugin [ proxyquire-universal ] \"test/**/*-test.js\"",
"test-headless": "mochify --no-detect-globals --recursive -R dot --grep WebWorker --invert \"test/**/*-test.js\"",
"test-coverage": "nyc npm run test-headless -- --transform [ babelify --ignore [ test ] --plugins [ babel-plugin-istanbul ] ]",

@@ -49,5 +49,6 @@ "test-cloud": "npm run test-headless -- --wd",

"build": "node ./build.cjs",
"dev-docs": "cd docs; rsync -r --delete release-source/ releases/dev; npm run serve-docs",
"build-docs": "cd docs; bundle exec jekyll build",
"serve-docs": "cd docs; bundle exec jekyll serve --incremental --verbose",
"lint": "eslint --max-warnings 99 '**/*.{js,cjs,mjs}'",
"serve-docs": "cd docs; bundle exec jekyll serve --incremental --verbose --livereload",
"lint": "eslint --max-warnings 0 '**/*.{js,cjs,mjs}'",
"unimported": "unimported .",

@@ -74,3 +75,3 @@ "pretest-webworker": "npm run build",

"lint-staged": {
"*.{js,css,md}": "prettier --check",
"**/*.{js,css,md}": "prettier --write",
"*.js": "eslint --quiet",

@@ -81,13 +82,13 @@ "*.mjs": "eslint --quiet --ext mjs --parser-options=sourceType:module"

"@sinonjs/commons": "^3.0.0",
"@sinonjs/fake-timers": "^10.3.0",
"@sinonjs/fake-timers": "^11.2.2",
"@sinonjs/samsam": "^8.0.0",
"diff": "^5.1.0",
"nise": "^5.1.4",
"nise": "^5.1.5",
"supports-color": "^7.2.0"
},
"devDependencies": {
"@babel/core": "^7.21.0",
"@sinonjs/eslint-config": "^4.0.6",
"@babel/core": "^7.23.2",
"@sinonjs/eslint-config": "^4.1.0",
"@sinonjs/eslint-plugin-no-prototype-methods": "^0.1.1",
"@sinonjs/referee": "^10.0.0",
"@sinonjs/referee": "^10.0.1",
"@studio/changes": "^2.2.0",

@@ -99,16 +100,12 @@ "babel-plugin-istanbul": "^6.1.1",

"dependency-check": "^4.1.0",
"husky": "^6.0.0",
"lint-staged": "^13.2.0",
"lint-staged": "^15.0.2",
"mocha": "^10.2.0",
"mochify": "^9.2.0",
"nyc": "^15.1.0",
"prettier": "^2.8.4",
"proxyquire": "^2.1.3",
"proxyquire-universal": "^3.0.1",
"proxyquireify": "^3.2.1",
"puppeteer": "^19.7.4",
"rimraf": "^4.4.0",
"semver": "^7.3.8",
"prettier": "^3.0.3",
"puppeteer": "^21.4.0",
"rimraf": "^5.0.5",
"semver": "^7.5.4",
"shelljs": "^0.8.5",
"unimported": "^1.26.0"
"unimported": "^1.30.0"
},

@@ -145,8 +142,3 @@ "files": [

"mode": "auto"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
}
}

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc