DEV: Support for running theme test with Ember CLI (third attempt)

DEV: Support for running theme test with Ember CLI (third attempt)

The second attempt fixed issues with smoke test.

This one makes sure minification only happens in production mode.

diff --git a/.eslintignore b/.eslintignore
index 68b8560..3956d17 100644
--- a/.eslintignore
+++ b/.eslintignore
@@ -12,7 +12,7 @@ lib/highlight_js/
 plugins/**/lib/javascripts/locale
 public/
 vendor/
-app/assets/javascripts/discourse/tests/test_helper.js
+app/assets/javascripts/discourse/tests/test-boot-rails.js
 app/assets/javascripts/discourse/tests/fixtures
 node_modules/
 dist/
diff --git a/.prettierignore b/.prettierignore
index 3884169..217c164 100644
--- a/.prettierignore
+++ b/.prettierignore
@@ -20,7 +20,7 @@ lib/highlight_js/
 plugins/**/lib/javascripts/locale
 public/
 vendor/
-app/assets/javascripts/discourse/tests/test_helper.js
+app/assets/javascripts/discourse/tests/test-boot-rails.js
 app/assets/javascripts/discourse/tests/fixtures
 node_modules/
 dist/
diff --git a/app/assets/javascripts/discourse-common/addon/lib/debounce.js b/app/assets/javascripts/discourse-common/addon/lib/debounce.js
index 5e30864..dcd2693 100644
--- a/app/assets/javascripts/discourse-common/addon/lib/debounce.js
+++ b/app/assets/javascripts/discourse-common/addon/lib/debounce.js
@@ -11,7 +11,9 @@ let testingFunc = isLegacyEmber() ? run : next;
 
 export default function () {
   if (isTesting()) {
-    return testingFunc(...arguments);
+    // Don't include the time argument (in ms)
+    let args = [].slice.call(arguments, 0, -1);
+    return testingFunc.apply(void 0, args);
   } else {
     return debounce(...arguments);
   }
diff --git a/app/assets/javascripts/discourse/ember-cli-build.js b/app/assets/javascripts/discourse/ember-cli-build.js
index 5125e7e..5ce12f6 100644
--- a/app/assets/javascripts/discourse/ember-cli-build.js
+++ b/app/assets/javascripts/discourse/ember-cli-build.js
@@ -14,6 +14,7 @@ module.exports = function (defaults) {
   let discourseRoot = resolve("../../../..");
   let vendorJs = discourseRoot + "/vendor/assets/javascripts/";
 
+  const isProduction = EmberApp.env().includes("production");
   let app = new EmberApp(defaults, {
     autoRun: false,
     "ember-qunit": {
@@ -37,8 +38,66 @@ module.exports = function (defaults) {
       // We don't use SRI in Rails. Disable here to match:
       enabled: false,
     },
+
+    "ember-cli-terser": {
+      enabled: isProduction,
+      exclude: [
+        "**/test-*.js",
+        "**/core-tests*.js",
+        "**/highlightjs/*",
+        "**/javascripts/*",
+      ],
+    },
+
+    // We need to build tests in prod for theme tests
+    tests: true,
   });
 
+  // Patching a private method is not great, but there's no other way for us to tell
+  // Ember CLI that we want the tests alone in a package without helpers/fixtures, since
+  // we re-use those in the theme tests.
+  app._defaultPackager.packageApplicationTests = function (tree) {
+    let appTestTrees = []
+      .concat(
+        this.packageEmberCliInternalFiles(),
+        this.packageTestApplicationConfig(),
+        tree
+      )
+      .filter(Boolean);
+
+    appTestTrees = mergeTrees(appTestTrees, {
+      overwrite: true,
+      annotation: "TreeMerger (appTestTrees)",
+    });
+
+    let tests = concat(appTestTrees, {
+      inputFiles: [
+        "**/tests/acceptance/*.js",
+        "**/tests/integration/*.js",
+        "**tests/unit/*.js",
+      ],
+      headerFiles: ["vendor/ember-cli/tests-prefix.js"],
+      footerFiles: ["vendor/ember-cli/app-config.js"],
+      outputFile: "/assets/core-tests.js",
+      annotation: "Concat: Core Tests",
+      sourceMapConfig: false,
+    });
+
+    let testHelpers = concat(appTestTrees, {
+      inputFiles: [
+        "**/tests/test-boot-ember-cli.js",
+        "**/tests/helpers/**/*.js",
+        "**/tests/fixtures/**/*.js",
+        "**/tests/setup-tests.js",
+      ],
+      outputFile: "/assets/test-helpers.js",
+      annotation: "Concat: Test Helpers",
+      sourceMapConfig: false,
+    });
+
+    return mergeTrees([tests, testHelpers]);
+  };
+
   // WARNING: We should only import scripts here if they are not in NPM.
   // For example: our very specific version of bootstrap-modal.
   app.import(vendorJs + "bootbox.js");
@@ -70,7 +129,6 @@ module.exports = function (defaults) {
     }),
   ]);
 
