qunit
qunit copied to clipboard
Allow raw HTML as an assertion message
Using 2.19.4, Windows, browser
New feature: config option to bypass the call to EscapeText at around line 5783:
var message = escapeText(details.message) || (details.result ? 'okay' : 'failed');
Very useful feature to put formatting and links in assertion messages.
@david-pfx I'm interested in exploring this, and like the idea of allowing rich text formatting. This would unlock many interesting features.
QUnit output is often passed through (or presented in) contexts where there is no HTML support. For example, most CI systems these days present build output as plain text (Jenkins, Travis CI, GitHub Actions, etc.). This includes e.g. when one uses cross-browser runners such as Karma, Headless Chrome via grunt-contrib-qunit, cloud browsers such via browserstack-runner, or e.g. when using QUnit to test a Node.js package.
Other examples exist within the browser, when using the TAP reporter, which prints to the browser console. While this is testing frontend JavaScript inside a browser, the web page is empty, with the QUnit results printed in the browser console.
If your need is mainly to make links clickable, perhaps an alternative would be for QUnit to do what browsers, terminals, and CI systems also do with their output - they automaticlaly scan for URLs in the plain text, and turn them into clickable links. Would that work for you?
A few other ideas based on your HTML proposal:
- QUnit could render the HTML code as unparsed HTML in these contexts. This seems suboptimal as that would look broken.
- QUnit could try to strip the HTML tags and render the remaining text. This would be fine for simple text styling, but for links this would make the URL inaccessible.
- QUnit could require that, if you specify an HTML message, that you also specify a plain text version. This would place extra work on developers and make for a more complicated Assertion API.