DEV: A bunch of tests (like controller) weren't cleaning up
This creates a helper function with all the cleanup tasks we need to do after tests, then makes sure to call it after tests that previously weren't. This fixes a lot of flakey tests.
This commit is contained in:
parent
23aceedbd5
commit
2dc0f36e07
|
@ -13,7 +13,7 @@ import { forceMobile, resetMobile } from "discourse/lib/mobile";
|
||||||
import { getApplication, getContext, settled } from "@ember/test-helpers";
|
import { getApplication, getContext, settled } from "@ember/test-helpers";
|
||||||
import { getOwner } from "discourse-common/lib/get-owner";
|
import { getOwner } from "discourse-common/lib/get-owner";
|
||||||
import { later, run } from "@ember/runloop";
|
import { later, run } from "@ember/runloop";
|
||||||
import { moduleFor, setupApplicationTest } from "ember-qunit";
|
import { setupApplicationTest } from "ember-qunit";
|
||||||
import { Promise } from "rsvp";
|
import { Promise } from "rsvp";
|
||||||
import Site from "discourse/models/site";
|
import Site from "discourse/models/site";
|
||||||
import User from "discourse/models/user";
|
import User from "discourse/models/user";
|
||||||
|
@ -25,7 +25,6 @@ import { flushMap } from "discourse/services/store";
|
||||||
import { initSearchData } from "discourse/widgets/search-menu";
|
import { initSearchData } from "discourse/widgets/search-menu";
|
||||||
import { resetPostMenuExtraButtons } from "discourse/widgets/post-menu";
|
import { resetPostMenuExtraButtons } from "discourse/widgets/post-menu";
|
||||||
import { isEmpty } from "@ember/utils";
|
import { isEmpty } from "@ember/utils";
|
||||||
import { mapRoutes } from "discourse/mapping-router";
|
|
||||||
import { resetCustomPostMessageCallbacks } from "discourse/controllers/topic";
|
import { resetCustomPostMessageCallbacks } from "discourse/controllers/topic";
|
||||||
import { resetDecorators } from "discourse/widgets/widget";
|
import { resetDecorators } from "discourse/widgets/widget";
|
||||||
import { resetCache as resetOneboxCache } from "pretty-text/oneboxer";
|
import { resetCache as resetOneboxCache } from "pretty-text/oneboxer";
|
||||||
|
@ -118,18 +117,43 @@ export function applyPretender(name, server, helper) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function controllerModule(name, args = {}) {
|
// Add clean up code here to run after every test
|
||||||
moduleFor(name, name, {
|
function testCleanup() {
|
||||||
setup() {
|
flushMap();
|
||||||
this.registry.register("router:main", mapRoutes());
|
localStorage.clear();
|
||||||
let controller = this.subject();
|
User.resetCurrent();
|
||||||
controller.siteSettings = currentSettings();
|
resetExtraClasses();
|
||||||
if (args.setupController) {
|
clearOutletCache();
|
||||||
args.setupController(controller);
|
clearHTMLCache();
|
||||||
}
|
clearRewrites();
|
||||||
},
|
initSearchData();
|
||||||
needs: args.needs,
|
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) {
|
export function discourseModule(name, options) {
|
||||||
|
@ -147,6 +171,9 @@ export function discourseModule(name, options) {
|
||||||
this.siteSettings = currentSettings();
|
this.siteSettings = currentSettings();
|
||||||
clearResolverOptions();
|
clearResolverOptions();
|
||||||
});
|
});
|
||||||
|
hooks.afterEach(function () {
|
||||||
|
testCleanup();
|
||||||
|
});
|
||||||
|
|
||||||
this.getController = function (controllerName, properties) {
|
this.getController = function (controllerName, properties) {
|
||||||
let controller = this.container.lookup(`controller:${controllerName}`);
|
let controller = this.container.lookup(`controller:${controllerName}`);
|
||||||
|
@ -180,6 +207,7 @@ export function discourseModule(name, options) {
|
||||||
if (options && options.afterEach) {
|
if (options && options.afterEach) {
|
||||||
options.afterEach.call(this);
|
options.afterEach.call(this);
|
||||||
}
|
}
|
||||||
|
testCleanup();
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -270,41 +298,7 @@ export function acceptance(name, optionsOrCallback) {
|
||||||
if (options && options.afterEach) {
|
if (options && options.afterEach) {
|
||||||
options.afterEach.call(this);
|
options.afterEach.call(this);
|
||||||
}
|
}
|
||||||
flushMap();
|
testCleanup();
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
app._runInitializer("instanceInitializers", (_, initializer) => {
|
app._runInitializer("instanceInitializers", (_, initializer) => {
|
||||||
initializer.teardown?.();
|
initializer.teardown?.();
|
||||||
|
|
Loading…
Reference in New Issue