diff --git a/app/assets/javascripts/discourse/tests/helpers/qunit-helpers.js b/app/assets/javascripts/discourse/tests/helpers/qunit-helpers.js index 245f318e2b6..56a3391630c 100644 --- a/app/assets/javascripts/discourse/tests/helpers/qunit-helpers.js +++ b/app/assets/javascripts/discourse/tests/helpers/qunit-helpers.js @@ -13,7 +13,7 @@ import { forceMobile, resetMobile } from "discourse/lib/mobile"; import { getApplication, getContext, settled } from "@ember/test-helpers"; import { getOwner } from "discourse-common/lib/get-owner"; import { later, run } from "@ember/runloop"; -import { moduleFor, setupApplicationTest } from "ember-qunit"; +import { setupApplicationTest } from "ember-qunit"; import { Promise } from "rsvp"; import Site from "discourse/models/site"; import User from "discourse/models/user"; @@ -25,7 +25,6 @@ import { flushMap } from "discourse/services/store"; import { initSearchData } from "discourse/widgets/search-menu"; import { resetPostMenuExtraButtons } from "discourse/widgets/post-menu"; import { isEmpty } from "@ember/utils"; -import { mapRoutes } from "discourse/mapping-router"; import { resetCustomPostMessageCallbacks } from "discourse/controllers/topic"; import { resetDecorators } from "discourse/widgets/widget"; import { resetCache as resetOneboxCache } from "pretty-text/oneboxer"; @@ -118,18 +117,43 @@ export function applyPretender(name, server, helper) { } } -export function controllerModule(name, args = {}) { - moduleFor(name, name, { - setup() { - this.registry.register("router:main", mapRoutes()); - let controller = this.subject(); - controller.siteSettings = currentSettings(); - if (args.setupController) { - args.setupController(controller); - } - }, - needs: args.needs, - }); +// Add clean up code here to run after every test +function testCleanup() { + flushMap(); + localStorage.clear(); + User.resetCurrent(); + resetExtraClasses(); + clearOutletCache(); + clearHTMLCache(); + clearRewrites(); + initSearchData(); + resetDecorators(); + resetPostCookedDecorators(); + resetPluginOutletDecorators(); + resetTopicTitleDecorators(); + resetUsernameDecorators(); + resetOneboxCache(); + resetCustomPostMessageCallbacks(); + resetUserSearchCache(); + resetCardClickListenerSelector(); + resetComposerCustomizations(); + resetQuickSearchRandomTips(); + resetPostMenuExtraButtons(); + clearNavItems(); + setTopicList(null); + _clearSnapshots(); + cleanUpComposerUploadHandler(); + cleanUpComposerUploadMarkdownResolver(); + cleanUpComposerUploadPreProcessor(); + clearTopicFooterDropdowns(); + clearTopicFooterButtons(); + clearDesktopNotificationHandlers(); + resetLastEditNotificationClick(); + clearAuthMethods(); + setTestPresence(true); + if (!LEGACY_ENV) { + clearPresenceCallbacks(); + } } export function discourseModule(name, options) { @@ -147,6 +171,9 @@ export function discourseModule(name, options) { this.siteSettings = currentSettings(); clearResolverOptions(); }); + hooks.afterEach(function () { + testCleanup(); + }); this.getController = function (controllerName, properties) { let controller = this.container.lookup(`controller:${controllerName}`); @@ -180,6 +207,7 @@ export function discourseModule(name, options) { if (options && options.afterEach) { options.afterEach.call(this); } + testCleanup(); }, }); } @@ -270,41 +298,7 @@ export function acceptance(name, optionsOrCallback) { if (options && options.afterEach) { options.afterEach.call(this); } - flushMap(); - localStorage.clear(); - User.resetCurrent(); - resetExtraClasses(); - clearOutletCache(); - clearHTMLCache(); - clearRewrites(); - initSearchData(); - resetDecorators(); - resetPostCookedDecorators(); - resetPluginOutletDecorators(); - resetTopicTitleDecorators(); - resetUsernameDecorators(); - resetOneboxCache(); - resetCustomPostMessageCallbacks(); - resetUserSearchCache(); - resetCardClickListenerSelector(); - resetComposerCustomizations(); - resetQuickSearchRandomTips(); - resetPostMenuExtraButtons(); - clearNavItems(); - setTopicList(null); - _clearSnapshots(); - cleanUpComposerUploadHandler(); - cleanUpComposerUploadMarkdownResolver(); - cleanUpComposerUploadPreProcessor(); - clearTopicFooterDropdowns(); - clearTopicFooterButtons(); - clearDesktopNotificationHandlers(); - resetLastEditNotificationClick(); - clearAuthMethods(); - setTestPresence(true); - if (!LEGACY_ENV) { - clearPresenceCallbacks(); - } + testCleanup(); app._runInitializer("instanceInitializers", (_, initializer) => { initializer.teardown?.();