From 972b6bc9d1ab2d2d9241fe16e39838ed4fe822b7 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 3 Sep 2021 12:30:53 +0000 Subject: [PATCH] [IMP] web: don't check for bad dom after test on failure Currently, if a test fails there's very high chances the DOM will not be clean, because qunit doesn't have good cleanup APIs. This means a test failure will always be prefixed by a dump of the page DOM which is just confusing and makes it hard to find the actual error. This change updates the OdooAfterTestHook handler to: * Receive the `Test` itself, instead of adding more information to the synthetic object it currently receives. * Only show the leftover DOM if the test otherwise succeeded. * Do the entire reporting via `pushFailure`, rather than having duplication between an explicit `console.error` and a test failure. * Update the QUnit.log handler to - not show `undefined` - try to improve readability by removing the bracketing and quoting closes odoo/odoo#75951 Forward-port-of: #75939 X-original-commit: 8bceac8032f48ae77e8a2c0c038f3bc26489e0ac Signed-off-by: Xavier Morel (xmo) --- addons/web/static/lib/qunit/qunit-2.9.1.js | 3 ++- addons/web/static/tests/helpers/cleanup.js | 8 +++----- 2 files changed, 5 insertions(+), 6 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 7efc1f1f759..f456cc15750 100644 --- a/addons/web/static/lib/qunit/qunit-2.9.1.js +++ b/addons/web/static/lib/qunit/qunit-2.9.1.js @@ -2981,6 +2981,7 @@ } Test.prototype = { + get moduleName() { return this.module.name; }, before: function before() { var _this = this; @@ -3147,7 +3148,7 @@ this.pushFailure("Expected at least one assertion, but none were run - call " + "expect(0) to accept zero assertions.", this.stack); } - emit("OdooAfterTestHook", { moduleName: this.module.name, testName: this.testName }); // Odoo customization + emit("OdooAfterTestHook", this); // Odoo customization var i, module = this.module, diff --git a/addons/web/static/tests/helpers/cleanup.js b/addons/web/static/tests/helpers/cleanup.js index d68bc467ee3..9aeec42977c 100644 --- a/addons/web/static/tests/helpers/cleanup.js +++ b/addons/web/static/tests/helpers/cleanup.js @@ -72,17 +72,15 @@ QUnit.on("OdooAfterTestHook", function (info) { if (QUnit.config.debug) { return; } + const failed = info.testReport.getStatus() === 'failed'; const toRemove = []; // check for leftover elements in the body for (const bodyChild of document.body.children) { const tolerated = validElements.find( (e) => e.tagName === bodyChild.tagName && bodyChild.getAttribute(e.attr) === e.value ); - if (!tolerated) { - console.error( -`Test ${info.moduleName} > ${info.testName}: body still contains undesirable elements: - ${bodyChild.outerHTML}`); - QUnit.pushFailure(`Body still contains undesirable elements`); + if (!failed && !tolerated) { + QUnit.pushFailure(`Body still contains undesirable elements:\n${bodyChild.outerHTML}`); } if (!tolerated || !tolerated.keep) { toRemove.push(bodyChild);