From e429af8220aa8c87d6201cea6fe7f040799947da Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Wed, 10 Mar 2021 13:32:20 -0500 Subject: [PATCH] FIX: QUnit tests could time out based on load order (#12342) By default our QUnit test runner starts automatically. This is normally fine but for our `run-qunit.js` script we add a bunch of QUnit events using `eval` and sometimes those events were added after the tests already started/finished resulting in a hang. This adds a new parameter that will cause QUnit not to run automatically, which the runner uses, then triggers a `start()` when it knows it's ready. --- app/assets/javascripts/discourse/tests/setup-tests.js | 3 +++ test/run-qunit.js | 6 ++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/discourse/tests/setup-tests.js b/app/assets/javascripts/discourse/tests/setup-tests.js index 266b81b3e89..be43cc10826 100644 --- a/app/assets/javascripts/discourse/tests/setup-tests.js +++ b/app/assets/javascripts/discourse/tests/setup-tests.js @@ -244,6 +244,9 @@ function setupTestsCommon(application, container, config) { let pluginPath = getUrlParameter("qunit_single_plugin") ? "/" + getUrlParameter("qunit_single_plugin") + "/" : "/plugins/"; + if (getUrlParameter("qunit_disable_auto_start") === "1") { + QUnit.config.autostart = false; + } Object.keys(requirejs.entries).forEach(function (entry) { let isTest = /\-test/.test(entry); diff --git a/test/run-qunit.js b/test/run-qunit.js index 9438b34679f..9737efc35aa 100644 --- a/test/run-qunit.js +++ b/test/run-qunit.js @@ -106,8 +106,9 @@ async function runAllTests() { } }); - console.log("navigate to " + args[0]); - Page.navigate({ url: args[0] }); + let url = args[0] + "&qunit_disable_auto_start=1"; + console.log("navigate to ", url); + Page.navigate({ url }); Page.loadEventFired(async () => { let qff = process.env.QUNIT_FAIL_FAST; @@ -281,6 +282,7 @@ function logQUnit() { window.qunitDone = context; }); + QUnit.start(); } let qunit_script = logQUnit.toString();