2023-03-10 18:37:28 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2024-01-03 19:41:09 +08:00
|
|
|
describe "JS Deprecation Handling", type: :system do
|
|
|
|
it "can successfully print a deprecation message after applying production-mode shims" do
|
2023-03-10 18:37:28 +08:00
|
|
|
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
|
|
|
|
|
|
|
|
# Apply deprecate shims. These are applied automatically in production
|
|
|
|
# builds, but running a full production build for system specs would be
|
|
|
|
# too slow
|
|
|
|
page.execute_script <<~JS
|
|
|
|
require("discourse/lib/deprecate-shim").applyShim();
|
|
|
|
JS
|
|
|
|
|
|
|
|
# Trigger a deprecation, then return the console.warn calls
|
|
|
|
warn_calls = page.execute_script <<~JS
|
|
|
|
const { deprecate } = require('@ember/debug');
|
|
|
|
deprecate("Some message", false, { id: "some.id" })
|
|
|
|
return window.intercepted_warnings
|
|
|
|
JS
|
|
|
|
|
|
|
|
expect(warn_calls.size).to eq(1)
|
|
|
|
call, backtrace = warn_calls[0]
|
|
|
|
|
|
|
|
expect(call).to eq("DEPRECATION: Some message [deprecation id: some.id]")
|
|
|
|
expect(backtrace).to include("shimLogDeprecationToConsole")
|
|
|
|
end
|
2024-01-03 19:41:09 +08:00
|
|
|
|
|
|
|
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-common/lib/deprecated").default;
|
|
|
|
deprecated("Fake deprecation message", { id: "fake-deprecation" })
|
|
|
|
JS
|
|
|
|
|
|
|
|
message = find("#global-notice-critical-deprecation")
|
|
|
|
expect(message).to have_text(
|
|
|
|
"One of your themes or plugins needs updating for compatibility with upcoming Discourse core changes",
|
|
|
|
)
|
|
|
|
expect(message).to have_text(SiteSetting.warn_critical_js_deprecations_message)
|
|
|
|
end
|
2024-08-09 22:04:05 +08:00
|
|
|
|
|
|
|
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-common/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")
|
|
|
|
end
|
2023-03-10 18:37:28 +08:00
|
|
|
end
|