Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HTML Reporter: Convert to HtmlReporter class
=== What === Turn html.js into an HtmlReporter class where the HtmlReporter.init static method contains (most) of the browser runner logic that we would run even if the HtmlReporter were turned off. This patch primarily deals with making html.js itself free of side-effects by delaying any browser setup logic to the init() function. In a future patch we can take this further and move the logic to a "browser runner" function of sorts, such that what is left in the reporter can be made conditional on the presence of `div[id=qunit]` and/or `QUnit.config.reporters.html`. This is tracked in qunitjs#1118 and qunitjs#1711. Ref qunitjs#1486. === Why === We need html.js to be side-effect free in order to add native ESM support, tracked at qunitjs#1551. To support native ESM exports, we need to introduce a separate distribution file since ESM export syntax isn't allowed in scripts. I expect numerous projects to involve mixed ESM imports and CJS require usage, especially when integration layers and plugins are involved. To avoid a split-brain problem, this means we need to somehow have both export the same one. The way I intend to do this is by detecting if QUnit was already defined, and if so, discard our local definition and use that one instead. This means we need to only init the browser runner only if we're the first one (e.g. window.onerror, QUnit.begin for fixture, QUnit.testDone for HTML reporting, etc). To accomplish that, start by making html.js side-effect free, deferring its init code to a (for now) unconditional call at the end of qunit.js.
- Loading branch information