[IMP] web: qunit: always log name of failing test
After each test, a check is done that there is no leftover in the DOM. If there are, the suite fails, but there is no indication on the test that left elements in the DOM. This commit logs that missing information. We also stop dumping the DOM when this happens, as it was rather creating noise than providing useful information (the remaining elements are still logged though). closes odoo/odoo#58806 X-original-commit: 598d036b59012af0a95894d759fe3b6276fc8ccb Signed-off-by: Christophe Monniez (moc) <moc@odoo.com> Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
@@ -3142,7 +3142,7 @@
|
||||
this.pushFailure("Expected at least one assertion, but none were run - call " + "expect(0) to accept zero assertions.", this.stack);
|
||||
}
|
||||
|
||||
emit("OdooAfterTestHook"); // Odoo customization
|
||||
emit("OdooAfterTestHook", { moduleName: this.module.name, testName: this.testName }); // Odoo customization
|
||||
|
||||
var i,
|
||||
module = this.module,
|
||||
|
||||
@@ -159,8 +159,10 @@ QUnit.moduleDone(function(result) {
|
||||
* After each test, we check that there is no leftover in the DOM.
|
||||
*
|
||||
* Note: this event is not QUnit standard, we added it for this specific use case.
|
||||
* As a payload, an object with keys 'moduleName' and 'testName' is provided. It
|
||||
* is used to indicate the test that left elements in the DOM, when it happens.
|
||||
*/
|
||||
QUnit.on('OdooAfterTestHook', function () {
|
||||
QUnit.on('OdooAfterTestHook', function (info) {
|
||||
const toRemove = [];
|
||||
// check for leftover elements in the body
|
||||
for (const bodyChild of document.body.children) {
|
||||
@@ -168,9 +170,9 @@ QUnit.on('OdooAfterTestHook', function () {
|
||||
e.tagName === bodyChild.tagName && bodyChild[e.attr] === e.value
|
||||
);
|
||||
if (!tolerated) {
|
||||
console.error(`Test ${info.moduleName} > ${info.testName}`);
|
||||
console.error('Body still contains undesirable elements:' +
|
||||
'\nInvalid element:\n' + bodyChild.outerHTML +
|
||||
'\nBody HTML: \n' + $('body').html());
|
||||
'\nInvalid element:\n' + bodyChild.outerHTML);
|
||||
QUnit.pushFailure(`Body still contains undesirable elements`);
|
||||
}
|
||||
if (!tolerated || !tolerated.keep) {
|
||||
|
||||
Reference in New Issue
Block a user