From df9e546f5dca40caab77ba9acd970496b46464ab Mon Sep 17 00:00:00 2001 From: David Taylor Date: Thu, 18 Aug 2022 23:32:38 +0100 Subject: [PATCH] DEV: Abort qunit tests when clicking in the toolbar (#17989) Ever opened `/tests`, immediately tried to change the config, and got frustrated that focus keeps getting stolen by the running tests? Worry no more - this commit will make the tests auto-abort when you click any of the input/dropdowns in the QUnit header. It's not perfect - abort will wait until the end of the currently running test, so sometimes focus will be stolen one more time. But it's still a lot better than having to manually find and click the abort button. --- .../javascripts/discourse/tests/setup-tests.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app/assets/javascripts/discourse/tests/setup-tests.js b/app/assets/javascripts/discourse/tests/setup-tests.js index f8e37d3aa5..4b76abc502 100644 --- a/app/assets/javascripts/discourse/tests/setup-tests.js +++ b/app/assets/javascripts/discourse/tests/setup-tests.js @@ -150,6 +150,23 @@ function setupToolbar() { label: "Plugin", value: Array.from(pluginNames), }); + + // Abort tests when the qunit controls are clicked + document.querySelector("#qunit").addEventListener("click", ({ target }) => { + if (!target.closest("#qunit-testrunner-toolbar")) { + // Outside toolbar, carry on + return; + } + + if (target.closest("label[for=qunit-urlconfig-hidepassed]")) { + // This one can be toggled during tests, carry on + return; + } + + if (["INPUT", "SELECT", "LABEL"].includes(target.tagName)) { + document.querySelector("#qunit-abort-tests-button")?.click(); + } + }); } function reportMemoryUsageAfterTests() {