mirror of
https://github.com/discourse/discourse.git
synced 2026-08-06 13:08:40 +08:00
This PR implements stricter deprecation handling that enforces deprecation-free tests for core and preinstalled plugins, while allowing custom (non-preinstalled) plugins and themes to have deprecations without causing test failures. ### Key Changes #### CI Workflow Improvements - Split plugin system tests into separate CI targets: `core-plugins`, `official-plugins`, and `chat` - Enhance `bin/turbo_rspec` to accept comma-separated exclude patterns via `--exclude-pattern` - Simplify workflow configuration with default `shell: bash` and consolidated environment variables #### Plugin Classification & Detection - Centralize official plugins list in `config/official_plugins.json` for unified backend and frontend access - Detect preinstalled plugins by checking for absence of `.git` directory - Add `isOfficial` and `isPreinstalled` metadata flags to plugin info - Add `data-preinstalled` and `data-official` attributes to all plugin and theme script tags for runtime identification #### Deprecation Source Tracking - Track deprecation sources (core, plugin, or theme) through template map and resolver to attribute deprecations correctly - Improve `source-identifier.js` to detect admin UI plugin files in both development and production environments - Add source information to deprecation messages for better debugging #### Test Infrastructure - Modify `raise-on-deprecation` test helper to skip errors for custom (non-preinstalled) plugins and themes - Add `EMBER_RAISE_ON_DEPRECATION` environment variable to control deprecation throwing behavior in Rails tests - Automatically set `EMBER_RAISE_ON_DEPRECATION` for core and preinstalled plugin/theme specs in `rails_helper.rb` - Improve deprecation summary output for system specs with test/spec origin tracking #### Deprecation Workflow Enhancements - Add `dont-throw` handler for selective deprecation bypassing in test fixtures without raising errors - Add `dont-count` handler for preventing deprecation counting in specific scenarios (e.g., test fixtures) #### Deprecation Fixes - Fix pending deprecations across core plugins (chat, data-explorer, discourse-subscriptions, gamification, house-ads, reactions, rss-polling, styleguide) - Update import paths and remove deprecated patterns - Migrate deprecated Handlebars templates to JavaScript API ### Testing Strategy With these changes: - **Core and preinstalled plugins** must pass all tests without any deprecations - **Custom plugins and themes** can have deprecations without failing tests - Test fixtures can use `dont-throw` and `dont-count` handlers when testing deprecation behavior itself - System specs automatically configure deprecation enforcement based on test file location --------- Co-authored-by: David Taylor <david@taylorhq.com> Co-authored-by: Jarek Radosz <jradosz@gmail.com>
82 lines
2.9 KiB
Ruby
Vendored
82 lines
2.9 KiB
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
describe "JS Deprecation Handling", type: :system do
|
|
it "can successfully print a deprecation message after applying production-mode shims" do
|
|
visit("/latest")
|
|
expect(find("#main-outlet-wrapper")).to be_visible
|
|
|
|
# Intercept console.warn so we can enumerate calls later
|
|
page.execute_script <<~JS
|
|
window.intercepted_warnings = [];
|
|
console.warn = (msg) => window.intercepted_warnings.push([msg, (new Error()).stack])
|
|
JS
|
|
|
|
warn_calls = nil
|
|
page.driver.with_playwright_page do |playwright_page|
|
|
warn_calls = playwright_page.evaluate <<~JS
|
|
() => {
|
|
const { deprecate } = require('@ember/debug');
|
|
deprecate("Some message", false, { id: "fake.deprecation", for: "discourse", since: "3.4.0", until: "3.5.0" });
|
|
return window.intercepted_warnings;
|
|
}
|
|
JS
|
|
end
|
|
|
|
expect(warn_calls.size).to eq(1)
|
|
call, backtrace = warn_calls[0]
|
|
|
|
expect(call).to start_with("DEPRECATION: Some message [deprecation id: fake.deprecation]")
|
|
end
|
|
|
|
it "shows warnings to admins for critical deprecations" do
|
|
sign_in Fabricate(:admin)
|
|
|
|
SiteSetting.warn_critical_js_deprecations = true
|
|
SiteSetting.warn_critical_js_deprecations_message =
|
|
"Discourse core changes will be applied to your site on Jan 15."
|
|
|
|
visit("/latest")
|
|
|
|
page.execute_script <<~JS
|
|
const deprecated = require("discourse/lib/deprecated").default;
|
|
deprecated("Fake deprecation message", { id: "fake.deprecation1" })
|
|
deprecated("Other fake deprecation message", { id: "fake.deprecation2" })
|
|
JS
|
|
|
|
message = find("#global-notice-critical-deprecation--fake-deprecation1")
|
|
expect(message).to have_text("One of your themes or plugins contains code which needs updating")
|
|
expect(message).to have_text("fake.deprecation1")
|
|
expect(message).to have_text(SiteSetting.warn_critical_js_deprecations_message)
|
|
|
|
message = find("#global-notice-critical-deprecation--fake-deprecation2")
|
|
expect(message).to have_text("One of your themes or plugins contains code which needs updating")
|
|
expect(message).to have_text("fake.deprecation2")
|
|
expect(message).to have_text(SiteSetting.warn_critical_js_deprecations_message)
|
|
end
|
|
|
|
it "can show warnings triggered during initial render" do
|
|
sign_in Fabricate(:admin)
|
|
|
|
t = Fabricate(:theme, name: "Theme With Tests")
|
|
t.set_field(
|
|
target: :extra_js,
|
|
type: :js,
|
|
name: "discourse/connectors/below-footer/my-connector.gjs",
|
|
value: <<~JS,
|
|
import deprecated from "discourse/lib/deprecated";
|
|
function triggerDeprecation(){
|
|
deprecated("Fake deprecation message", { id: "fake.deprecation" })
|
|
}
|
|
export default <template>
|
|
{{triggerDeprecation}}
|
|
</template>
|
|
JS
|
|
)
|
|
t.save!
|
|
SiteSetting.default_theme_id = t.id
|
|
|
|
visit "/latest"
|
|
|
|
expect(page).to have_css("#global-notice-critical-deprecation--fake-deprecation")
|
|
end
|
|
end
|