DEV: Abstract `Ember.testing` so our application code doesn't use it

DEV: Abstract Ember.testing so our application code doesn’t use it

diff --git a/app/assets/javascripts/discourse-common/addon/config/environment.js b/app/assets/javascripts/discourse-common/addon/config/environment.js
index 18ce3cc..8d684bf 100644
--- a/app/assets/javascripts/discourse-common/addon/config/environment.js
+++ b/app/assets/javascripts/discourse-common/addon/config/environment.js
@@ -1,3 +1,9 @@
 export const INPUT_DELAY = 250;
 
-export default { environment: Ember.testing ? "test" : "development" };
+let environment = Ember.testing ? "test" : "development";
+
+export function isTesting() {
+  return environment === "test";
+}
+
+export default { environment };
diff --git a/app/assets/javascripts/discourse/app/helpers/page-reloader.js b/app/assets/javascripts/discourse/app/helpers/page-reloader.js
index a227bec..e2b8382 100644
--- a/app/assets/javascripts/discourse/app/helpers/page-reloader.js
+++ b/app/assets/javascripts/discourse/app/helpers/page-reloader.js
@@ -1,7 +1,7 @@
-import Ember from "ember";
+import { isTesting } from "discourse-common/config/environment";
 
 export function reload() {
-  if (!Ember.testing) {
+  if (!isTesting()) {
     location.reload();
   }
 }
diff --git a/app/assets/javascripts/discourse/app/lib/category-tag-search.js b/app/assets/javascripts/discourse/app/lib/category-tag-search.js
index 85b17f5..9a370f0 100644
--- a/app/assets/javascripts/discourse/app/lib/category-tag-search.js
+++ b/app/assets/javascripts/discourse/app/lib/category-tag-search.js
@@ -5,10 +5,11 @@ import { TAG_HASHTAG_POSTFIX } from "discourse/lib/tag-hashtags";
 import { SEPARATOR } from "discourse/lib/category-hashtags";
 import { Promise } from "rsvp";
 import { later, cancel } from "@ember/runloop";
+import { isTesting } from "discourse-common/config/environment";
 
-var cache = {};
-var cacheTime;
-var oldSearch;
+let cache = {};
+let cacheTime;
+let oldSearch;
 
 function updateCache(term, results) {
   cache[term] = results;
@@ -22,7 +23,7 @@ function searchTags(term, categories, limit) {
       () => {
         resolve(CANCELLED_STATUS);
       },
-      Ember.testing ? 50 : 5000
+      isTesting() ? 50 : 5000
     );
 
     const debouncedSearch = discourseDebounce((q, cats, resultFunc) => {
diff --git a/app/assets/javascripts/discourse/app/lib/user-search.js b/app/assets/javascripts/discourse/app/lib/user-search.js
index 86d7d46..5a63122 100644
--- a/app/assets/javascripts/discourse/app/lib/user-search.js
+++ b/app/assets/javascripts/discourse/app/lib/user-search.js
@@ -4,6 +4,7 @@ import { userPath } from "discourse/lib/url";
 import { emailValid } from "discourse/lib/utilities";
 import { Promise } from "rsvp";
 import { later, cancel } from "@ember/runloop";
+import { isTesting } from "discourse-common/config/environment";
 
 var cache = {},
   cacheKey,
@@ -185,7 +186,7 @@ export default function userSearch(options) {
       () => {
         resolve(CANCELLED_STATUS);
       },
-      Ember.testing ? 50 : 5000
+      isTesting() ? 50 : 5000
     );
 
     if (skipSearch(term, options.allowEmails)) {

GitHub sha: 3fe5eacd

1 Like