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

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

diff --git a/app/assets/javascripts/discourse/tests/setup-tests.js b/app/assets/javascripts/discourse/tests/setup-tests.js
index 7201dd8..beaa09c 100644
--- a/app/assets/javascripts/discourse/tests/setup-tests.js
+++ b/app/assets/javascripts/discourse/tests/setup-tests.js
@@ -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

GitHub sha: 89cc9103038a5f7a395665487eacca207202da35

This commit appears in #14458 which was approved by jjaffeux and CvX. It was merged by davidtaylorhq.