Skip to content

Commit

Permalink
HTML Reporter: Move internal urlparams import out of html.js
Browse files Browse the repository at this point in the history
As prep to extract a reporter-agnostic "HTML Runner" from the
HTML Reporter, move the `urlparams.js` import out of html.js.

It is important (and covered by `test/reporter-html/hidepassed.html`)
that the `QUnit.begin()` callback in urlparams.js continues to run
before the one in html.js.

When only moving the import statement, this breaks because diff.js
was also importing html.js for re-use of the `escapeText` function.
As such the order in reporter.js was not what it appeared.

It appeared as:

- fixture
- diff
- html
  - urlparams

But was actually:

- fixture
- diff
  - html
    - urlparams
- html (redundant)

Ref #1118
  • Loading branch information
Krinkle committed Sep 24, 2023
1 parent f1dd012 commit 8e5f59b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 26 deletions.
22 changes: 22 additions & 0 deletions src/core/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,25 @@ export function errorString (error) {
return resultErrorString;
}
}

export function escapeText (str) {
if (!str) {
return '';
}

// Both single quotes and double quotes (for attributes)
return ('' + str).replace(/['"<>&]/g, function (s) {
switch (s) {
case "'":
return '&#039;';
case '"':
return '&quot;';
case '<':
return '&lt;';
case '>':
return '&gt;';
case '&':
return '&amp;';
}
});
}
2 changes: 1 addition & 1 deletion src/html-reporter/diff.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import QUnit from '../core';
import { escapeText } from './html';
import { escapeText } from '../core/utilities';

/*
* This file is a modified version of google-diff-match-patch's JavaScript implementation
Expand Down
26 changes: 1 addition & 25 deletions src/html-reporter/html.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import QUnit from '../core';
import { extend, errorString } from '../core/utilities';
import { extend, errorString, escapeText } from '../core/utilities';
import { window, document, navigator, console, StringMap } from '../globals';
import './urlparams';
import fuzzysort from 'fuzzysort';

const stats = {
Expand All @@ -10,29 +9,6 @@ const stats = {
completed: 0
};

// Escape text for attribute or text content.
export function escapeText (str) {
if (!str) {
return '';
}

// Both single quotes and double quotes (for attributes)
return ('' + str).replace(/['"<>&]/g, function (s) {
switch (s) {
case "'":
return '&#039;';
case '"':
return '&quot;';
case '<':
return '&lt;';
case '>':
return '&gt;';
case '&':
return '&amp;';
}
});
}

(function () {
// Don't load the HTML Reporter on non-browser environments
if (!window || !document) {
Expand Down
1 change: 1 addition & 0 deletions src/html-reporter/reporter.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import './fixture';
import './diff';
import './urlparams';
import './html';

0 comments on commit 8e5f59b

Please sign in to comment.