Skip to content

Commit

Permalink
fix: Allow for a log limit setting on the assertion object, that when…
Browse files Browse the repository at this point in the history
… true, will truncate the error.message that is returned via a failing assertion. The limit for the log message will be set to a default if none was provided
  • Loading branch information
sgoossens committed Dec 12, 2022
1 parent 62caa67 commit f71d859
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lib/sinon/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ var forEach = arrayProto.forEach;
var join = arrayProto.join;
var splice = arrayProto.splice;

function createAssertObject() {
var DEFAULT_LOG_LIMIT = 10000;

function createAssertObject(shouldLimitAssertionLogs) {
var assert;
var assertionLogLimit;

function verifyIsStub() {
var args = arraySlice(arguments);
Expand Down Expand Up @@ -117,6 +120,9 @@ function createAssertObject() {
failException: "AssertError",

fail: function fail(message) {
if (shouldLimitAssertionLogs) {
message.substring(0, assertionLogLimit ?? DEFAULT_LOG_LIMIT);
}
var error = new Error(message);
error.name = this.failException || assert.failException;

Expand Down
3 changes: 2 additions & 1 deletion lib/sinon/sandbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function Sandbox() {
var sandbox = this;
var fakeRestorers = [];
var promiseLib;
var shouldLimitAssertionLogs;

var collection = [];
var loggedLeakWarning = false;
Expand All @@ -56,7 +57,7 @@ function Sandbox() {
}
}

sandbox.assert = sinonAssert.createAssertObject();
sandbox.assert = sinonAssert.createAssertObject(shouldLimitAssertionLogs);

sandbox.serverPrototype = fakeServer;

Expand Down

0 comments on commit f71d859

Please sign in to comment.