0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-05 15:18:34 +08:00
discourse/spec/system/ember_deprecation_spec.rb
David Taylor 9527868295
DEV: Replace JS build system with Rolldown (#35963)
This replaces the old ember-cli build with a modern Rolldown build. In
local testing, this provides an 80% improvement in build times, while
remaining 100% backwards compatible for themes and plugins.

As part of this move, we have decided to stop using a proxy in front of
Discourse for development. Development should now be done directly
against the Rails server.

`bin/ember-cli -u` has been replaced with `bin/dev`. This will launch
Rails on `:3000`, and will run the rolldown build in the background. Log
output from both processes will be shown with an appropriate prefix. You
should visit `:3000` in your browser. `:4200` will no longer serve
anything.

To help with migration, `bin/ember-cli` is now a backwards-compatible
shim. It will print help information, and will launch a lightweight
server on `:4200` with instructions to move to `:3000`.

If you prefer to launch Rails and the JS build as separate commands, you
can still do that. Rails boot commands are unchanged, and the rolldown
development builder can be run using `bin/dev --only ember`.

https://meta.discourse.org/t/403908

---------

Co-authored-by: Jarek Radosz <jarek@cvx.dev>
Co-authored-by: Chris Manson <chris@manson.ie>
2026-05-29 11:11:55 +01:00

107 lines
3.7 KiB
Ruby
Vendored

# frozen_string_literal: true
describe "JS Deprecation Handling" 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")
expect(page).to have_css("#site-logo")
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 "emits ember-this-fallback deprecation for theme .hbs connectors using property fallback",
expected_js_deprecations: %w[ember-this-fallback.this-property-fallback] do
t = Fabricate(:theme, name: "Theme With Hbs Connector")
t.set_field(
target: :extra_js,
name: "discourse/connectors/below-footer/my-connector.hbs",
value: "{{someProperty}}",
)
t.save!
SiteSetting.default_theme_id = t.id
visit "/latest"
expect(find("#main-outlet-wrapper")).to be_visible
try_until_success do
expect(
$playwright_logger.logs.any? do |log|
log[:message].include?("ember-this-fallback.this-property-fallback")
end,
).to eq(true)
end
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