From 89cc9103038a5f7a395665487eacca207202da35 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Tue, 28 Sep 2021 14:30:55 +0100 Subject: [PATCH] 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 --- .../discourse/tests/setup-tests.js | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/app/assets/javascripts/discourse/tests/setup-tests.js b/app/assets/javascripts/discourse/tests/setup-tests.js index 7201dd80585..beaa09ca814 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