DEV: Simplify test setup (#17441)
This commit is contained in:
parent
8a68f49adb
commit
8bc0ec3fac
|
@ -30,7 +30,6 @@ import deprecated from "discourse-common/lib/deprecated";
|
||||||
import { flushMap } from "discourse/services/store";
|
import { flushMap } from "discourse/services/store";
|
||||||
import { registerObjects } from "discourse/pre-initializers/inject-discourse-objects";
|
import { registerObjects } from "discourse/pre-initializers/inject-discourse-objects";
|
||||||
import sinon from "sinon";
|
import sinon from "sinon";
|
||||||
import { run } from "@ember/runloop";
|
|
||||||
import { disableCloaking } from "discourse/widgets/post-stream";
|
import { disableCloaking } from "discourse/widgets/post-stream";
|
||||||
import { clearState as clearPresenceState } from "discourse/tests/helpers/presence-pretender";
|
import { clearState as clearPresenceState } from "discourse/tests/helpers/presence-pretender";
|
||||||
import { addModuleExcludeMatcher } from "ember-cli-test-loader/test-support/index";
|
import { addModuleExcludeMatcher } from "ember-cli-test-loader/test-support/index";
|
||||||
|
@ -62,15 +61,12 @@ function AcceptanceModal(option, _relatedTarget) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let app;
|
|
||||||
let started = false;
|
let started = false;
|
||||||
|
|
||||||
function createApplication(config, settings) {
|
function createApplication(config, settings) {
|
||||||
if (app) {
|
const app = Application.create(config);
|
||||||
run(app, "destroy");
|
|
||||||
}
|
|
||||||
|
|
||||||
app = Application.create(config);
|
app.injectTestHelpers();
|
||||||
setApplication(app);
|
setApplication(app);
|
||||||
setResolver(buildResolver("discourse").create({ namespace: 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();
|
disableCloaking();
|
||||||
|
|
||||||
QUnit.config.hidepassed = true;
|
QUnit.config.hidepassed = true;
|
||||||
|
|
||||||
application.rootElement = "#ember-testing";
|
|
||||||
application.setupForTesting();
|
|
||||||
application.injectTestHelpers();
|
|
||||||
|
|
||||||
sinon.config = {
|
sinon.config = {
|
||||||
injectIntoThis: false,
|
injectIntoThis: false,
|
||||||
injectInto: null,
|
injectInto: null,
|
||||||
|
@ -225,15 +217,13 @@ function setupTestsCommon(application, container, config) {
|
||||||
setupData = setupDataElement.dataset;
|
setupData = setupDataElement.dataset;
|
||||||
setupDataElement.remove();
|
setupDataElement.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
QUnit.testStart(function (ctx) {
|
QUnit.testStart(function (ctx) {
|
||||||
bootbox.$body = $("#ember-testing");
|
bootbox.$body = $("#ember-testing");
|
||||||
let settings = resetSettings();
|
let settings = resetSettings();
|
||||||
resetThemeSettings();
|
resetThemeSettings();
|
||||||
|
|
||||||
if (config) {
|
const app = createApplication(config, settings);
|
||||||
// Ember CLI testing environment
|
|
||||||
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 : "";
|
||||||
|
@ -290,11 +280,11 @@ function setupTestsCommon(application, container, config) {
|
||||||
|
|
||||||
createHelperContext({
|
createHelperContext({
|
||||||
get siteSettings() {
|
get siteSettings() {
|
||||||
return container.lookup("site-settings:main");
|
return app.__container__.lookup("site-settings:main");
|
||||||
},
|
},
|
||||||
capabilities: {},
|
capabilities: {},
|
||||||
get site() {
|
get site() {
|
||||||
return container.lookup("site:main") || Site.current();
|
return app.__container__.lookup("site:main") || Site.current();
|
||||||
},
|
},
|
||||||
registry: app.__registry__,
|
registry: app.__registry__,
|
||||||
});
|
});
|
||||||
|
@ -381,16 +371,6 @@ function setupTestsCommon(application, container, config) {
|
||||||
|
|
||||||
setupToolbar();
|
setupToolbar();
|
||||||
reportMemoryUsageAfterTests();
|
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) {
|
function getUrlParameter(name) {
|
||||||
|
|
Loading…
Reference in New Issue