REFACTOR: Import `QUnit` and related helpers rather than globals

REFACTOR: Import QUnit and related helpers rather than globals

We used many global functions to handle tests when they should be imported like other libraries in our application. This also gets us closer to the way Ember CLI prefers our tests to be laid out.

diff --git a/.eslintrc b/.eslintrc
index 8f0efcc..c311011 100644
--- a/.eslintrc
+++ b/.eslintrc
@@ -2,5 +2,11 @@
   "extends": "eslint-config-discourse",
   "rules": {
     "discourse-ember/global-ember": 2
+  },
+  "globals": {
+    "moduleFor": "off",
+    "moduleForComponent": "off",
+    "testStart": "off",
+    "testDone": "off"
   }
 }
diff --git a/app/assets/javascripts/admin/tests/admin/integration/components/group-list-setting-test.js b/app/assets/javascripts/admin/tests/admin/integration/components/group-list-setting-test.js
index 19ab163..4df70d2 100644
--- a/app/assets/javascripts/admin/tests/admin/integration/components/group-list-setting-test.js
+++ b/app/assets/javascripts/admin/tests/admin/integration/components/group-list-setting-test.js
@@ -1,3 +1,4 @@
+import { moduleForComponent } from "ember-qunit";
 import EmberObject from "@ember/object";
 import selectKit from "discourse/tests/helpers/select-kit-helper";
 import componentTest from "discourse/tests/helpers/component-test";
diff --git a/app/assets/javascripts/admin/tests/admin/integration/components/themes-list-item-test.js b/app/assets/javascripts/admin/tests/admin/integration/components/themes-list-item-test.js
index 05c52ac..70bace0 100644
--- a/app/assets/javascripts/admin/tests/admin/integration/components/themes-list-item-test.js
+++ b/app/assets/javascripts/admin/tests/admin/integration/components/themes-list-item-test.js
@@ -1,3 +1,4 @@
+import { moduleForComponent } from "ember-qunit";
 import I18n from "I18n";
 import componentTest from "discourse/tests/helpers/component-test";
 import Theme from "admin/models/theme";
diff --git a/app/assets/javascripts/admin/tests/admin/integration/components/themes-list-test.js b/app/assets/javascripts/admin/tests/admin/integration/components/themes-list-test.js
index ed462ad..7dc3779 100644
--- a/app/assets/javascripts/admin/tests/admin/integration/components/themes-list-test.js
+++ b/app/assets/javascripts/admin/tests/admin/integration/components/themes-list-test.js
@@ -1,3 +1,4 @@
+import { moduleForComponent } from "ember-qunit";
 import I18n from "I18n";
 import componentTest from "discourse/tests/helpers/component-test";
 import Theme, { THEMES, COMPONENTS } from "admin/models/theme";
diff --git a/app/assets/javascripts/admin/tests/admin/unit/controllers/admin-customize-themes-show-test.js b/app/assets/javascripts/admin/tests/admin/unit/controllers/admin-customize-themes-show-test.js
index b0e06a9..318f55f 100644
--- a/app/assets/javascripts/admin/tests/admin/unit/controllers/admin-customize-themes-show-test.js
+++ b/app/assets/javascripts/admin/tests/admin/unit/controllers/admin-customize-themes-show-test.js
@@ -1,3 +1,5 @@
+import { moduleFor } from "ember-qunit";
+import { test } from "qunit";
 import { mapRoutes } from "discourse/mapping-router";
 import Theme from "admin/models/theme";
 
@@ -8,7 +10,7 @@ moduleFor("controller:admin-customize-themes-show", {
   needs: ["controller:adminUser"],
 });
 
