Skip to content

Commit

Permalink
HTML Reporter: Change #qunit-testresult from P to DIV
Browse files Browse the repository at this point in the history
The previous DOM structure was impossible to represent in an HTML
string, which meant that systems like TestSwarm that serialize the
page and save or transfer it elsewhere, will end up with a corruption
when that same page is then retrieved and rendered again later, because
the element will be implicitly closed by the first DIV child.

The paragraph was already styled with `margin/padding: 0`, so this
makes no visual difference.

The Theme API has only been documented since yesterday during the
QUnit 3.0 dev cycle. Given this wasn't documented before, any change
is considered a breaking change and thus part of QUnit 3.0.

Going forward, the Theme API documents the selector for this by ID
only, not by tag name. That documentation was written based on how
most themes seem to style it, hence this is not likely to break
themes in practice.

Fixes #1301.
  • Loading branch information
Krinkle committed Jul 1, 2024
1 parent 438ce6b commit f3faf02
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
22 changes: 21 additions & 1 deletion docs/browser.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,17 +184,37 @@ For failed assertions, the parenthical reports the failed, passed, and total num

The HTML Reporter populates the `<div id="qunit">` element with the following structure:

QUnit 1.x, 2.x:

```html
<div id="qunit">
<h1 id="qunit-header">…</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar">…</div>
<h2 id="qunit-userAgent">¬</h2>
<h2 id="qunit-userAgent"></h2>
<p id="qunit-testresult">…</p>
<ol id="qunit-tests"></ol>
</div>
```

<details markdown="1">
<summary>As of QUnit 3.0</summary>

```html
<div id="qunit">
<h1 id="qunit-header">…</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar">…</div>
<h2 id="qunit-userAgent">…</h2>
<div id="qunit-testresult">…</div>
<ol id="qunit-tests"></ol>
</div>
```

</details>

-----

You can style these to create your own theme, or add custom styles to the default theme.

Examples: [Theme plugins](./plugins.md)
Expand Down
2 changes: 1 addition & 1 deletion src/reporters/HtmlReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ export default class HtmlReporter {

if (tests) {
tests.innerHTML = '';
result = document.createElement('p');
result = document.createElement('div');
result.id = 'qunit-testresult';
result.className = 'result';
tests.parentNode.insertBefore(result, tests);
Expand Down

0 comments on commit f3faf02

Please sign in to comment.