A platform for community discussion. Free, open, simple.
DEV: Switch to using standard ember-cli test bundle (#23337)
David Taylorc7dce90f43ec
diff --git a/app/assets/javascripts/discourse/ember-cli-build.js b/app/assets/javascripts/discourse/ember-cli-build.jsindex b1082e07c27..3a21935e0c3 100644--- a/app/assets/javascripts/discourse/ember-cli-build.js+++ b/app/assets/javascripts/discourse/ember-cli-build.js@@ -110,60 +110,6 @@ module.exports = function (defaults) {},});- // 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)",- });-- const tests = concat(appTestTrees, {- inputFiles: ["**/tests/**/*-test.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,- });-- const testHelpers = concat(appTestTrees, {- inputFiles: [- "**/tests/loader-shims.js",- "**/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,- });-- if (isTest) {- return mergeTrees([- tests,- testHelpers,- discourseScss(`${discourseRoot}/app/assets/stylesheets`, "qunit.scss"),- discourseScss(- `${discourseRoot}/app/assets/stylesheets`,- "qunit-custom.scss"- ),- ]);- } else {- 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");@@ -191,6 +137,17 @@ module.exports = function (defaults) {.findAddonByName("pretty-text").treeForMarkdownItBundle();+ let testemStylesheetTree;+ if (isTest) {+ testemStylesheetTree = mergeTrees([+ discourseScss(`${discourseRoot}/app/assets/stylesheets`, "qunit.scss"),+ discourseScss(+ `${discourseRoot}/app/assets/stylesheets`,+ "qunit-custom.scss"+ ),+ ]);+ }+return app.toTree([createI18nTree(discourseRoot, vendorJs),parsePluginClientSettings(discourseRoot, vendorJs, app),@@ -214,5 +171,6 @@ module.exports = function (defaults) {}),generateScriptsTree(app),discoursePluginsTree,+ testemStylesheetTree,]);};diff --git a/app/assets/javascripts/discourse/tests/index.html b/app/assets/javascripts/discourse/tests/index.htmlindex 004e7613e16..f51840ddcf2 100644--- a/app/assets/javascripts/discourse/tests/index.html+++ b/app/assets/javascripts/discourse/tests/index.html@@ -67,8 +67,7 @@<template id="dynamic-test-js">{{content-for "test-plugin-css"}}{{content-for "test-plugin-js"}}- <script defer src="{{rootURL}}assets/test-helpers.js"></script>- <script defer src="{{rootURL}}assets/core-tests.js"></script>+ <script defer src="{{rootURL}}assets/tests.js"></script>{{content-for "test-plugin-tests-js"}}<script defer src="{{rootURL}}assets/scripts/discourse-test-trigger-ember-cli-boot.js"></script><script defer src="{{rootURL}}assets/scripts/discourse-boot.js"></script>diff --git a/app/assets/javascripts/discourse/tests/setup-tests.js b/app/assets/javascripts/discourse/tests/setup-tests.jsindex 45dd3b69e46..24968be7390 100644--- a/app/assets/javascripts/discourse/tests/setup-tests.js+++ b/app/assets/javascripts/discourse/tests/setup-tests.js@@ -359,19 +359,25 @@ export default function setupTests(config) {const target = getUrlParameter("target") || "core";+ const hasPluginJs = !!document.querySelector("script[data-discourse-plugin]");+ const hasThemeJs = !!document.querySelector("script[data-theme-id]");+const shouldLoadModule = (name) => {if (!/\-test/.test(name)) {return false;}const isPlugin = name.match(/\/plugins\//);- const isCore = !isPlugin;+ const isTheme = name.match(/\/theme-\d+\//);+ const isCore = !isPlugin && !isTheme;const pluginName = name.match(/\/plugins\/([\w-]+)\//)?.[1];const loadCore = target === "core" || target === "all";const loadAllPlugins = target === "plugins" || target === "all";- if (isCore && !loadCore) {+ if (hasThemeJs) {+ return isTheme;+ } else if (isCore && !loadCore) {return false;} else if (isPlugin && !(loadAllPlugins || pluginName === target)) {return false;@@ -389,9 +395,6 @@ export default function setupTests(config) {reportMemoryUsageAfterTests();patchFailedAssertion();- const hasPluginJs = !!document.querySelector("script[data-discourse-plugin]");- const hasThemeJs = !!document.querySelector("script[data-theme-id]");-if (!hasPluginJs && !hasThemeJs) {configureRaiseOnDeprecation();}diff --git a/app/assets/javascripts/discourse/tests/test-boot-ember-cli.js b/app/assets/javascripts/discourse/tests/test-boot-ember-cli.jsindex fd8ffc4f209..7f8fa2be407 100644--- a/app/assets/javascripts/discourse/tests/test-boot-ember-cli.js+++ b/app/assets/javascripts/discourse/tests/test-boot-ember-cli.js@@ -26,7 +26,8 @@ document.addEventListener("discourse-booted", () => {const params = new URLSearchParams(window.location.search);const target = params.get("target");- const testingCore = !target || target === "core";+ const testingTheme = !!document.querySelector("script[data-theme-id]");+ const testingCore = !testingTheme && (!target || target === "core");const disableAutoStart = params.get("qunit_disable_auto_start") === "1";Ember.ENV.LOG_STACKTRACE_ON_DEPRECATION = false;diff --git a/app/assets/javascripts/discourse/tests/test-helper.js b/app/assets/javascripts/discourse/tests/test-helper.jsnew file mode 100644index 00000000000..6f3b3b60a7a--- /dev/null+++ b/app/assets/javascripts/discourse/tests/test-helper.js@@ -0,0 +1 @@+// We don't currently use this file, but it is require'd by ember-cli's test bundlediff --git a/app/helpers/qunit_helper.rb b/app/helpers/qunit_helper.rbindex 2813ed1e9d6..c2eca924bb4 100644--- a/app/helpers/qunit_helper.rb+++ b/app/helpers/qunit_helper.rb@@ -11,6 +11,6 @@ module QunitHelper"#{Discourse.base_path}" \"/theme-javascripts/tests/#{theme.id}-#{digest}.js" \"?__ws=#{Discourse.current_hostname}"- "<script defer src='#{src}'></script>".html_safe+ "<script defer src='#{src}' data-theme-id='#{theme.id}'></script>".html_safeendenddiff --git a/app/views/qunit/theme.html.erb b/app/views/qunit/theme.html.erbindex 99560c118c4..be2e930c7bc 100644--- a/app/views/qunit/theme.html.erb+++ b/app/views/qunit/theme.html.erb@@ -14,7 +14,7 @@<%= preload_script file %><%- end %><%= preload_script "test-support" %>- <%= preload_script "test-helpers" %>+ <%= preload_script "tests" %><%= preload_script "test-site-settings" %><%= theme_translations_lookup %><%= theme_js_lookup %>diff --git a/spec/requests/qunit_controller_spec.rb b/spec/requests/qunit_controller_spec.rbindex a77ee41d054..c9ad03ffc29 100644--- a/spec/requests/qunit_controller_spec.rb+++ b/spec/requests/qunit_controller_spec.rb@@ -96,9 +96,9 @@ RSpec.describe QunitController doexpect(response.body).to include("/stylesheets/desktop_")expect(response.body).to include("* https://qunitjs.com/") # inlined QUnit CSSexpect(response.body).to include("/assets/locales/en.js")- expect(response.body).to include("/test-support")- expect(response.body).to include("/test-helpers")- expect(response.body).to include("/test-site-settings")+ expect(response.body).to include("/test-support.js")+ expect(response.body).to include("/tests.js")+ expect(response.body).to include("/test-site-settings.js")expect(response.body).to include("/assets/markdown-it-bundle.js")expect(response.body).to include("/assets/discourse.js")expect(response.body).to include("/assets/admin.js")