[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) <aab@odoo.com>
This commit is contained in:
Géry Debongnie
2021-02-25 14:45:15 +00:00
parent e2b85d4613
commit cbadef9365
3 changed files with 21 additions and 2 deletions
+15 -1
View File
@@ -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,
+1 -1
View File
@@ -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
@@ -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) {