Truncate pretty printer output that is more than j$.MAX_PRETTY_PRINT_CHARS long
This commit is contained in:
@@ -146,6 +146,12 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
|
|||||||
* @name jasmine.MAX_PRETTY_PRINT_ARRAY_LENGTH
|
* @name jasmine.MAX_PRETTY_PRINT_ARRAY_LENGTH
|
||||||
*/
|
*/
|
||||||
j$.MAX_PRETTY_PRINT_ARRAY_LENGTH = 50;
|
j$.MAX_PRETTY_PRINT_ARRAY_LENGTH = 50;
|
||||||
|
/**
|
||||||
|
* Maximum number of charasters to display when pretty printing objects.
|
||||||
|
* Characters past this number will be ellipised.
|
||||||
|
* @name jasmine.MAX_PRETTY_PRINT_CHARS
|
||||||
|
*/
|
||||||
|
j$.MAX_PRETTY_PRINT_CHARS = 1000;
|
||||||
/**
|
/**
|
||||||
* Default number of milliseconds Jasmine will wait for an asynchronous spec to complete.
|
* Default number of milliseconds Jasmine will wait for an asynchronous spec to complete.
|
||||||
* @name jasmine.DEFAULT_TIMEOUT_INTERVAL
|
* @name jasmine.DEFAULT_TIMEOUT_INTERVAL
|
||||||
@@ -4044,6 +4050,7 @@ getJasmineRequireObj().pp = function(j$) {
|
|||||||
function StringPrettyPrinter() {
|
function StringPrettyPrinter() {
|
||||||
PrettyPrinter.call(this);
|
PrettyPrinter.call(this);
|
||||||
|
|
||||||
|
this.length = 0;
|
||||||
this.stringParts = [];
|
this.stringParts = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4187,9 +4194,22 @@ getJasmineRequireObj().pp = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
StringPrettyPrinter.prototype.append = function(value) {
|
StringPrettyPrinter.prototype.append = function(value) {
|
||||||
this.stringParts.push(value);
|
if (this.length < j$.MAX_PRETTY_PRINT_CHARS) {
|
||||||
|
value = truncate(value, j$.MAX_PRETTY_PRINT_CHARS - this.length);
|
||||||
|
this.length += value.length;
|
||||||
|
this.stringParts.push(value);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function truncate(s, maxlen) {
|
||||||
|
if (s.length <= maxlen) {
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
s = s.substring(0, maxlen - 4);
|
||||||
|
return s + ' ...';
|
||||||
|
}
|
||||||
|
|
||||||
function keys(obj, isArray) {
|
function keys(obj, isArray) {
|
||||||
var allKeys = Object.keys ? Object.keys(obj) :
|
var allKeys = Object.keys ? Object.keys(obj) :
|
||||||
(function(o) {
|
(function(o) {
|
||||||
|
|||||||
@@ -131,6 +131,21 @@ describe("jasmineUnderTest.pp", function () {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should truncate outputs that are too long", function() {
|
||||||
|
var originalMaxChars = jasmineUnderTest.MAX_PRETTY_PRINT_CHARS;
|
||||||
|
var big = [
|
||||||
|
{ a: 1, b: "a long string" },
|
||||||
|
{}
|
||||||
|
];
|
||||||
|
|
||||||
|
try {
|
||||||
|
jasmineUnderTest.MAX_PRETTY_PRINT_CHARS = 34;
|
||||||
|
expect(jasmineUnderTest.pp(big)).toEqual("[ Object({ a: 1, b: 'a long st ...");
|
||||||
|
} finally {
|
||||||
|
jasmineUnderTest.MAX_PRETTY_PRINT_CHARS = originalMaxChars;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
it("should print 'null' as the constructor of an object with its own constructor property", function() {
|
it("should print 'null' as the constructor of an object with its own constructor property", function() {
|
||||||
expect(jasmineUnderTest.pp({constructor: function() {}})).toContain("null({");
|
expect(jasmineUnderTest.pp({constructor: function() {}})).toContain("null({");
|
||||||
expect(jasmineUnderTest.pp({constructor: 'foo'})).toContain("null({");
|
expect(jasmineUnderTest.pp({constructor: 'foo'})).toContain("null({");
|
||||||
|
|||||||
@@ -92,6 +92,7 @@ getJasmineRequireObj().pp = function(j$) {
|
|||||||
function StringPrettyPrinter() {
|
function StringPrettyPrinter() {
|
||||||
PrettyPrinter.call(this);
|
PrettyPrinter.call(this);
|
||||||
|
|
||||||
|
this.length = 0;
|
||||||
this.stringParts = [];
|
this.stringParts = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -235,9 +236,22 @@ getJasmineRequireObj().pp = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
StringPrettyPrinter.prototype.append = function(value) {
|
StringPrettyPrinter.prototype.append = function(value) {
|
||||||
this.stringParts.push(value);
|
if (this.length < j$.MAX_PRETTY_PRINT_CHARS) {
|
||||||
|
value = truncate(value, j$.MAX_PRETTY_PRINT_CHARS - this.length);
|
||||||
|
this.length += value.length;
|
||||||
|
this.stringParts.push(value);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function truncate(s, maxlen) {
|
||||||
|
if (s.length <= maxlen) {
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
s = s.substring(0, maxlen - 4);
|
||||||
|
return s + ' ...';
|
||||||
|
}
|
||||||
|
|
||||||
function keys(obj, isArray) {
|
function keys(obj, isArray) {
|
||||||
var allKeys = Object.keys ? Object.keys(obj) :
|
var allKeys = Object.keys ? Object.keys(obj) :
|
||||||
(function(o) {
|
(function(o) {
|
||||||
|
|||||||
@@ -16,6 +16,12 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
|
|||||||
* @name jasmine.MAX_PRETTY_PRINT_ARRAY_LENGTH
|
* @name jasmine.MAX_PRETTY_PRINT_ARRAY_LENGTH
|
||||||
*/
|
*/
|
||||||
j$.MAX_PRETTY_PRINT_ARRAY_LENGTH = 50;
|
j$.MAX_PRETTY_PRINT_ARRAY_LENGTH = 50;
|
||||||
|
/**
|
||||||
|
* Maximum number of charasters to display when pretty printing objects.
|
||||||
|
* Characters past this number will be ellipised.
|
||||||
|
* @name jasmine.MAX_PRETTY_PRINT_CHARS
|
||||||
|
*/
|
||||||
|
j$.MAX_PRETTY_PRINT_CHARS = 1000;
|
||||||
/**
|
/**
|
||||||
* Default number of milliseconds Jasmine will wait for an asynchronous spec to complete.
|
* Default number of milliseconds Jasmine will wait for an asynchronous spec to complete.
|
||||||
* @name jasmine.DEFAULT_TIMEOUT_INTERVAL
|
* @name jasmine.DEFAULT_TIMEOUT_INTERVAL
|
||||||
|
|||||||
Reference in New Issue
Block a user