Revert "FEATURE: Introduce theme/component QUnit tests (#12517)" (#12632)

Revert “FEATURE: Introduce theme/component QUnit tests (#12517)” (#12632)

This reverts commit https://github.com/discourse/discourse/commit/a53d8d3e61d33dde22628a8ceb94b6a27cb0a99a and https://github.com/discourse/discourse/commit/105634435fe605f122e4a0a4a4293cc37a6747c6.

Reverted because the change broke some components. Will be added back in a few days.

diff --git a/app/assets/javascripts/discourse/app/helpers/theme-helpers.js b/app/assets/javascripts/discourse/app/helpers/theme-helpers.js
index 477b89b..9898775 100644
--- a/app/assets/javascripts/discourse/app/helpers/theme-helpers.js
+++ b/app/assets/javascripts/discourse/app/helpers/theme-helpers.js
@@ -1,7 +1,6 @@
-import { registerUnbound } from "discourse-common/lib/helpers";
+import { helperContext, registerUnbound } from "discourse-common/lib/helpers";
 import I18n from "I18n";
 import deprecated from "discourse-common/lib/deprecated";
-import { getSetting as getThemeSetting } from "discourse/lib/theme-settings-store";
 
 registerUnbound("theme-i18n", (themeId, key, params) => {
   return I18n.t(`theme_translations.${themeId}.${key}`, params);
@@ -19,6 +18,5 @@ registerUnbound("theme-setting", (themeId, key, hash) => {
       { since: "v2.2.0.beta8", dropFrom: "v2.3.0" }
     );
   }
-
-  return getThemeSetting(themeId, key);
+  return helperContext().themeSettings.getSetting(themeId, key);
 });
diff --git a/app/assets/javascripts/discourse/app/initializers/auto-load-modules.js b/app/assets/javascripts/discourse/app/initializers/auto-load-modules.js
index fa2ca51..b985d85 100644
--- a/app/assets/javascripts/discourse/app/initializers/auto-load-modules.js
+++ b/app/assets/javascripts/discourse/app/initializers/auto-load-modules.js
@@ -19,6 +19,7 @@ export function autoLoadModules(container, registry) {
 
   let context = {
     siteSettings: container.lookup("site-settings:main"),
+    themeSettings: container.lookup("service:theme-settings"),
     keyValueStore: container.lookup("key-value-store:main"),
     capabilities: container.lookup("capabilities:main"),
     currentUser: container.lookup("current-user:main"),
diff --git a/app/assets/javascripts/discourse/app/lib/theme-settings-store.js b/app/assets/javascripts/discourse/app/lib/theme-settings-store.js
deleted file mode 100644
index 6503d6b..0000000
--- a/app/assets/javascripts/discourse/app/lib/theme-settings-store.js
+++ /dev/null
@@ -1,47 +0,0 @@
-import { get } from "@ember/object";
-
-const originalSettings = {};
-const settings = {};
-
-export function registerSettings(
-  themeId,
-  settingsObject,
-  { force = false } = {}
-) {
-  if (settings[themeId] && !force) {
-    return;
-  }
-  originalSettings[themeId] = Object.assign({}, settingsObject);
-  const s = {};
-  Object.keys(settingsObject).forEach((key) => {
-    Object.defineProperty(s, key, {
-      enumerable: true,
-      get() {
-        return settingsObject[key];
-      },
-      set(newVal) {
-        settingsObject[key] = newVal;
-      },
-    });
-  });
-  settings[themeId] = s;
-}
-
-export function getSetting(themeId, settingKey) {
-  if (settings[themeId]) {
-    return get(settings[themeId], settingKey);
-  }
-  return null;
-}
-
-export function getObjectForTheme(themeId) {
-  return settings[themeId];
-}
-
-export function resetSettings() {
-  Object.keys(originalSettings).forEach((themeId) => {
-    Object.keys(originalSettings[themeId]).forEach((key) => {
-      settings[themeId][key] = originalSettings[themeId][key];
-    });
-  });
-}
diff --git a/app/assets/javascripts/discourse/app/services/theme-settings.js b/app/assets/javascripts/discourse/app/services/theme-settings.js
new file mode 100644
index 0000000..3a1afbd
--- /dev/null
+++ b/app/assets/javascripts/discourse/app/services/theme-settings.js
@@ -0,0 +1,26 @@
+import Service from "@ember/service";
+import { get } from "@ember/object";
+
+export default Service.extend({
+  settings: null,
+
+  init() {
+    this._super(...arguments);
+    this._settings = {};
+  },
+
+  registerSettings(themeId, settingsObject) {
+    this._settings[themeId] = settingsObject;
+  },
+
+  getSetting(themeId, settingsKey) {
+    if (this._settings[themeId]) {
+      return get(this._settings[themeId], settingsKey);
+    }
+    return null;
+  },
+
+  getObjectForTheme(themeId) {
+    return this._settings[themeId];
+  },
+});
diff --git a/app/assets/javascripts/discourse/tests/setup-tests.js b/app/assets/javascripts/discourse/tests/setup-tests.js
index df1c06c..066d4ff 100644
--- a/app/assets/javascripts/discourse/tests/setup-tests.js
+++ b/app/assets/javascripts/discourse/tests/setup-tests.js
@@ -17,7 +17,6 @@ import { setupS3CDN, setupURL } from "discourse-common/lib/get-url";
 import Application from "../app";
 import MessageBus from "message-bus-client";
 import PreloadStore from "discourse/lib/preload-store";
-import { resetSettings as resetThemeSettings } from "discourse/lib/theme-settings-store";
 import QUnit from "qunit";
 import { ScrollingDOMMethods } from "discourse/mixins/scrolling";
 import Session from "discourse/models/session";
@@ -155,7 +154,6 @@ function setupTestsCommon(application, container, config) {
   QUnit.testStart(function (ctx) {
     bootbox.$body = $("#ember-testing");
     let settings = resetSettings();
-    resetThemeSettings();
 
     if (config) {
       // Ember CLI testing environment
@@ -253,8 +251,6 @@ function setupTestsCommon(application, container, config) {
   let pluginPath = getUrlParameter("qunit_single_plugin")
     ? "/" + getUrlParameter("qunit_single_plugin") + "/"
     : "/plugins/";
-  let themeOnly = getUrlParameter("theme_name") || getUrlParameter("theme_url");
-
   if (getUrlParameter("qunit_disable_auto_start") === "1") {
     QUnit.config.autostart = false;
   }
@@ -263,20 +259,8 @@ function setupTestsCommon(application, container, config) {
     let isTest = /\-test/.test(entry);
     let regex = new RegExp(pluginPath);
     let isPlugin = regex.test(entry);
-    let isTheme = /^discourse\/theme\-\d+\/.+/.test(entry);
-
-    if (!isTest) {
-      return;
-    }
-
-    if (themeOnly) {
-      if (isTheme) {
-        require(entry, null, null, true);
-      }
-      return;
-    }
 
-    if (!skipCore || isPlugin) {
+    if (isTest && (!skipCore || isPlugin)) {
       require(entry, null, null, true);
     }
   });
diff --git a/app/assets/javascripts/discourse/tests/test_helper.js b/app/assets/javascripts/discourse/tests/test_helper.js
index affd1b3..595e95e 100644
--- a/app/assets/javascripts/discourse/tests/test_helper.js
+++ b/app/assets/javascripts/discourse/tests/test_helper.js
@@ -41,3 +41,13 @@
 //= require setup-tests
 //= require test-shims
 //= require jquery.magnific-popup.min.js
+
+document.write(
+  '<div id="ember-testing-container"><div id="ember-testing"></div></div>'
+);
+document.write(
+  "<style>#ember-testing-container { position: fixed; background: white; bottom: 0; right: 0; width: 640px; height: 384px; overflow: auto; z-index: 9999; border: 1px solid #ccc; transform: translateZ(0)} #ember-testing { zoom: 50%; }</style>"
+);
+
+let setupTestsLegacy = require("discourse/tests/setup-tests").setupTestsLegacy;
+setupTestsLegacy(window.Discourse);
diff --git a/app/assets/javascripts/discourse/tests/test_starter.js b/app/assets/javascripts/discourse/tests/test_starter.js
deleted file mode 100644
index 77b69af..0000000
--- a/app/assets/javascripts/discourse/tests/test_starter.js
+++ /dev/null
@@ -1,11 +0,0 @@
-// discourse-skip-module
-
-document.write(
-  '<div id="ember-testing-container"><div id="ember-testing"></div></div>'
-);
-document.write(
-  "<style>#ember-testing-container { position: fixed; background: white; bottom: 0; right: 0; width: 640px; height: 384px; overflow: auto; z-index: 9999; border: 1px solid #ccc; transform: translateZ(0)} #ember-testing { zoom: 50%; }</style>"
-);
-
-let setupTestsLegacy = require("discourse/tests/setup-tests").setupTestsLegacy;
-setupTestsLegacy(window.Discourse);
diff --git a/app/controllers/qunit_controller.rb b/app/controllers/qunit_controller.rb
index 5e71847..f042d0a 100644
--- a/app/controllers/qunit_controller.rb
+++ b/app/controllers/qunit_controller.rb
@@ -1,26 +1,11 @@
 # frozen_string_literal: true
 
 class QunitController < ApplicationController
-  skip_before_action *%i{
-    check_xhr
-    preload_json

[... diff too long, it was truncated ...]

GitHub sha: 2b9ab3a0

This commit appears in #12632 which was approved by eviltrout. It was merged by OsamaSayegh.

This commit has been mentioned on Discourse Meta. There might be relevant details there: