REFACTOR: Use imports for `sinon` and `setResolver`

REFACTOR: Use imports for sinon and setResolver

I also took the opportunity with this commit to move some test specific stuff out of discourse-loader which is loaded on the front end of the application. The test module building now happens in the test_helper bundle.

diff --git a/.eslintrc b/.eslintrc
index c311011..4719bf3 100644
--- a/.eslintrc
+++ b/.eslintrc
@@ -7,6 +7,7 @@
     "moduleFor": "off",
     "moduleForComponent": "off",
     "testStart": "off",
-    "testDone": "off"
+    "testDone": "off",
+    "sinon": "off"
   }
 }
diff --git a/app/assets/javascripts/discourse-loader.js b/app/assets/javascripts/discourse-loader.js
index f6aa32d..a953157 100644
--- a/app/assets/javascripts/discourse-loader.js
+++ b/app/assets/javascripts/discourse-loader.js
@@ -146,26 +146,13 @@ var define, requirejs;
       "@ember/object/internals": {
         guidFor: Ember.guidFor,
       },
+      "@ember/test-helpers": {
+        setResolver: window.setResolver,
+      },
       I18n: {
         // eslint-disable-next-line
         default: I18n,
       },
-      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/setup-tests.js b/app/assets/javascripts/discourse/tests/setup-tests.js
index dc2ed57..8f8f689 100644
--- a/app/assets/javascripts/discourse/tests/setup-tests.js
+++ b/app/assets/javascripts/discourse/tests/setup-tests.js
@@ -24,9 +24,11 @@ import { clearAppEventsCache } from "discourse/services/app-events";
 import QUnit from "qunit";
 import MessageBus from "message-bus-client";
 import deprecated from "discourse-common/lib/deprecated";
+import sinon from "sinon";
+import { setResolver } from "@ember/test-helpers";
 
 export default function setupTests(App) {
-  window.setResolver(buildResolver("discourse").create({ namespace: App }));
+  setResolver(buildResolver("discourse").create({ namespace: App }));
 
   sinon.config = {
     injectIntoThis: false,
diff --git a/app/assets/javascripts/discourse/tests/test_helper.js b/app/assets/javascripts/discourse/tests/test_helper.js
index 125e8e5..d84c9b1 100644
--- a/app/assets/javascripts/discourse/tests/test_helper.js
+++ b/app/assets/javascripts/discourse/tests/test_helper.js
@@ -1,6 +1,5 @@
 // discourse-skip-module
 
-/*global document, sinon, QUnit, Logster */
 //= require env
 //= require jquery.debug
 //= require jquery.ui.widget
@@ -41,8 +40,7 @@
 //= require_tree ../../admin/tests/admin
 //= require plugin_tests
 //= require setup-tests
-//= require_self
-//
+//= require test-shims
 //= require jquery.magnific-popup.min.js
 
 let setupTests = require("discourse/tests/setup-tests").default;
diff --git a/app/assets/javascripts/discourse/tests/unit/lib/formatter-test.js b/app/assets/javascripts/discourse/tests/unit/lib/formatter-test.js
index 22914c5..15de4b5 100644
--- a/app/assets/javascripts/discourse/tests/unit/lib/formatter-test.js
+++ b/app/assets/javascripts/discourse/tests/unit/lib/formatter-test.js
@@ -8,6 +8,7 @@ import {
   durationTiny,
 } from "discourse/lib/formatter";
 import { discourseModule } from "discourse/tests/helpers/qunit-helpers";
+import sinon from "sinon";
 
 discourseModule("lib:formatter", {
   beforeEach() {
diff --git a/app/assets/javascripts/discourse/tests/unit/models/topic-tracking-state-test.js b/app/assets/javascripts/discourse/tests/unit/models/topic-tracking-state-test.js
index 313c6d8..45f03b7 100644
--- a/app/assets/javascripts/discourse/tests/unit/models/topic-tracking-state-test.js
+++ b/app/assets/javascripts/discourse/tests/unit/models/topic-tracking-state-test.js
@@ -4,6 +4,7 @@ import createStore from "discourse/tests/helpers/create-store";
 import Category from "discourse/models/category";
 import { NotificationLevels } from "discourse/lib/notification-levels";
 import User from "discourse/models/user";
+import sinon from "sinon";
 
 module("model:topic-tracking-state", {
   beforeEach() {
diff --git a/app/assets/javascripts/test-shims.js b/app/assets/javascripts/test-shims.js
new file mode 100644
index 0000000..c9f47d5
--- /dev/null
+++ b/app/assets/javascripts/test-shims.js
@@ -0,0 +1,27 @@
+// discourse-skip-module
+
+define("sinon", () => {
+  return { default: window.sinon };
+});
+define("qunit", () => {
+  return {
+    default: window.QUnit,
+    test: window.QUnit.test,
+    skip: window.QUnit.skip,
+    module: window.QUnit.module,
+  };
+});
+define("ember-qunit", () => {
+  return {
+    moduleFor: window.moduleFor,
+    moduleForComponent: window.moduleForComponent,
+  };
+});
+define("@ember/test-helpers", () => {
+  return {
+    setResolver: window.setResolver,
+  };
+});
+define("pretender", () => {
+  return { default: window.Pretender };
+});
diff --git a/app/assets/javascripts/wizard/test/test_helper.js b/app/assets/javascripts/wizard/test/test_helper.js
index 31e0805..c7e818c 100644
--- a/app/assets/javascripts/wizard/test/test_helper.js
+++ b/app/assets/javascripts/wizard/test/test_helper.js
@@ -23,6 +23,7 @@
 //= require_tree ./models
 //= require_tree ./components
 //= require ./wizard-pretender
+//= require test-shims
 
 // Trick JSHint into allow document.write
 var d = document;
diff --git a/plugins/discourse-local-dates/test/javascripts/lib/local-date-builder-test.js.es6 b/plugins/discourse-local-dates/test/javascripts/lib/local-date-builder-test.js.es6
index bfd3467..f64d49b 100644
--- a/plugins/discourse-local-dates/test/javascripts/lib/local-date-builder-test.js.es6
+++ b/plugins/discourse-local-dates/test/javascripts/lib/local-date-builder-test.js.es6
@@ -1,5 +1,6 @@
 import I18n from "I18n";
 import LocalDateBuilder from "./local-date-builder";
+import sinon from "sinon";
 
 const UTC = "Etc/UTC";
 const SYDNEY = "Australia/Sydney";

GitHub sha: 38620364

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