DEV: Add plugin-related parameters to the QUnit web UI

DEV: Add plugin-related parameters to the QUnit web UI

This commit also hides a number of options which are not used during Discourse development.

Change have been tested on both the legacy /qunit route, and the Ember CLI /tests route.

diff --git a/app/assets/javascripts/discourse/tests/setup-tests.js b/app/assets/javascripts/discourse/tests/setup-tests.js
index c88e08e..8ce4374 100644
--- a/app/assets/javascripts/discourse/tests/setup-tests.js
+++ b/app/assets/javascripts/discourse/tests/setup-tests.js
@@ -81,14 +81,50 @@ function createApplication(config, settings) {
   return app;
 }
 
+function setupToolbar() {
+  // Most default toolbar items aren't useful for Discourse
+  QUnit.config.urlConfig = QUnit.config.urlConfig.reject((c) =>
+    [
+      "noglobals",
+      "notrycatch",
+      "nolint",
+      "devmode",
+      "dockcontainer",
+      "nocontainer",
+    ].includes(c.id)
+  );
+
+  QUnit.config.urlConfig.push({
+    id: "qunit_skip_core",
+    label: "Skip Core",
+    value: "1",
+  });
+
+  QUnit.config.urlConfig.push({
+    id: "qunit_skip_plugins",
+    label: "Skip Plugins",
+    value: "1",
+  });
+
+  const pluginNames = new Set();
+
+  Object.keys(requirejs.entries).forEach((moduleName) => {
+    const found = moduleName.match(/\/plugins\/([\w-]+)\//);
+    if (found && moduleName.match(/\-test/)) {
+      pluginNames.add(found[1]);
+    }
+  });
+
+  QUnit.config.urlConfig.push({
+    id: "qunit_single_plugin",
+    label: "Plugin",
+    value: Array.from(pluginNames),
+  });
+}
+
 function setupTestsCommon(application, container, config) {
   QUnit.config.hidepassed = true;
 
-  // Let's customize QUnit options a bit
-  QUnit.config.urlConfig = QUnit.config.urlConfig.filter(
-    (c) => ["dockcontainer", "nocontainer"].indexOf(c.id) === -1
-  );
-
   application.rootElement = "#ember-testing";
   application.setupForTesting();
   application.injectTestHelpers();
@@ -315,6 +351,7 @@ function setupTestsCommon(application, container, config) {
   // forces 0 as duration for all jquery animations
   jQuery.fx.off = true;
 
+  setupToolbar();
   setApplication(application);
   setDefaultOwner(application.__container__);
   resetSite();
@@ -347,5 +384,17 @@ function replaceUrlParameter(name, value) {
   } else {
     queryParams.set(name, value);
   }
-  window.location = "?" + queryParams.toString();
+  history.replaceState(null, null, "?" + queryParams.toString());
+
+  QUnit.begin(() => {
+    QUnit.config[name] = value;
+    const formElement = document.querySelector(
+      `#qunit-testrunner-toolbar [name=${name}]`
+    );
+    if (formElement?.type === "checkbox") {
+      formElement.checked = !!value;
+    } else if (formElement) {
+      formElement.value = value;
+    }
+  });
 }

GitHub sha: 4bdeb457274dd36e1d763e657b323ba9ddee0e7b

This commit appears in #14401 which was approved by eviltrout. It was merged by davidtaylorhq.