New core features system specs in plugins and themes

AI-generated summary

loic announced the inclusion of “smoke specs” or core features specs in both the plugin and theme skeletons. These specs are designed to ensure that plugins and themes do not break the basic functionality of Discourse. The announcement provides code snippets for integrating these specs into existing projects, noting that enable_current_plugin is used for plugins and upload_theme_or_component for themes. For bulk updates across repositories, a script for the mass-pr tool is available. Additionally, developers can skip specific examples if their plugin or theme intentionally alters basic functionality, using keywords such as login, likes, profile, topics, and various search options.

gormus suggested that the list of skip keywords and the ability to skip examples should be documented directly in the skeleton files or linked within them for easier access. loic agreed with this suggestion and confirmed that the documentation has been added to both the plugin and theme skeleton repositories.

Regarding technical issues, pfaffman noted that tests may fail if a theme requires different Theme authorized extensions because the theme cannot load properly during the test suite. gormus provided a solution to this issue by setting SiteSetting.theme_authorized_extensions within the spec file before uploading the theme. pfaffman acknowledged this fix, noting it is a simple solution.

We’ve just included what we call smoke specs or core features specs in both skeletons for plugins and themes.

These specs ensure the plugin or the theme you’re working on doesn’t break the basic functionality of Discourse.

It’s easy to add these specs to an existing plugin or theme:

For a plugin

# spec/system/core_features_spec.rb

RSpec.describe "Core features", type: :system do
  before { enable_current_plugin }

  it_behaves_like "having working core features"
end

For a theme

# spec/system/core_features_spec.rb

RSpec.describe "Core features", type: :system do
  before { upload_theme_or_component }

  it_behaves_like "having working core features"
end

If you need to update many repositories at once, a script for our mass-pr tool is available.

If the plugin or the theme you’re working on changes a basic functionality of Discourse on purpose, then it’s possible to skip some of the examples from the core features specs:

it_behaves_like "having working core features", skip_examples: %i[login likes]

Here’s the complete list of keywords for skipping examples:

  • login
  • likes
  • profile
  • topics
  • topics:read
  • topics:reply
  • topics:create
  • search
  • search:quick_search
  • search:full_page

IMHO, it would be very handy and helpful to include this detail in

and

… or the link of this topic :slight_smile:

That’s a good idea, it’s been done in DEV: Add short explanations for the core features specs by Flink · Pull Request #52 · discourse/discourse-theme-skeleton · GitHub and DEV: Add short explanations for the core features specs by Flink · Pull Request #78 · discourse/discourse-plugin-skeleton · GitHub :grin:

If your theme needs to have a different Theme authorized extensions all tests fail because the theme can’t load.

I recently stumbled on this issue. Here’s how the required extensions can be set:

RSpec.describe "Core features" do
+ SiteSetting.theme_authorized_extensions = "js|css"
  before { upload_theme_or_component }

  it_behaves_like "having working core features"
end

That’s not hard. I wonder what theme I was working on or if I solved the problem! :person_shrugging: