0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-05 16:23:34 +08:00
discourse/spec/system/script_encoding_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

90 lines
2.7 KiB
Ruby
Vendored

# frozen_string_literal: true
describe "script encoding" do
let(:js_cdn_requests) { [] }
before { stub_and_log_cdn_requests }
def stub_and_log_cdn_requests
page.driver.with_playwright_page do |page|
page.route(
"http://cdn.example.com/**/*",
->(route, request) do
js_cdn_requests << request.url if request.url.end_with?(".js")
origin_uri = URI(request.frame.url)
request_uri = URI(request.url)
# We don't actually have assets/br/ files or a CDN, so invisibly
# rewrite the request to the regular assets
mocked_result =
URI::HTTP.build(
scheme: origin_uri.scheme,
host: origin_uri.host,
port: origin_uri.port,
path: request_uri.path.sub("assets/br", "assets/js"),
)
response = route.fetch(url: mocked_result.to_s)
route.fulfill(
response:,
headers: response.headers.merge({ "access-control-allow-origin" => "*" }),
)
end,
)
end
end
context "without s3 assets" do
before { set_cdn_url "http://cdn.example.com" }
it "loads JS chunks with the .js extension" do
user = Fabricate(:admin)
sign_in user
visit "/latest"
expect(js_cdn_requests.length).to be > 1
expect(js_cdn_requests.any? { |r| r.match?(%r{/br/.+\.js\Z}) }).to eq(false)
js_cdn_requests.clear
# Use the composer to trigger an async chunk load
find("#create-topic").click
find(".d-editor-input").fill_in(with: "This is a test")
expect(page).to have_css(".d-editor-preview", text: "This is a test")
expect(js_cdn_requests.length).to be > 1
expect(js_cdn_requests.any? { |r| r.match?(%r{/br/.+\.js\Z}) }).to eq(false)
end
end
context "with s3 assets" do
before do
global_setting :s3_bucket, "test_bucket"
global_setting :s3_region, "ap-australia"
global_setting :s3_access_key_id, "123"
global_setting :s3_secret_access_key, "123"
global_setting :s3_cdn_url, "http://cdn.example.com"
end
it "loads JS chunks with the /br/ path" do
user = Fabricate(:admin)
sign_in user
visit "/latest"
expect(js_cdn_requests.length).to be > 1
expect(js_cdn_requests.all? { |r| r.match?(%r{/br/.+\.js\Z}) }).to eq(true)
js_cdn_requests.clear
# Use the composer to trigger an async chunk load
find("#create-topic").click
find(".d-editor-input").fill_in(with: "This is a test")
expect(page).to have_css(".d-editor-preview", text: "This is a test")
expect(js_cdn_requests.length).to be > 1
expect(js_cdn_requests.all? { |r| r.match?(%r{/br/.+\.js\Z}) }).to eq(true)
end
end
end