diff --git a/app/assets/javascripts/discourse/tests/setup-tests.js b/app/assets/javascripts/discourse/tests/setup-tests.js index 059d4d53cae..3a48e08796e 100644 --- a/app/assets/javascripts/discourse/tests/setup-tests.js +++ b/app/assets/javascripts/discourse/tests/setup-tests.js @@ -30,7 +30,6 @@ import deprecated from "discourse-common/lib/deprecated"; import { flushMap } from "discourse/services/store"; import { registerObjects } from "discourse/pre-initializers/inject-discourse-objects"; import sinon from "sinon"; -import { run } from "@ember/runloop"; import { disableCloaking } from "discourse/widgets/post-stream"; import { clearState as clearPresenceState } from "discourse/tests/helpers/presence-pretender"; import { addModuleExcludeMatcher } from "ember-cli-test-loader/test-support/index"; @@ -62,15 +61,12 @@ function AcceptanceModal(option, _relatedTarget) { }); } -let app; let started = false; function createApplication(config, settings) { - if (app) { - run(app, "destroy"); - } + const app = Application.create(config); - app = Application.create(config); + app.injectTestHelpers(); setApplication(app); setResolver(buildResolver("discourse").create({ namespace: app })); @@ -176,15 +172,11 @@ function writeSummaryLine(message) { } } -function setupTestsCommon(application, container, config) { +export default function setupTests(config) { disableCloaking(); QUnit.config.hidepassed = true; - application.rootElement = "#ember-testing"; - application.setupForTesting(); - application.injectTestHelpers(); - sinon.config = { injectIntoThis: false, injectInto: null, @@ -225,15 +217,13 @@ function setupTestsCommon(application, container, config) { setupData = setupDataElement.dataset; setupDataElement.remove(); } + QUnit.testStart(function (ctx) { bootbox.$body = $("#ember-testing"); let settings = resetSettings(); resetThemeSettings(); - if (config) { - // Ember CLI testing environment - app = createApplication(config, settings); - } + const app = createApplication(config, settings); const cdn = setupData ? setupData.cdn : null; const baseUri = setupData ? setupData.baseUri : ""; @@ -290,11 +280,11 @@ function setupTestsCommon(application, container, config) { createHelperContext({ get siteSettings() { - return container.lookup("site-settings:main"); + return app.__container__.lookup("site-settings:main"); }, capabilities: {}, get site() { - return container.lookup("site:main") || Site.current(); + return app.__container__.lookup("site:main") || Site.current(); }, registry: app.__registry__, }); @@ -381,16 +371,6 @@ function setupTestsCommon(application, container, config) { setupToolbar(); reportMemoryUsageAfterTests(); - setApplication(application); - setDefaultOwner(application.__container__); - resetSite(); -} - -export default function setupTests(config) { - let settings = resetSettings(); - app = createApplication(config, settings); - setupTestsCommon(app, app.__container__, config); - sinon.restore(); } function getUrlParameter(name) {