Skip to content

Commit

Permalink
HTML Reporter: Fix broken "Rerun without max depth" link
Browse files Browse the repository at this point in the history
=== Background

The documentation was added in qunitjs/api.qunitjs.com#132,
but the check has always been "if (maxDepth && depth > maxDepth)",
which means the only way to disable the limit is null (or 0).

Setting -1 has never had the effect allowing infinite depth. Instead,
it is equivalent to a limit 0, whereby even `["x"]` at depth=0 is
considered exceeding -1 and thus formatted as `[object Array]`.

Note that actually setting `0` doesn't set a limit of 0, since 0
is falsey so it behaves the same as null or Infinity (i.e. no limit).

The origin of this mistake is most likely the HTML Reporter feature
that adds a "Rerun" link with "maxDepth=-1" set in the url params,
when the diff contains an "[object" placeholder indicating that
the diff is incomplete. This feature was introduced in QUnit 1.18
with e6976c3 and ecc33ac.

This feature broke the very next release in 1.19, after only a few months,
due to 825691f ("Split source to smaller files") which removed
a chunk of code from core.js without moving it elsewhere.
This chunk included:
```js
if ( urlParams.maxDepth ) {
config.maxDepth = parseInt( urlParams.maxDepth, 10 ) === -1 ?
  Number.POSITIVE_INFINITY :
  urlParams.maxDepth;
}
```

In the 1.18 release, where the feature briefly worked, it was specifically
parsing -1 in `urlParams.maxDepth` as Infinity. It did not apply to
QUnit.config.maxDepth (preconfig) and did not apply to QUnit.dump.maxDepth
(runtime changes).

=== What

I'm changing the docs for `QUnit.config.maxDepth` to say "0" for
"no limit". Our own tests used "null" which also works.

I'm standardising on "0" because it doesn't require any special-casing
that way. We can simply document it as "number", and let all ENV preconfig
and url params parse it as such, and it just works, without special
cases for somehow parsing "null" or "-1" in a special way.
  • Loading branch information
Krinkle committed Jul 14, 2024
1 parent e159093 commit 91db92d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
7 changes: 6 additions & 1 deletion docs/api/config/maxDepth.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ In the HTML Reporter, the depth up-to which an object will be serialized during
</tr>
</table>

To disable the depth limit, use a value of `-1`.
To disable the depth limit and allow infinite depth, use a value of `0`.

This is used by [`QUnit.dump.parse()`](../extension/QUnit.dump.parse.md).

## Changelog

| [QUnit 1.18](https://github.com/qunitjs/qunit/releases/tag/1.18.0) | Introduce `QUnit.config.maxDepth` to enable setting via [preconfig](./index.md). Temporary changes at runtime must change `QUnit.dump.maxDepth` instead.
| [QUnit 1.16](https://github.com/qunitjs/qunit/releases/tag/1.16.0) | Introduce `QUnit.dump.maxDepth`.
1 change: 1 addition & 0 deletions src/core/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ if (preConfig) {
// Apply QUnit.urlParams
// in accordance with /docs/api/config.index.md#order
readFlatPreconfigString(urlParams.filter, 'filter');
readFlatPreconfigNumber(urlParams.maxDepth, 'maxDepth');
readFlatPreconfigString(urlParams.module, 'module');
if (urlParams.moduleId) {
config.moduleId = [].concat(urlParams.moduleId);
Expand Down
2 changes: 1 addition & 1 deletion src/reporters/HtmlReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,7 @@ export default class HtmlReporter {
'Diff suppressed as the depth of object is more than current max depth (' +
this.config.maxDepth + ').<p>Hint: Use <code>QUnit.dump.maxDepth</code> to ' +
' run with a higher max depth or <a href="' +
escapeText(this.makeUrl({ maxDepth: -1 })) + "'>" +
escapeText(this.makeUrl({ maxDepth: 0 })) + "'>" +
'Rerun</a> without max depth.</p></td></tr>';
} else {
message += '<tr class="test-message"><th>Message: </th><td>' +
Expand Down
6 changes: 5 additions & 1 deletion test/main/dump.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
/* globals document, Symbol */

QUnit.module('dump', {
beforeEach: function () {
// Run most tests without a limit
QUnit.dump.maxDepth = 0;
},
afterEach: function () {
// Restore default
QUnit.dump.maxDepth = null;
QUnit.dump.maxDepth = 5;
}
});

Expand Down

0 comments on commit 91db92d

Please sign in to comment.