From 8e5f59bfd2d436c4fe0256755f0f66561597040b Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Sun, 24 Sep 2023 14:32:55 -0700 Subject: [PATCH] HTML Reporter: Move internal `urlparams` import out of html.js 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 https://github.com/qunitjs/qunit/issues/1118 --- src/core/utilities.js | 22 ++++++++++++++++++++++ src/html-reporter/diff.js | 2 +- src/html-reporter/html.js | 26 +------------------------- src/html-reporter/reporter.js | 1 + 4 files changed, 25 insertions(+), 26 deletions(-) diff --git a/src/core/utilities.js b/src/core/utilities.js index a1bbe16b6..6b8d51dcd 100644 --- a/src/core/utilities.js +++ b/src/core/utilities.js @@ -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 '''; + case '"': + return '"'; + case '<': + return '<'; + case '>': + return '>'; + case '&': + return '&'; + } + }); +} diff --git a/src/html-reporter/diff.js b/src/html-reporter/diff.js index bbe306d9f..eb8fb97c5 100644 --- a/src/html-reporter/diff.js +++ b/src/html-reporter/diff.js @@ -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 diff --git a/src/html-reporter/html.js b/src/html-reporter/html.js index bad16362f..7a4ba76b6 100644 --- a/src/html-reporter/html.js +++ b/src/html-reporter/html.js @@ -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 = { @@ -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 '''; - case '"': - return '"'; - case '<': - return '<'; - case '>': - return '>'; - case '&': - return '&'; - } - }); -} - (function () { // Don't load the HTML Reporter on non-browser environments if (!window || !document) { diff --git a/src/html-reporter/reporter.js b/src/html-reporter/reporter.js index ebdd17b57..7b41864b9 100644 --- a/src/html-reporter/reporter.js +++ b/src/html-reporter/reporter.js @@ -1,3 +1,4 @@ import './fixture'; import './diff'; +import './urlparams'; import './html';