-  const isProduction = EmberApp.env().includes("production");
   if (isProduction) {
     return new AssetRev(mergedTree, {
       exclude: [
diff --git a/app/assets/javascripts/discourse/package.json b/app/assets/javascripts/discourse/package.json
index 32b1092..056a33e 100644
--- a/app/assets/javascripts/discourse/package.json
+++ b/app/assets/javascripts/discourse/package.json
@@ -34,7 +34,7 @@
     "discourse-common": "^1.0.0",
     "discourse-hbr": "^1.0.0",
     "discourse-widget-hbs": "^1.0.0",
-    "ember-auto-import": "^1.10.1",
+    "ember-auto-import": "^1.12.0",
     "ember-buffered-proxy": "^2.0.0-beta.0",
     "ember-cli": "~3.25.3",
     "ember-cli-app-version": "^4.0.0",
diff --git a/app/assets/javascripts/discourse/public/assets/scripts/discourse-test-listen-boot.js b/app/assets/javascripts/discourse/public/assets/scripts/discourse-test-listen-boot.js
new file mode 100644
index 0000000..8f46890
--- /dev/null
+++ b/app/assets/javascripts/discourse/public/assets/scripts/discourse-test-listen-boot.js
@@ -0,0 +1,4 @@
+document.write(
+  "<style>#ember-testing-container { position: fixed; background: white; bottom: 0; right: 0; width: 640px; height: 384px; overflow: auto; z-index: 9999; border: 1px solid #ccc; transform: translateZ(0)} #ember-testing { width: 200%; height: 200%; transform: scale(0.5); transform-origin: top left; }</style>"
+);
+require('discourse/tests/test-boot-ember-cli');
diff --git a/app/assets/javascripts/discourse/tests/active-plugins.js.erb b/app/assets/javascripts/discourse/tests/active-plugins.js.erb
new file mode 100644
index 0000000..6b29585
--- /dev/null
+++ b/app/assets/javascripts/discourse/tests/active-plugins.js.erb
@@ -0,0 +1,11 @@
+<%
+  DiscoursePluginRegistry.javascripts.each { |js| require_asset(js) }
+  DiscoursePluginRegistry.handlebars.each { |hb| require_asset(hb) }
+  DiscoursePluginRegistry.each_globbed_asset do |f|
+    if File.directory?(f)
+      depend_on(f)
+    else
+      require_asset(f)
+    end
+  end
+%>
diff --git a/app/assets/javascripts/discourse/tests/core-tests.js b/app/assets/javascripts/discourse/tests/core-tests.js
new file mode 100644
index 0000000..1890b65
--- /dev/null
+++ b/app/assets/javascripts/discourse/tests/core-tests.js
@@ -0,0 +1,3 @@
+//= require_tree ./acceptance
+//= require_tree ./integration
+//= require_tree ./unit
diff --git a/app/assets/javascripts/discourse/tests/core_plugins_tests.js b/app/assets/javascripts/discourse/tests/core_plugins_tests.js
deleted file mode 100644
index f9c99ce..0000000
--- a/app/assets/javascripts/discourse/tests/core_plugins_tests.js
+++ /dev/null
@@ -1,4 +0,0 @@
-//= require_tree ./acceptance
-//= require_tree ./integration
-//= require_tree ./unit
-//= require ./plugin_tests
diff --git a/app/assets/javascripts/discourse/tests/index.html b/app/assets/javascripts/discourse/tests/index.html
index 34c33c4..1c9ac2b 100644
--- a/app/assets/javascripts/discourse/tests/index.html
+++ b/app/assets/javascripts/discourse/tests/index.html
@@ -50,9 +50,14 @@
     <script src="{{rootURL}}assets/test-support.js"></script>
     <script src="{{rootURL}}assets/discourse.js"></script>
     <script src="{{rootURL}}assets/discourse-markdown.js"></script>
-    <script src="{{rootURL}}assets/discourse/tests/core_plugins_tests.js"></script>
+    <script src="{{rootURL}}assets/discourse/tests/active-plugins.js"></script>
     <script src="{{rootURL}}assets/admin.js"></script>
-    <script src="{{rootURL}}assets/tests.js"></script>
+    <script src="{{rootURL}}assets/test-helpers.js"></script>
+    <script src="{{rootURL}}assets/core-tests.js"></script>
+    <script src="{{rootURL}}assets/discourse/tests/plugin-tests.js"></script>
+    <script>
+      require('discourse/tests/test-boot-ember-cli');
+    </script>

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

GitHub sha: 6272edd1219652a8e1c9c33e16229b029cec603c

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