FIX: Theme tests should work in production (#13333)

FIX: Theme tests should work in production (#13333)

The ember_jquery bundle contains production builds of Ember and jQuery which doesn’t work with tests. This commits introduces a new theme_qunit_vendor bundle which is copy of the vendor bundle but doesn’t contain ember_jquery.

This commit is a partial revert of https://github.com/discourse/discourse/commit/409c8585e46250ee495356e1897a4fda905152b3

diff --git a/app/assets/javascripts/discourse/tests/theme_qunit_ember_jquery.js b/app/assets/javascripts/discourse/tests/theme_qunit_ember_jquery.js
new file mode 100644
index 0000000..caccb2d
--- /dev/null
+++ b/app/assets/javascripts/discourse/tests/theme_qunit_ember_jquery.js
@@ -0,0 +1,6 @@
+// discourse-skip-module
+
+//= require env
+//= require jquery.debug
+//= require ember.debug
+//= require discourse-loader
diff --git a/app/assets/javascripts/discourse/tests/theme_qunit_tests_vendor.js b/app/assets/javascripts/discourse/tests/theme_qunit_tests_vendor.js
new file mode 100644
index 0000000..3c6865b
--- /dev/null
+++ b/app/assets/javascripts/discourse/tests/theme_qunit_tests_vendor.js
@@ -0,0 +1,15 @@
+// discourse-skip-module
+
+//= require qunit
+//= require ember-qunit
+//= require fake_xml_http_request
+//= require route-recognizer
+//= require pretender
+
+// These are not loaded in prod or development
+// But we need them for testing handlebars templates in qunit
+//= require handlebars
+//= require ember-template-compiler
+
+//= require sinon
+//= require break_string
diff --git a/app/assets/javascripts/discourse/tests/theme_qunit_vendor.js b/app/assets/javascripts/discourse/tests/theme_qunit_vendor.js
index 3c6865b..5776eb6 100644
--- a/app/assets/javascripts/discourse/tests/theme_qunit_vendor.js
+++ b/app/assets/javascripts/discourse/tests/theme_qunit_vendor.js
@@ -1,15 +1,37 @@
-// discourse-skip-module
+// This bundle contains the same dependencies as app/assets/javascripts/vendor.js
+// minus ember_jquery.
+// ember_jquery doesn't work with theme tests in production because it
+// contains production builds of Ember and jQuery, so we have a separate bundle
+// caled theme_qunit_ember_jquery which contains a debug build for Ember and jQuery.
+// We don't put theme_qunit_ember_jquery in this bundle because it would make the
+// bundle too big and cause OOM exceptions during rebuilds for self-hosters on
+// low-end machines.
 
-//= require qunit
-//= require ember-qunit
-//= require fake_xml_http_request
-//= require route-recognizer
-//= require pretender
+//= require logster
 
-// These are not loaded in prod or development
-// But we need them for testing handlebars templates in qunit
-//= require handlebars
-//= require ember-template-compiler
+//= require template_include.js
 
-//= require sinon
-//= require break_string
+//= require message-bus
+//= require jquery.ui.widget.js
+//= require Markdown.Converter.js
+//= require bootbox.js
+//= require popper.js
+//= require bootstrap-modal.js
+//= require caret_position
+//= require jquery.color.js
+//= require jquery.fileupload.js
+//= require jquery.iframe-transport.js
+//= require jquery.tagsinput.js
+//= require jquery.sortable.js
+//= require lodash.js
+//= require mousetrap.js
+//= require mousetrap-global-bind.js
+//= require rsvp.js
+//= require show-html.js
+//= require buffered-proxy
+//= require jquery.autoellipsis-1.0.10
+//= require virtual-dom
+//= require virtual-dom-amd
+//= require intersection-observer
+//= require discourse-shims
+//= require pretty-text-bundle
diff --git a/app/views/qunit/theme.html.erb b/app/views/qunit/theme.html.erb
index c12f34a..3016de7 100644
--- a/app/views/qunit/theme.html.erb
+++ b/app/views/qunit/theme.html.erb
@@ -7,8 +7,9 @@
       <%= discourse_stylesheet_link_tag(:desktop, theme_ids: nil) %>
       <%= discourse_stylesheet_link_tag(:test_helper, theme_ids: nil) %>
       <%= preload_script "locales/en" %>
-      <%= preload_script "vendor" %>
+      <%= preload_script "discourse/tests/theme_qunit_ember_jquery" %>
       <%= preload_script "discourse/tests/theme_qunit_vendor" %>
+      <%= preload_script "discourse/tests/theme_qunit_tests_vendor" %>
       <%= preload_script "markdown-it-bundle" %>
       <%= preload_script "application" %>
       <%- Discourse.find_plugin_js_assets(include_official: allow_plugins?, include_unofficial: allow_third_party_plugins?, request: request).each do |file| %>
diff --git a/config/application.rb b/config/application.rb
index f3a47a4..b1a4d82 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -173,8 +173,10 @@ module Discourse
       confirm-new-email/bootstrap.js
       onpopstate-handler.js
       embed-application.js
-      discourse/tests/theme_qunit_helper.js
+      discourse/tests/theme_qunit_ember_jquery.js
       discourse/tests/theme_qunit_vendor.js
+      discourse/tests/theme_qunit_tests_vendor.js
+      discourse/tests/theme_qunit_helper.js
       discourse/tests/test_starter.js
     }
 
diff --git a/spec/requests/qunit_controller_spec.rb b/spec/requests/qunit_controller_spec.rb
index ec825e7..aa77731 100644
--- a/spec/requests/qunit_controller_spec.rb
+++ b/spec/requests/qunit_controller_spec.rb
@@ -98,8 +98,9 @@ describe QunitController do
         expect(response.body).to include("/stylesheets/desktop_")
         expect(response.body).to include("/stylesheets/test_helper_")
         expect(response.body).to include("/assets/locales/en.js")
-        expect(response.body).to include("/assets/vendor.js")
+        expect(response.body).to include("/assets/discourse/tests/theme_qunit_ember_jquery.js")
         expect(response.body).to include("/assets/discourse/tests/theme_qunit_vendor.js")
+        expect(response.body).to include("/assets/discourse/tests/theme_qunit_tests_vendor.js")
         expect(response.body).to include("/assets/markdown-it-bundle.js")
         expect(response.body).to include("/assets/application.js")
         expect(response.body).to include("/assets/admin.js")

GitHub sha: 940eb28e31636cf585a27daa92a1e86a14238423

This commit appears in #13333 which was approved by eviltrout. It was merged by OsamaSayegh.