Skip to content

Commit 73c03cf

Browse files
committed
HTML Reporter: Fix broken "Rerun without a depth limit" link (really)
Follows-up 91db92d, which recently fixed another part of the `maxDepth` feature, but left the HTML still invalid. Follows-up 47e3b99, which broke the HTML by mistakenly swapping one of the double quotes for a single quote, thus leaving the anchor element unclosed.
1 parent 3d8aae7 commit 73c03cf

File tree

4 files changed

+121
-9
lines changed

4 files changed

+121
-9
lines changed

demos/qunit-config-maxDepth.html

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>qunit-config-maxDepth</title>
6+
<link rel="stylesheet" href="../src/core/qunit.css">
7+
</head>
8+
<body>
9+
<div id="qunit"></div>
10+
<script src="../qunit/qunit.js"></script>
11+
<script>
12+
QUnit.test('example', function (assert) {
13+
// Assume default of QUnit.config.maxDepth of 5.
14+
assert.deepEqual(
15+
{
16+
one: {
17+
two: {
18+
three: {
19+
four: {
20+
five: {
21+
six: true
22+
}
23+
}
24+
}
25+
}
26+
}
27+
},
28+
{
29+
one: {
30+
two: {
31+
three: {
32+
four: {
33+
five: {
34+
six: false
35+
}
36+
}
37+
}
38+
}
39+
}
40+
}
41+
);
42+
});
43+
</script>
44+
</body>
45+
</html>

src/core/qunit.css

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,11 +313,13 @@ body {
313313
cursor: pointer;
314314
}
315315

316-
.qunit-test a {
316+
.qunit-test > a {
317317
padding: 0.5em;
318+
user-select: none;
319+
}
320+
.qunit-test a {
318321
color: inherit;
319322
text-decoration: underline;
320-
user-select: none;
321323
}
322324
.qunit-test a:hover,
323325
.qunit-test a:focus {

src/core/reporters/HtmlReporter.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -900,14 +900,17 @@ export default class HtmlReporter {
900900
message += '<tr class="test-diff"><th>Diff: </th><td><pre>'
901901
+ diffHtml + '</pre></td></tr>';
902902
}
903-
} else if (expected.indexOf('[object Array]') !== -1
904-
|| expected.indexOf('[object Object]') !== -1) {
903+
} else if (
904+
expected.indexOf('[object Array]') !== -1
905+
|| expected.indexOf('[object Object]') !== -1
906+
) {
907+
// To test this interatively, use /demos/qunit-config-maxDepth.html
905908
message += '<tr class="test-message"><th>Message: </th><td>'
906-
+ 'Diff suppressed as the depth of object is more than current max depth ('
907-
+ this.config.maxDepth + ').<p>Hint: Use <code>QUnit.dump.maxDepth</code> to '
908-
+ ' run with a higher max depth or <a href="'
909-
+ escapeText(this.makeUrl({ maxDepth: 0 })) + "'>"
910-
+ 'Rerun</a> without max depth.</p></td></tr>';
909+
+ 'Diff suppressed because the object is more than ' + this.config.maxDepth
910+
+ ' levels deep.<p>Hint: Use <code>QUnit.config.maxDepth</code> to '
911+
+ 'set a higher limit, or <a href="'
912+
+ escapeText(this.makeUrl({ maxDepth: 0 })) + '">Rerun without a depth limit</a>'
913+
+ '.</p><br/></td></tr>';
911914
} else {
912915
message += '<tr class="test-message"><th>Message: </th><td>'
913916
+ 'Diff suppressed as the expected and actual results have an equivalent'

test/main/HtmlReporter.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,68 @@ QUnit.test('test-output [trace]', function (assert) {
235235
);
236236
});
237237

238+
// For an interative test, refer to /demos/qunit-config-maxDepth.html
239+
QUnit.test('test-output [maxDepth exceeded]', function (assert) {
240+
var element = document.createElement('div');
241+
new QUnit.reporters.html(this.MockQUnit, {
242+
element: element,
243+
config: {
244+
maxDepth: 2,
245+
urlConfig: []
246+
}
247+
});
248+
QUnit.dump.maxDepth = 2;
249+
250+
this.MockQUnit.emit('runStart', { testCounts: { total: 1 } });
251+
this.MockQUnit.emit('begin', { modules: [] });
252+
this.MockQUnit.emit('testStart', { testId: '00A', name: 'A' });
253+
this.MockQUnit.emit('log', {
254+
testId: '00A',
255+
message: 'boo',
256+
result: false,
257+
actual: {
258+
one: {
259+
two: {
260+
three: 1
261+
}
262+
}
263+
},
264+
expected: {
265+
one: {
266+
two: {
267+
three: 2
268+
}
269+
}
270+
},
271+
runtime: 1
272+
});
273+
this.MockQUnit.emit('testDone', {
274+
testId: '00A',
275+
name: 'A',
276+
total: 1,
277+
passed: 1,
278+
failed: 0,
279+
runtime: 2
280+
});
281+
282+
var testOutput = element.querySelector('#qunit-test-output-00A');
283+
assert.strictEqual(
284+
testOutput.textContent,
285+
'A (1)' + 'Rerun' + '2 ms' + 'boo' + '@ 1 ms'
286+
+ 'Expected: {\n'
287+
+ ' "one": {\n'
288+
+ ' "two": [object Object]\n'
289+
+ ' }\n'
290+
+ '}'
291+
+ 'Message: Diff suppressed because the object is more than 2 levels deep.'
292+
+ 'Hint: Use QUnit.config.maxDepth to set a higher limit, or Rerun without a depth limit.',
293+
'test output'
294+
);
295+
296+
// Restore default
297+
QUnit.dump.maxDepth = 5;
298+
});
299+
238300
QUnit.test('onError [early]', function (assert) {
239301
var element = document.createElement('div');
240302
new QUnit.reporters.html(this.MockQUnit, {

0 commit comments

Comments
 (0)