Skip to content

Commit 0c2bb7f

Browse files
committed
Tests: Fix flaky dump test "Circular reference with arrays"
There were two issues here: * The test relied on non-default maxDepth of null or > 10 since its example involves recurion 10 levels deep, and the default maxDepth is 5. * There is a bug in `QUnit.dump.parse()` where, if the input value cannot be mapped to a formatter function, it returns a function instead of a string. This bug was introduced nearly ten years ago in commit 818b2be, where `error` was replaced with a function that had a different purpose than what was there before, and this one use of it as fallback was not updated. Unfortunately, I am unable to say what value causes this to happen. I can consistently reproduce the issue in Safari 9.1 via BrowserStack, but only if I don't open the console, don't run a subset of the test, and don't modify any of the surrounding code. I have tried dozens upon dozens of clever ways to store values during the parse() function call in temporary variables and alert() them but as soon as I tried to capture anything that would help, the bug would stop happening. I can only conclude that there must be some kind of memory or JIT corruption in the JavaScript engine of Safari 9.1 that has some extremely specific conditions attached to it. Conditions that we did not meet before the last few commits, and are meeting now. ``` [OS X El Capitan, Safari 9.1] Error: "Circular reference with arrays" failed Died on test #1 @http://localhost:8899/test/main/dump.js:279:11: expected.indexOf is not a function. (In 'expected.indexOf("[object Array]")', 'expected.indexOf' is undefined) ```
1 parent 8802caf commit 0c2bb7f

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/dump.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,10 @@ export default ( function() {
104104
stack.pop();
105105
return res;
106106
}
107-
return ( parserType === "string" ) ? parser : this.parsers.error;
107+
if ( parserType === "string" ) {
108+
return parser;
109+
}
110+
return "[ERROR: Missing QUnit.dump formatter for type " + objType + "]";
108111
},
109112
typeOf: function( obj ) {
110113
let type;
@@ -180,6 +183,9 @@ export default ( function() {
180183
error: function( error ) {
181184
return "Error(\"" + error.message + "\")";
182185
},
186+
187+
// This has been unused since QUnit 1.0.0.
188+
// @todo Deprecate and remove.
183189
unknown: "[Unknown]",
184190
"null": "null",
185191
"undefined": "undefined",

test/main/dump.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
QUnit.module( "dump", {
55
afterEach: function() {
6+
7+
// Restore default
68
QUnit.dump.maxDepth = null;
79
}
810
} );
@@ -239,6 +241,8 @@ function chainwrap( depth, first, prev ) {
239241
QUnit.test( "Check dump recursion", function( assert ) {
240242
var noref, nodump, selfref, selfdump, parentref, parentdump, circref, circdump;
241243

244+
// QUnit.dump.maxDepth = 20;
245+
242246
noref = chainwrap( 0 );
243247
nodump = QUnit.dump.parse( noref );
244248
assert.equal( nodump, "{\n \"first\": true,\n \"wrap\": undefined\n}" );
@@ -263,6 +267,8 @@ QUnit.test( "Check dump recursion", function( assert ) {
263267
QUnit.test( "Check equal/deepEqual recursion", function( assert ) {
264268
var noRecursion, selfref, circref;
265269

270+
// QUnit.dump.maxDepth = 20;
271+
266272
noRecursion = chainwrap( 0 );
267273
assert.equal( noRecursion, noRecursion, "I should be equal to me." );
268274
assert.deepEqual( noRecursion, noRecursion, "... and so in depth." );

0 commit comments

Comments
 (0)