From b7ce395a47c371d51041e2debbf8768a70532c24 Mon Sep 17 00:00:00 2001 From: "Lucas Perais (lpe)" Date: Thu, 2 Jun 2022 09:46:32 +0000 Subject: [PATCH] [IMP] web: qunit: debug doesn't completely finishes the test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added debugTestId url searchParam that executes that test in debug mode. While in debug mode, one can fully interact with it, and the console logs the test's internal state. closes odoo/odoo#92770 Signed-off-by: Géry Debongnie --- addons/web/static/tests/qunit.js | 41 +++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/addons/web/static/tests/qunit.js b/addons/web/static/tests/qunit.js index 5ef1748e7a7..d0417e56b82 100644 --- a/addons/web/static/tests/qunit.js +++ b/addons/web/static/tests/qunit.js @@ -308,13 +308,48 @@ errorMessages.push(info); }); - QUnit.debug = (name, cb) => { - owl.whenReady(() => document.body.classList.add("debug")); - QUnit.config.debug = true; + // Append a "Rerun in debug" link. + // Only works if the test is not hidden. + QUnit.testDone(async ({ testId}) => { + const testElement = document.getElementById(`qunit-test-output-${testId}`); + if (!testElement) { // Is probably hidden because it passed + return; + } + const reRun = testElement.querySelector("li a"); + const reRunDebug = document.createElement("a"); + reRunDebug.textContent = "Rerun in debug"; + const location = window.location; + reRunDebug.setAttribute("href", `${location.origin}${location.pathname}${location.search}&debugTestId=${testId}`); + + reRun.parentElement.insertBefore(reRunDebug, reRun.nextSibling); + }); + + function setQUnitDebugMode() { + owl.whenReady(() => document.body.classList.add("debug")); // make the test visible to the naked eye + QUnit.config.debug = true; // allows for helper functions to behave differently (logging, the HTML element in which the test occurs etc...) QUnit.config.testTimeout = 60 * 60 * 1000; + // Allows for interacting with the test when it is over + // In fact, this will pause QUnit. + // Also, logs useful info in the console. + QUnit.testDone(async (...args) => { + console.groupCollapsed("Debug Test output"); + console.log(...args); + console.groupEnd(); + await new Promise(() => {}); + }); + } + + QUnit.debug = (name, cb) => { + setQUnitDebugMode(); QUnit.only(name, cb); }; + const debugTestId = new URLSearchParams(location.search).get("debugTestId"); + if (debugTestId) { + QUnit.config.testId = [debugTestId]; + setQUnitDebugMode(); + } + // Override global UnhandledRejection that is assigned wayyy before this file // Do not really crash on non-errors rejections const qunitUnhandledReject = QUnit.onUnhandledRejection;