From c4bddd6ba2000b2ebea36505d6f7fd627aa3338b Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Tue, 29 Sep 2020 09:45:57 +0000 Subject: [PATCH] [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) Signed-off-by: Aaron Bohy (aab) --- addons/web/static/lib/qunit/qunit-2.9.1.js | 2 +- addons/web/static/tests/helpers/qunit_config.js | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/addons/web/static/lib/qunit/qunit-2.9.1.js b/addons/web/static/lib/qunit/qunit-2.9.1.js index 1e8e542c87c..303d4fb40de 100644 --- a/addons/web/static/lib/qunit/qunit-2.9.1.js +++ b/addons/web/static/lib/qunit/qunit-2.9.1.js @@ -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, diff --git a/addons/web/static/tests/helpers/qunit_config.js b/addons/web/static/tests/helpers/qunit_config.js index 48c17d90a98..a8c42fee8b3 100644 --- a/addons/web/static/tests/helpers/qunit_config.js +++ b/addons/web/static/tests/helpers/qunit_config.js @@ -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) {