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 #1118 and #1711. Ref #1486. Intentional changes: * Use of previousFailure is no longer conditional on QUnit.config.reorder in order to make it more stateless. The message already did not state that it relates to config.reorder, and stating that it previously failed is accurate either way. * Calling ev.preventDefault() is no longer conditional. This has been supported since IE9. QUnit 2 already required IE9+, and QUnit 3.0 will require IE11. jQuery removed similar check in jQuery 2.2.0, with commit jquery/jquery@a873558436. === Why === We need html.js to be side-effect free in order to add native ESM support, tracked at #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