From c7dce90f43ec15f93b95e719d3fafca50e40edb1 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Mon, 4 Sep 2023 17:09:55 +0100 Subject: [PATCH] DEV: Switch to using standard ember-cli test bundle (#23337) Previously we were patching ember-cli so that it would split the test bundle into two halves: the helpers, and the tests themselves. This was done so that we could use the helpers for `/theme-qunit` without needing to load all the core tests. This patch has proven problematic to maintain, and will become even harder under Embroider. This commit removes the patch, so that ember-cli goes back to generating a single `tests.js` bundle. This means that core test definitions will now be included in the bundle when using `/theme-qunit`, and so this commit also updates our test module filter to exclude them from the run. This is the same way that we handle plugin tests on the regular `/tests` route, and is fully supported by qunit. For now, this keeps `/theme-qunit` working in both development and production environments. However, we are very likely to drop support in production as part of the move to Embroider. --- .../javascripts/discourse/ember-cli-build.js | 66 ++++--------------- .../javascripts/discourse/tests/index.html | 3 +- .../discourse/tests/setup-tests.js | 13 ++-- .../discourse/tests/test-boot-ember-cli.js | 3 +- .../discourse/tests/test-helper.js | 1 + app/helpers/qunit_helper.rb | 2 +- app/views/qunit/theme.html.erb | 2 +- spec/requests/qunit_controller_spec.rb | 6 +- 8 files changed, 29 insertions(+), 67 deletions(-) create mode 100644 app/assets/javascripts/discourse/tests/test-helper.js diff --git a/app/assets/javascripts/discourse/ember-cli-build.js b/app/assets/javascripts/discourse/ember-cli-build.js index 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.html index 004e7613e16..f51840ddcf2 100644 --- a/app/assets/javascripts/discourse/tests/index.html +++ b/app/assets/javascripts/discourse/tests/index.html @@ -67,8 +67,7 @@