discourse/spec/system/ember_deprecation_test.rb
Alan Guo Xiang Tan 41f8bff2c3
DEV: Remove superfluous js: true metadata (#21960)
Why this change?

It is very unlikely that we need to ever JS for system tests considering
that we rely on a JS framework on the frontend.
2023-06-07 09:26:58 +08:00

35 lines
1.2 KiB
Ruby

# frozen_string_literal: true
describe "Production mode debug shims", type: :system 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