DEV: Do the full cleanup after **every** test (#17943)
Previously the global state wasn't cleared in some cases leading to widespread test failures.
This commit is contained in:
parent
655941b79c
commit
53af30ec3f
|
@ -7,7 +7,6 @@ import { autoLoadModules } from "discourse/initializers/auto-load-modules";
|
||||||
import QUnit, { test } from "qunit";
|
import QUnit, { test } from "qunit";
|
||||||
import { setupRenderingTest as emberSetupRenderingTest } from "ember-qunit";
|
import { setupRenderingTest as emberSetupRenderingTest } from "ember-qunit";
|
||||||
import { currentSettings } from "discourse/tests/helpers/site-settings";
|
import { currentSettings } from "discourse/tests/helpers/site-settings";
|
||||||
import { testCleanup } from "discourse/tests/helpers/qunit-helpers";
|
|
||||||
import { injectServiceIntoService } from "discourse/pre-initializers/inject-discourse-objects";
|
import { injectServiceIntoService } from "discourse/pre-initializers/inject-discourse-objects";
|
||||||
|
|
||||||
export function setupRenderingTest(hooks) {
|
export function setupRenderingTest(hooks) {
|
||||||
|
@ -16,11 +15,7 @@ export function setupRenderingTest(hooks) {
|
||||||
hooks.beforeEach(function () {
|
hooks.beforeEach(function () {
|
||||||
if (!hooks.usingDiscourseModule) {
|
if (!hooks.usingDiscourseModule) {
|
||||||
this.siteSettings = currentSettings();
|
this.siteSettings = currentSettings();
|
||||||
|
this.registry ||= this.owner.__registry__;
|
||||||
if (!this.registry) {
|
|
||||||
this.registry = this.owner.__registry__;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.container = this.owner;
|
this.container = this.owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,12 +55,6 @@ export function setupRenderingTest(hooks) {
|
||||||
|
|
||||||
$.fn.autocomplete = function () {};
|
$.fn.autocomplete = function () {};
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!hooks.usingDiscourseModule) {
|
|
||||||
hooks.afterEach(function () {
|
|
||||||
testCleanup(this.container);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function (name, hooks, opts) {
|
export default function (name, hooks, opts) {
|
||||||
|
|
|
@ -222,8 +222,6 @@ export function discourseModule(name, options) {
|
||||||
this.siteSettings = currentSettings();
|
this.siteSettings = currentSettings();
|
||||||
});
|
});
|
||||||
|
|
||||||
hooks.afterEach(() => testCleanup(this.container));
|
|
||||||
|
|
||||||
this.getController = function (controllerName, properties) {
|
this.getController = function (controllerName, properties) {
|
||||||
let controller = this.container.lookup(`controller:${controllerName}`);
|
let controller = this.container.lookup(`controller:${controllerName}`);
|
||||||
controller.application = {};
|
controller.application = {};
|
||||||
|
@ -251,7 +249,6 @@ export function discourseModule(name, options) {
|
||||||
},
|
},
|
||||||
afterEach() {
|
afterEach() {
|
||||||
options?.afterEach?.call(this);
|
options?.afterEach?.call(this);
|
||||||
testCleanup(this.container);
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ import {
|
||||||
applyPretender,
|
applyPretender,
|
||||||
exists,
|
exists,
|
||||||
resetSite,
|
resetSite,
|
||||||
|
testCleanup,
|
||||||
testsInitialized,
|
testsInitialized,
|
||||||
testsTornDown,
|
testsTornDown,
|
||||||
} from "discourse/tests/helpers/qunit-helpers";
|
} from "discourse/tests/helpers/qunit-helpers";
|
||||||
|
@ -11,7 +12,7 @@ import pretender, {
|
||||||
resetPretender,
|
resetPretender,
|
||||||
} from "discourse/tests/helpers/create-pretender";
|
} from "discourse/tests/helpers/create-pretender";
|
||||||
import { resetSettings } from "discourse/tests/helpers/site-settings";
|
import { resetSettings } from "discourse/tests/helpers/site-settings";
|
||||||
import { setDefaultOwner } from "discourse-common/lib/get-owner";
|
import { getOwner, setDefaultOwner } from "discourse-common/lib/get-owner";
|
||||||
import { setApplication, setResolver } from "@ember/test-helpers";
|
import { setApplication, setResolver } from "@ember/test-helpers";
|
||||||
import { setupS3CDN, setupURL } from "discourse-common/lib/get-url";
|
import { setupS3CDN, setupURL } from "discourse-common/lib/get-url";
|
||||||
import Application from "../app";
|
import Application from "../app";
|
||||||
|
@ -217,12 +218,13 @@ export default function setupTests(config) {
|
||||||
setupDataElement.remove();
|
setupDataElement.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let app;
|
||||||
QUnit.testStart(function (ctx) {
|
QUnit.testStart(function (ctx) {
|
||||||
bootbox.$body = $("#ember-testing");
|
bootbox.$body = $("#ember-testing");
|
||||||
let settings = resetSettings();
|
let settings = resetSettings();
|
||||||
resetThemeSettings();
|
resetThemeSettings();
|
||||||
|
|
||||||
const app = createApplication(config, settings);
|
app = createApplication(config, settings);
|
||||||
|
|
||||||
const cdn = setupData ? setupData.cdn : null;
|
const cdn = setupData ? setupData.cdn : null;
|
||||||
const baseUri = setupData ? setupData.baseUri : "";
|
const baseUri = setupData ? setupData.baseUri : "";
|
||||||
|
@ -296,6 +298,8 @@ export default function setupTests(config) {
|
||||||
});
|
});
|
||||||
|
|
||||||
QUnit.testDone(function () {
|
QUnit.testDone(function () {
|
||||||
|
testCleanup(getOwner(app), app);
|
||||||
|
|
||||||
sinon.restore();
|
sinon.restore();
|
||||||
resetPretender();
|
resetPretender();
|
||||||
clearPresenceState();
|
clearPresenceState();
|
||||||
|
|
Loading…
Reference in New Issue