From 704606e73158875956366d25368761965128a2a6 Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Wed, 16 Mar 2022 14:32:38 +0100 Subject: [PATCH] DEV: Support `registerWaiter` import in legacy env (#16195) Throw in `unregisterWaiter` too --- app/assets/javascripts/discourse-loader.js | 4 ++++ app/assets/javascripts/discourse/app/lib/load-script.js | 7 +++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/discourse-loader.js b/app/assets/javascripts/discourse-loader.js index e55edf45cc7..3416edbdffe 100644 --- a/app/assets/javascripts/discourse-loader.js +++ b/app/assets/javascripts/discourse-loader.js @@ -164,6 +164,10 @@ var define, requirejs; "@ember/object/internals": { guidFor: Ember.guidFor, }, + "@ember/test": { + registerWaiter: Ember.Test.registerWaiter, + unregisterWaiter: Ember.Test.unregisterWaiter, + }, I18n: { // eslint-disable-next-line default: I18n, diff --git a/app/assets/javascripts/discourse/app/lib/load-script.js b/app/assets/javascripts/discourse/app/lib/load-script.js index b4bee3cc30a..38d2710e1f6 100644 --- a/app/assets/javascripts/discourse/app/lib/load-script.js +++ b/app/assets/javascripts/discourse/app/lib/load-script.js @@ -3,6 +3,8 @@ import { PUBLIC_JS_VERSIONS } from "discourse/lib/public-js-versions"; import { Promise } from "rsvp"; import { ajax } from "discourse/lib/ajax"; import { run } from "@ember/runloop"; +import { isTesting } from "discourse-common/config/environment"; +import { registerWaiter } from "@ember/test"; const _loaded = {}; const _loading = {}; @@ -14,8 +16,9 @@ function loadWithTag(path, cb) { let s = document.createElement("script"); s.src = path; - // eslint-disable-next-line no-undef - Ember.Test?.registerWaiter(() => finished); + if (isTesting()) { + registerWaiter(() => finished); + } s.onload = s.onreadystatechange = function (_, abort) { finished = true;