qunitjs / qunit

🔮 An easy-to-use JavaScript unit testing framework.
https://qunitjs.com
MIT License
4.02k stars 783 forks source link

Allow raw used as an assertion message #1718

Open david-pfx opened 1 year ago

david-pfx commented 1 year ago

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.

Krinkle commented 1 year ago

@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: