DEV: Use isLegacyEmber helper in setup-tests (#14458)

We were using multiple methods to check which environment we're running in. This commit switches us to use the isLegacyEmber helper consistently. This should be a no-op, but makes the code much easier to read
This commit is contained in:
David Taylor 2021-09-28 14:30:55 +01:00 committed by GitHub
parent 7fa2eb52f7
commit 89cc910303
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 13 deletions

View File

@ -29,9 +29,9 @@ import { createHelperContext } from "discourse-common/lib/helpers";
import deprecated from "discourse-common/lib/deprecated";
import { flushMap } from "discourse/models/store";
import { registerObjects } from "discourse/pre-initializers/inject-discourse-objects";
import { setupApplicationTest } from "ember-qunit";
import sinon from "sinon";
import { run } from "@ember/runloop";
import { isLegacyEmber } from "discourse-common/config/environment";
const Plugin = $.fn.modal;
const Modal = Plugin.Constructor;
@ -286,7 +286,7 @@ function setupTestsCommon(application, container, config) {
$(".modal-backdrop").remove();
flushMap();
if (!setupApplicationTest) {
if (isLegacyEmber()) {
// ensures any event not removed is not leaking between tests
// most likely in initializers, other places (controller, component...)
// should be fixed in code
@ -335,22 +335,18 @@ function setupTestsCommon(application, container, config) {
return true;
};
try {
// Ember CLI
const emberCliTestLoader = require("ember-cli-test-loader/test-support/index");
emberCliTestLoader.addModuleExcludeMatcher(
(name) => !shouldLoadModule(name)
);
} catch (e) {
if (!String(e).indexOf("Could not find module")) {
throw e;
}
// Legacy
if (isLegacyEmber()) {
Object.keys(requirejs.entries).forEach(function (entry) {
if (shouldLoadModule(entry)) {
require(entry, null, null, true);
}
});
} else {
// Ember CLI
const emberCliTestLoader = require("ember-cli-test-loader/test-support/index");
emberCliTestLoader.addModuleExcludeMatcher(
(name) => !shouldLoadModule(name)
);
}
// forces 0 as duration for all jquery animations