From cbadef9365c24805dc089e6e25b8a71e99678914 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Wed, 24 Feb 2021 13:53:53 +0000 Subject: [PATCH] [IMP] web: display annotated tracebacks in debug=assets Warning: this commit savagely patches qunitjs sourcecode. I know... I feel bad. Since we updated the way debug=assets work, we have a new problem in the qunit test suite: the tracebacks displayed by QUnit are relative to the bundle file, not the original file, which is annoying in practice. There is really no good way that I could find to integrate with QUnit to perform that task, so I had to do it the ugly way: modify QUnit from the inside to use the StackTrace library to annotate the traceback with the proper information. closes odoo/odoo#66771 Signed-off-by: Aaron Bohy (aab) --- addons/web/static/lib/qunit/qunit-2.9.1.js | 16 +++++++++++++++- addons/web/static/src/js/core/error_utils.js | 2 +- addons/web/static/tests/helpers/qunit_config.js | 5 +++++ 3 files changed, 21 insertions(+), 2 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 303d4fb40de..9724e74e0b9 100644 --- a/addons/web/static/lib/qunit/qunit-2.9.1.js +++ b/addons/web/static/lib/qunit/qunit-2.9.1.js @@ -8,6 +8,7 @@ * * Date: 2019-01-07T16:37Z */ + (function (global$1) { 'use strict'; @@ -21,6 +22,7 @@ var document$1 = window$1 && window$1.document; var navigator = window$1 && window$1.navigator; + var lastError = null; var localSessionStorage = function () { var x = "qunit-test-string"; @@ -3031,6 +3033,7 @@ try { runTest(this); } catch (e) { + lastError = e; this.pushFailure("Died on test #" + (this.assertions.length + 1) + " " + this.stack + ": " + (e.message || e), extractStacktrace(e, 0)); // Else next test will carry the responsibility @@ -5331,7 +5334,18 @@ assertLi.className = details.result ? "pass" : "fail"; assertLi.innerHTML = message; assertList.appendChild(assertLi); - }); + + // Odoo Customisation!!! + // Crappy hack to display traceback with sourcemaps if debug=assets + if (lastError && QUnit.annotateTraceback && odoo && odoo.debug && odoo.debug.includes("assets")) { + const pre = assertLi.querySelector("pre"); + + QUnit.annotateTraceback(lastError).then(traceback => { + pre.innerText = traceback; + }); + lastError = null; + } + }); QUnit.testDone(function (details) { var testTitle, diff --git a/addons/web/static/src/js/core/error_utils.js b/addons/web/static/src/js/core/error_utils.js index 9bdc0a1009f..2ccfb5cd6db 100644 --- a/addons/web/static/src/js/core/error_utils.js +++ b/addons/web/static/src/js/core/error_utils.js @@ -1,7 +1,7 @@ /** @odoo-module **/ import { loadJS } from "web.ajax"; - +import BrowserDetection from "web.BrowserDetection"; /** * Format the traceback of an error. Basically, we just add the error message * in the traceback if necessary (Chrome already does it by default, but not diff --git a/addons/web/static/tests/helpers/qunit_config.js b/addons/web/static/tests/helpers/qunit_config.js index 575c8022d2b..580698c5490 100644 --- a/addons/web/static/tests/helpers/qunit_config.js +++ b/addons/web/static/tests/helpers/qunit_config.js @@ -237,6 +237,11 @@ QUnit.config.urlConfig.push({ }); QUnit.begin(function() { + if (odoo.__DEBUG__.services["@web/js/core/error_utils"]) { + const errorUtils = odoo.__DEBUG__.services["@web/js/core/error_utils"]; + const { annotateTraceback } = errorUtils + QUnit.annotateTraceback = annotateTraceback + } if (QUnit.config.failfast) { QUnit.testDone(function(details) { if (details.failed > 0) {