-QUnit.test("can display source url for remote themes", function (assert) {
+test("can display source url for remote themes", function (assert) {
   const repoUrl = "https://github.com/discourse/discourse-brand-header.git";
   const remoteTheme = Theme.create({
     id: 2,
@@ -29,9 +31,7 @@ QUnit.test("can display source url for remote themes", function (assert) {
   );
 });
 
-QUnit.test("can display source url for remote theme branches", function (
-  assert
-) {
+test("can display source url for remote theme branches", function (assert) {
   const remoteTheme = Theme.create({
     id: 2,
     default: true,
diff --git a/app/assets/javascripts/admin/tests/admin/unit/controllers/admin-customize-themes-test.js b/app/assets/javascripts/admin/tests/admin/unit/controllers/admin-customize-themes-test.js
index bd21caf..06eec98 100644
--- a/app/assets/javascripts/admin/tests/admin/unit/controllers/admin-customize-themes-test.js
+++ b/app/assets/javascripts/admin/tests/admin/unit/controllers/admin-customize-themes-test.js
@@ -1,3 +1,5 @@
+import { moduleFor } from "ember-qunit";
+import { test } from "qunit";
 import { mapRoutes } from "discourse/mapping-router";
 import Theme from "admin/models/theme";
 
@@ -8,7 +10,7 @@ moduleFor("controller:admin-customize-themes", {
   needs: ["controller:adminUser"],
 });
 
-QUnit.test("can list themes correctly", function (assert) {
+test("can list themes correctly", function (assert) {
   const defaultTheme = Theme.create({ id: 2, default: true, name: "default" });
   const userTheme = Theme.create({
     id: 3,
diff --git a/app/assets/javascripts/admin/tests/admin/unit/controllers/admin-user-badges-test.js b/app/assets/javascripts/admin/tests/admin/unit/controllers/admin-user-badges-test.js
index 175d1f2..b377f7f 100644
--- a/app/assets/javascripts/admin/tests/admin/unit/controllers/admin-user-badges-test.js
+++ b/app/assets/javascripts/admin/tests/admin/unit/controllers/admin-user-badges-test.js
@@ -1,3 +1,5 @@
+import { moduleFor } from "ember-qunit";
+import { test } from "qunit";
 import Badge from "discourse/models/badge";
 import { mapRoutes } from "discourse/mapping-router";
 
@@ -8,7 +10,7 @@ moduleFor("controller:admin-user-badges", {
   needs: ["controller:adminUser"],
 });
 
-QUnit.test("grantableBadges", function (assert) {
+test("grantableBadges", function (assert) {
   const badgeFirst = Badge.create({
     id: 3,
     name: "A Badge",
diff --git a/app/assets/javascripts/admin/tests/admin/unit/models/theme-test.js b/app/assets/javascripts/admin/tests/admin/unit/models/theme-test.js
index d05cc24..05f4dea 100644
--- a/app/assets/javascripts/admin/tests/admin/unit/models/theme-test.js
+++ b/app/assets/javascripts/admin/tests/admin/unit/models/theme-test.js
@@ -1,8 +1,9 @@
+import { test, module } from "qunit";
 import Theme from "admin/models/theme";
 
-QUnit.module("model:theme");
+module("model:theme");
 
-QUnit.test("can add an upload correctly", function (assert) {
+test("can add an upload correctly", function (assert) {
   let theme = Theme.create();
 
   assert.equal(
diff --git a/app/assets/javascripts/discourse-loader.js b/app/assets/javascripts/discourse-loader.js
index 3586997..f6aa32d 100644
--- a/app/assets/javascripts/discourse-loader.js
+++ b/app/assets/javascripts/discourse-loader.js
@@ -153,6 +153,19 @@ var define, requirejs;
       pretender: {
         default: window.Pretender,
       },
+      "ember-qunit": {
+        moduleFor: window.moduleFor,
+        moduleForComponent: window.moduleForComponent,
+      },
+      qunit:
+        typeof window.QUnit !== "undefined"
+          ? {
+              default: window.QUnit,
+              test: window.QUnit.test,
+              skip: window.QUnit.skip,
+              module: window.QUnit.module,
+            }
+          : undefined,
     };
   }
 
diff --git a/app/assets/javascripts/discourse/tests/acceptance/about-test.js b/app/assets/javascripts/discourse/tests/acceptance/about-test.js
index 3b50422..f58b5e4 100644
--- a/app/assets/javascripts/discourse/tests/acceptance/about-test.js
+++ b/app/assets/javascripts/discourse/tests/acceptance/about-test.js
@@ -1,7 +1,8 @@
+import { test } from "qunit";
 import { acceptance } from "discourse/tests/helpers/qunit-helpers";
 acceptance("About");
 
-QUnit.test("viewing", async (assert) => {
+test("viewing", async (assert) => {
   await visit("/about");
 
   assert.ok($("body.about-page").length, "has body class");
diff --git a/app/assets/javascripts/discourse/tests/acceptance/account-created-test.js b/app/assets/javascripts/discourse/tests/acceptance/account-created-test.js
index 3a93a2f..a03faf2 100644
--- a/app/assets/javascripts/discourse/tests/acceptance/account-created-test.js
+++ b/app/assets/javascripts/discourse/tests/acceptance/account-created-test.js
@@ -1,9 +1,10 @@
+import { test } from "qunit";
 import { acceptance } from "discourse/tests/helpers/qunit-helpers";
 import PreloadStore from "discourse/lib/preload-store";
 
 acceptance("Account Created");
 

[... diff too long, it was truncated ...]

GitHub sha: 71d37953

This commit appears in #10839 which was approved by CvX. It was merged by eviltrout.