Skip to content

Commit

Permalink
Fix 2448: remove custom formatter
Browse files Browse the repository at this point in the history
Remove option to pass a custom formatter.

The sub libraries of Sinon has long moved on to use `util.inspect` from
Node. By using that in Sinon itself, we align all the libraries.
  • Loading branch information
mroderick committed Nov 28, 2022
1 parent 49ef930 commit b75fbfa
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 26 deletions.
3 changes: 0 additions & 3 deletions lib/sinon.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ var behavior = require("./sinon/behavior");
var createSandbox = require("./sinon/create-sandbox");
var extend = require("./sinon/util/core/extend");
var fakeTimers = require("./sinon/util/fake-timers");
var format = require("./sinon/util/core/format");
var nise = require("nise");
var Sandbox = require("./sinon/sandbox");
var stub = require("./sinon/stub");
Expand All @@ -19,8 +18,6 @@ var apiMethods = {
expectation: require("./sinon/mock-expectation"),
defaultConfig: require("./sinon/util/core/default-config"),

setFormatter: format.setFormatter,

// fake timers
timers: fakeTimers.timers,

Expand Down
8 changes: 4 additions & 4 deletions lib/sinon/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var calledInOrder = require("@sinonjs/commons").calledInOrder;
var createMatcher = require("@sinonjs/samsam").createMatcher;
var orderByFirstCall = require("@sinonjs/commons").orderByFirstCall;
var timesInWords = require("./util/core/times-in-words");
var format = require("./util/core/format");
var inspect = require("util").inspect;
var stringSlice = require("@sinonjs/commons").prototypes.string.slice;
var globalObject = require("@sinonjs/commons").global;

Expand Down Expand Up @@ -162,7 +162,7 @@ function createAssertObject() {
var msg;
if (typeof count !== "number") {
msg =
`expected ${format(count)} to be a number ` +
`expected ${inspect(count)} to be a number ` +
`but was of type ${typeof count}`;
failAssertion(this, msg);
} else if (method.callCount !== count) {
Expand Down Expand Up @@ -206,8 +206,8 @@ function createAssertObject() {
} else {
var formatted = [
"expected value to match",
` expected = ${format(expectation)}`,
` actual = ${format(actual)}`,
` expected = ${inspect(expectation)}`,
` actual = ${inspect(actual)}`,
];

failAssertion(this, join(formatted, "\n"));
Expand Down
18 changes: 9 additions & 9 deletions lib/sinon/mock-expectation.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var match = require("@sinonjs/samsam").createMatcher;
var stub = require("./stub");
var assert = require("./assert");
var deepEqual = require("@sinonjs/samsam").deepEqual;
var format = require("./util/core/format");
var inspect = require("util").inspect;
var valueToString = require("@sinonjs/commons").valueToString;

var every = arrayProto.every;
Expand Down Expand Up @@ -166,17 +166,17 @@ var mockExpectation = {

if (!args) {
mockExpectation.fail(
`${this.method} received no arguments, expected ${format(
`${this.method} received no arguments, expected ${inspect(
expectedArguments
)}`
);
}

if (args.length < expectedArguments.length) {
mockExpectation.fail(
`${this.method} received too few arguments (${format(
`${this.method} received too few arguments (${inspect(
args
)}), expected ${format(expectedArguments)}`
)}), expected ${inspect(expectedArguments)}`
);
}

Expand All @@ -185,9 +185,9 @@ var mockExpectation = {
args.length !== expectedArguments.length
) {
mockExpectation.fail(
`${this.method} received too many arguments (${format(
`${this.method} received too many arguments (${inspect(
args
)}), expected ${format(expectedArguments)}`
)}), expected ${inspect(expectedArguments)}`
);
}

Expand All @@ -196,17 +196,17 @@ var mockExpectation = {
function (expectedArgument, i) {
if (!verifyMatcher(expectedArgument, args[i])) {
mockExpectation.fail(
`${this.method} received wrong arguments ${format(
`${this.method} received wrong arguments ${inspect(
args
)}, didn't match ${String(expectedArguments)}`
);
}

if (!deepEqual(args[i], expectedArgument)) {
mockExpectation.fail(
`${this.method} received wrong arguments ${format(
`${this.method} received wrong arguments ${inspect(
args
)}, expected ${format(expectedArguments)}`
)}, expected ${inspect(expectedArguments)}`
);
}
},
Expand Down
6 changes: 3 additions & 3 deletions lib/sinon/proxy-call.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var arrayProto = require("@sinonjs/commons").prototypes.array;
var match = require("@sinonjs/samsam").createMatcher;
var deepEqual = require("@sinonjs/samsam").deepEqual;
var functionName = require("@sinonjs/commons").functionName;
var sinonFormat = require("./util/core/format");
var inspect = require("util").inspect;
var valueToString = require("@sinonjs/commons").valueToString;

var concat = arrayProto.concat;
Expand Down Expand Up @@ -208,13 +208,13 @@ var callProto = {
}

formattedArgs = map(this.args, function (arg) {
return sinonFormat(arg);
return inspect(arg);
});

callStr = `${callStr + join(formattedArgs, ", ")})`;

if (typeof this.returnValue !== "undefined") {
callStr += ` => ${sinonFormat(this.returnValue)}`;
callStr += ` => ${inspect(this.returnValue)}`;
}

if (this.exception) {
Expand Down
4 changes: 2 additions & 2 deletions lib/sinon/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var functionToString = require("./util/core/function-to-string");
var proxyCall = require("./proxy-call");
var proxyCallUtil = require("./proxy-call-util");
var proxyInvoke = require("./proxy-invoke");
var sinonFormat = require("./util/core/format");
var inspect = require("util").inspect;

var push = arrayProto.push;
var forEach = arrayProto.forEach;
Expand Down Expand Up @@ -126,7 +126,7 @@ var proxyApi = {
if (typeof formatter === "function") {
return String(formatter(spyInstance, args));
} else if (!isNaN(parseInt(specifier, 10))) {
return sinonFormat(args[specifier - 1]);
return inspect(args[specifier - 1]);
}

return `%${specifier}`;
Expand Down
10 changes: 5 additions & 5 deletions lib/sinon/spy-formatters.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var arrayProto = require("@sinonjs/commons").prototypes.array;
var color = require("./color");
var match = require("@sinonjs/samsam").createMatcher;
var timesInWords = require("./util/core/times-in-words");
var sinonFormat = require("./util/core/format");
var inspect = require("util").inspect;
var jsDiff = require("diff");

var join = arrayProto.join;
Expand Down Expand Up @@ -85,7 +85,7 @@ module.exports = {
message += "\n";

var calledArgMessage =
j < calledArgs.length ? sinonFormat(calledArg) : "";
j < calledArgs.length ? inspect(calledArg) : "";
if (match.isMatcher(expectedArg)) {
message += colorSinonMatchText(
expectedArg,
Expand All @@ -94,7 +94,7 @@ module.exports = {
);
} else {
var expectedArgMessage =
j < expectedArgs.length ? sinonFormat(expectedArg) : "";
j < expectedArgs.length ? inspect(expectedArg) : "";
var diff = jsDiff.diffJson(
calledArgMessage,
expectedArgMessage
Expand Down Expand Up @@ -126,7 +126,7 @@ module.exports = {
var objects = [];

for (var i = 0, l = spyInstance.callCount; i < l; ++i) {
push(objects, sinonFormat(spyInstance.thisValues[i]));
push(objects, inspect(spyInstance.thisValues[i]));
}

return join(objects, ", ");
Expand All @@ -135,7 +135,7 @@ module.exports = {
"*": function (spyInstance, args) {
return join(
map(args, function (arg) {
return sinonFormat(arg);
return inspect(arg);
}),
", "
);
Expand Down

0 comments on commit b75fbfa

Please sign in to comment.