From 210d13e3cb1809527fa2d12764768a446d2572fb Mon Sep 17 00:00:00 2001 From: Godfrey Chan Date: Wed, 11 Oct 2023 14:20:02 -0700 Subject: [PATCH] DEV: fix setting isTesting (#23901) This started out as a seemingly benign refactor to replace the `require` for `withPluginApi` to an actual import. However, it broke the test in seemingly random places. It turns out that in serveral places, we are calling `isTesting()` in module scope and assigning the result to a constant. For example we do that in the composer service to disable checking drafts when testing. This is problematic because `isTesting` doesn't really set until the `discourse-bootstrap` initializer is run, and so any modules that are evaluated before then will have locked in the wrong value for `isTesting()`. If we are going to use and treat `isTesting()` like a constant then we will have to make sure we set it sufficiently early before any code-loading happens. --- app/assets/javascripts/discourse/app/app.js | 5 ++--- .../public/assets/scripts/discourse-test-listen-boot.js | 1 + .../assets/scripts/discourse-test-trigger-ember-cli-boot.js | 1 + .../javascripts/discourse/tests/test-boot-ember-cli.js | 3 --- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/discourse/app/app.js b/app/assets/javascripts/discourse/app/app.js index 8c0174c0c86..c250c6f79e8 100644 --- a/app/assets/javascripts/discourse/app/app.js +++ b/app/assets/javascripts/discourse/app/app.js @@ -2,10 +2,11 @@ import Application from "@ember/application"; import "./global-compat"; import "./loader-shims"; import require from "require"; +import { normalizeEmberEventHandling } from "discourse/lib/ember-events"; import { registerDiscourseImplicitInjections } from "discourse/lib/implicit-injections"; +import { withPluginApi } from "discourse/lib/plugin-api"; import { isTesting } from "discourse-common/config/environment"; import { buildResolver } from "discourse-common/resolver"; -import { normalizeEmberEventHandling } from "./lib/ember-events"; const _pluginCallbacks = []; let _unhandledThemeErrors = []; @@ -147,8 +148,6 @@ function loadInitializers(app) { } // Plugins that are registered via `