Skip to content

DEV: Only load specific plugin bundles during qunit test #33678

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 21, 2025

Conversation

davidtaylorhq
Copy link
Member

@davidtaylorhq davidtaylorhq commented Jul 17, 2025

Previously, running qunit tests for a plugin would load the JS of all installed plugins. This can be problematic because, depending on the plugins installed in the current environment, there can be unexpected interactions between the plugins.

This commit updates our qunit system to check the tests.requiredPlugins list from the theme/plugin about.json file, and only loads the listed plugins. This means that the environment is much more consistent across CI and different development environments.

Alongside that change, this commit also:

  • Starts storing the original about.json for themes in the database

  • Improves qunit error handling when the test environment fails to boot (e.g. there's a bad import in a plugin)

  • Restores plugin CSS in theme qunit tests

@@ -60,7 +60,7 @@ document.addEventListener("discourse-init", () => {
}

const isPlugin = name.match(/\/plugins\//);
const isTheme = name.match(/\/theme-\d+\//);
const isTheme = name.match(/\/theme--?\d+\//);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to account for the new system themes, which have negative IDs

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is already on main btw

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah nice! Will rebase to be 100% sure there aren't any conflicts with those changes

Copy link
Contributor

@CvX CvX left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stuff! 🔥

@@ -60,7 +60,7 @@ document.addEventListener("discourse-init", () => {
}

const isPlugin = name.match(/\/plugins\//);
const isTheme = name.match(/\/theme-\d+\//);
const isTheme = name.match(/\/theme--?\d+\//);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is already on main btw

@@ -213,6 +215,16 @@ export default function setupTests(config) {
QUnit.config.hidepassed = true;
QUnit.config.testTimeout = 60_000;

window.onunhandledrejection = (event) => {
// reports test boot failures to testem, so the browser doesn't hang forever
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, we didn't have that before? 👀

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this explains why we sometimes get those CI jobs which hang forever instead of failing cleanly. (e.g. if there's an import of a non-existent module)

@@ -1,6 +1,9 @@
# frozen_string_literal: true

class QunitController < ApplicationController
# Same list maintained in discourse-test-load-dynamic-js.js
ALWAYS_LOADED_PLUGINS = %w[discourse-local-dates]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so in the end only d-local-dates is widely needed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, and it's the only core plugin with no 'enabled_setting'

@davidtaylorhq davidtaylorhq merged commit 5ba2891 into main Jul 21, 2025
16 checks passed
@davidtaylorhq davidtaylorhq deleted the isolated-qunit branch July 21, 2025 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chat PRs which include a change to Chat plugin
Development

Successfully merging this pull request may close these issues.

2 participants