Skip to content

A platform for community discussion. Free, open, simple.

FIX: Defer scripts on theme-tests route (#17171)

Joe03ffb0bf27d7
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
index 8f46890eb42..21f78628fd3 100644
--- 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
@@ -1,4 +1,9 @@
-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>"
+document.body.insertAdjacentHTML(
+ "afterbegin",
+ `
+ <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/helpers/qunit_helper.rb b/app/helpers/qunit_helper.rb
index e0376a1ad26..3ca1b419bfc 100644
--- a/app/helpers/qunit_helper.rb
+++ b/app/helpers/qunit_helper.rb
@@ -10,6 +10,6 @@ module QunitHelper
"#{Discourse.base_path}" \
"/theme-javascripts/tests/#{theme.id}-#{digest}.js" \
"?__ws=#{Discourse.current_hostname}"
- "<script src='#{src}'></script>".html_safe
+ "<script defer src='#{src}'></script>".html_safe
end
end
diff --git a/app/views/qunit/theme.html.erb b/app/views/qunit/theme.html.erb
index 5b2b4c1cdee..bee0041d9e0 100644
--- a/app/views/qunit/theme.html.erb
+++ b/app/views/qunit/theme.html.erb
@@ -30,7 +30,7 @@
</style>
<%- end %>
<%- if params['testem'] %>
- <script src="/assets/testem.js"></script>
+ <script defer src="/assets/testem.js"></script>
<%- end %>
</head>
<body>