diff --git a/app/assets/javascripts/discourse/lib/bootstrap-json/index.js b/app/assets/javascripts/discourse/lib/bootstrap-json/index.js index b2b243fdc56..1c778d80a02 100644 --- a/app/assets/javascripts/discourse/lib/bootstrap-json/index.js +++ b/app/assets/javascripts/discourse/lib/bootstrap-json/index.js @@ -429,6 +429,8 @@ module.exports = { `` ) .join("\n"); + } else if (shouldLoadPluginTestJs() && type === "test-plugin-css") { + return ``; } }, diff --git a/app/assets/javascripts/discourse/public/assets/scripts/discourse-test-load-dynamic-js.js b/app/assets/javascripts/discourse/public/assets/scripts/discourse-test-load-dynamic-js.js index fc0237c6225..8041b5141bd 100644 --- a/app/assets/javascripts/discourse/public/assets/scripts/discourse-test-load-dynamic-js.js +++ b/app/assets/javascripts/discourse/public/assets/scripts/discourse-test-load-dynamic-js.js @@ -3,26 +3,32 @@ const dynamicJsTemplate = document.querySelector("#dynamic-test-js"); const params = new URLSearchParams(document.location.search); const skipPlugins = params.get("qunit_skip_plugins"); -for (const element of dynamicJsTemplate.content.childNodes) { - if (skipPlugins && element.dataset?.discoursePlugin) { - continue; +(async function setup() { + for (const element of dynamicJsTemplate.content.childNodes) { + if (skipPlugins && element.dataset?.discoursePlugin) { + continue; + } + + if ( + element.tagName === "SCRIPT" && + element.innerHTML.includes("EmberENV.TESTS_FILE_LOADED") + ) { + // Inline script introduced by ember-cli. Incompatible with CSP and our custom plugin JS loading system + // https://github.com/ember-cli/ember-cli/blob/04a38fda2c/lib/utilities/ember-app-utils.js#L131 + // We re-implement in test-boot-ember-cli.js + continue; + } + + const clone = element.cloneNode(true); + + if (clone.tagName === "SCRIPT") { + clone.async = false; + } + + document.querySelector("discourse-dynamic-test-js").appendChild(clone); + + if (clone.tagName === "LINK" && clone["rel"] === "stylesheet") { + await new Promise((resolve) => (clone.onload = resolve)); + } } - - if ( - element.tagName === "SCRIPT" && - element.innerHTML.includes("EmberENV.TESTS_FILE_LOADED") - ) { - // Inline script introduced by ember-cli. Incompatible with CSP and our custom plugin JS loading system - // https://github.com/ember-cli/ember-cli/blob/04a38fda2c/lib/utilities/ember-app-utils.js#L131 - // We re-implement in test-boot-ember-cli.js - continue; - } - - const clone = element.cloneNode(true); - - if (clone.tagName === "SCRIPT") { - clone.async = false; - } - - document.querySelector("discourse-dynamic-test-js").appendChild(clone); -} +})(); diff --git a/app/assets/javascripts/discourse/testem.js b/app/assets/javascripts/discourse/testem.js index fbc39514183..1bcc31d2cda 100644 --- a/app/assets/javascripts/discourse/testem.js +++ b/app/assets/javascripts/discourse/testem.js @@ -105,5 +105,11 @@ if (process.argv.includes("-t")) { "/plugins/": { target, }, + "/bootstrap/plugin-css-for-tests.css": { + target, + }, + "/stylesheets/": { + target, + }, }; } diff --git a/app/assets/javascripts/discourse/tests/index.html b/app/assets/javascripts/discourse/tests/index.html index 3277f0b1cc6..c286633609f 100644 --- a/app/assets/javascripts/discourse/tests/index.html +++ b/app/assets/javascripts/discourse/tests/index.html @@ -52,6 +52,7 @@