DEV: Support `registerWaiter` import in legacy env (#16195)

Throw in `unregisterWaiter` too
This commit is contained in:
Jarek Radosz 2022-03-16 14:32:38 +01:00 committed by GitHub
parent c58c2f53e8
commit 704606e731
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View File

@ -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,

View File

@ -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;