mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 16:46:12 +08:00
b59f1ad4ee
Our Ember build compiles assets into multiple chunks. In the past, we used the output from ember-auto-import-chunks-json-generator to give Rails a map of those chunks. However, that addon is specific to ember-auto-import, and is not compatible with Embroider. Instead, we can switch to parsing the html files which are output by ember-cli. These are guaranteed to have the correct JS files in the correct place. A <discourse-chunked-script> will allow us to easily identify which chunks belong to which entrypoint. In future, as we update more entrypoints to be compiled by Embroider/Webpack, we can easily introduce new wrappers. Previously applied in2c58d45
and reverted in24d46fd
. This version has been updated for subfolder support.
45 lines
1.2 KiB
Ruby
45 lines
1.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
describe EmberCli do
|
|
describe ".ember_version" do
|
|
it "works" do
|
|
expect(EmberCli.ember_version).to match(/\A\d+\.\d+/)
|
|
end
|
|
end
|
|
|
|
describe ".parse_chunks_from_html" do
|
|
def generate_html
|
|
<<~HTML
|
|
<html>
|
|
<head>
|
|
<discourse-chunked-script entrypoint="discourse">
|
|
<script src="#{Discourse.base_path}/assets/firstchunk.js"></script>
|
|
<script src="#{Discourse.base_path}/assets/secondchunk.js"></script>
|
|
</discourse-chunked-script>
|
|
</head>
|
|
<body>
|
|
Hello world
|
|
</body>
|
|
</html>
|
|
HTML
|
|
end
|
|
|
|
it "can parse chunks for a normal site" do
|
|
chunks = EmberCli.parse_chunks_from_html generate_html
|
|
expect(chunks["discourse"]).to eq(%w[firstchunk secondchunk])
|
|
end
|
|
|
|
it "can parse chunks for a subfolder site" do
|
|
set_subfolder "/discuss"
|
|
|
|
html = generate_html
|
|
|
|
# sanity check that our fixture is working
|
|
expect(html).to include("/discuss/assets/firstchunk.js")
|
|
|
|
chunks = EmberCli.parse_chunks_from_html html
|
|
expect(chunks["discourse"]).to eq(%w[firstchunk secondchunk])
|
|
end
|
|
end
|
|
end
|