mirror of
https://github.com/discourse/discourse.git
synced 2024-11-30 20:04:16 +08:00
270e98e45f
By default, Ember uses a babel transformation to strip out calls to `deprecate()` in production builds. Given that Discourse is a development platform for third-party themes/plugins, having deprecation messages visible in production is essential - many themes/plugins do not have comprehensive test-suites, and rely on production feedback to prompt changes. This commit patches Ember to print its deprecation messages to the console in production. In future we intend to improve the visibility of these to hosting providers and/or site admins. There are two main parts to this commit: 1. Use yarn's 'resolutions' feature to point `babel-plugin-debug-macros` to a discourse-owned fork. This fork prevents `deprecate()` calls from being stripped. Relevant change can be found at https://github.com/discourse/babel-plugin-debug-macros/commit/d179d613bf 2. Introduce a production shim for Ember's deprecation library, including the `registerDeprecationHandler` API. The default implementation is stripped out of production builds via an `if(DEBUG)` wrapper. Long term we hope that this kind of functionality can be made available in Ember itself via a flag.
35 lines
1.2 KiB
Ruby
35 lines
1.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
describe "Production mode debug shims", type: :system, js: true do
|
|
it "can successfully print a deprecation message after applying prod 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
|
|
|
|
# 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
|
|
end
|