@@ -76,8 +76,6 @@ def mock_bundle_configs(server_bundle_name: random_bundle_name, rsc_bundle_name:
7676 . and_return ( server_bundle_name )
7777 allow ( ReactOnRails ) . to receive_message_chain ( "configuration.rsc_bundle_js_file" )
7878 . and_return ( rsc_bundle_name )
79- allow ( ReactOnRails ) . to receive_message_chain ( "configuration.enforce_secure_server_bundles" )
80- . and_return ( false )
8179 allow ( ReactOnRails ) . to receive_message_chain ( "configuration.server_bundle_output_path" )
8280 . and_return ( nil )
8381 end
@@ -145,27 +143,14 @@ def mock_dev_server_running
145143 it { is_expected . to eq ( "#{ packer_public_output_path } /manifest.json" ) }
146144 end
147145
148- context "when file not in manifest and fallback to standard location " do
146+ context "when file not in manifest" do
149147 before do
150148 mock_missing_manifest_entry ( "webpack-bundle.js" )
151149 end
152150
153- let ( :standard_path ) { File . expand_path ( File . join ( "public" , "packs" , "webpack-bundle.js" ) ) }
154151 let ( :env_specific_path ) { File . join ( packer_public_output_path , "webpack-bundle.js" ) }
155152
156- it "returns standard path when bundle exists there" do
157- allow ( File ) . to receive ( :exist? ) . and_call_original
158- allow ( File ) . to receive ( :exist? ) . with ( File . expand_path ( env_specific_path ) ) . and_return ( false )
159- allow ( File ) . to receive ( :exist? ) . with ( standard_path ) . and_return ( true )
160-
161- result = described_class . bundle_js_file_path ( "webpack-bundle.js" )
162- expect ( result ) . to eq ( standard_path )
163- end
164-
165- it "returns environment-specific path when no bundle exists anywhere" do
166- allow ( File ) . to receive ( :exist? ) . and_call_original
167- allow ( File ) . to receive ( :exist? ) . and_return ( false )
168-
153+ it "returns environment-specific path" do
169154 result = described_class . bundle_js_file_path ( "webpack-bundle.js" )
170155 expect ( result ) . to eq ( File . expand_path ( env_specific_path ) )
171156 end
@@ -174,43 +159,46 @@ def mock_dev_server_running
174159 context "with server bundle (SSR/RSC) file not in manifest" do
175160 let ( :server_bundle_name ) { "server-bundle.js" }
176161 let ( :ssr_generated_path ) { File . expand_path ( File . join ( "ssr-generated" , server_bundle_name ) ) }
177- let ( :generated_server_path ) do
178- File . expand_path ( File . join ( "generated" , "server-bundles" , server_bundle_name ) )
179- end
180162
181- before do
182- mock_missing_manifest_entry ( server_bundle_name )
183- allow ( ReactOnRails ) . to receive_message_chain ( "configuration.server_bundle_js_file" )
184- . and_return ( server_bundle_name )
185- allow ( ReactOnRails ) . to receive_message_chain ( "configuration.enforce_secure_server_bundles" )
186- . and_return ( false )
187- allow ( ReactOnRails ) . to receive_message_chain ( "configuration.server_bundle_output_path" )
188- . and_return ( "ssr-generated" )
163+ context "with server_bundle_output_path configured" do
164+ before do
165+ mock_missing_manifest_entry ( server_bundle_name )
166+ allow ( ReactOnRails ) . to receive_message_chain ( "configuration.server_bundle_js_file" )
167+ . and_return ( server_bundle_name )
168+ allow ( ReactOnRails ) . to receive_message_chain ( "configuration.server_bundle_output_path" )
169+ . and_return ( "ssr-generated" )
170+ end
171+
172+ it "tries configured location first for server bundles" do
173+ allow ( File ) . to receive ( :exist? ) . and_call_original
174+ allow ( File ) . to receive ( :exist? ) . with ( ssr_generated_path ) . and_return ( true )
175+
176+ result = described_class . bundle_js_file_path ( server_bundle_name )
177+ expect ( result ) . to eq ( ssr_generated_path )
178+ end
179+
180+ it "falls back to configured path when no bundle exists" do
181+ allow ( File ) . to receive ( :exist? ) . and_call_original
182+ allow ( File ) . to receive ( :exist? ) . and_return ( false )
183+
184+ result = described_class . bundle_js_file_path ( server_bundle_name )
185+ expect ( result ) . to eq ( ssr_generated_path )
186+ end
189187 end
190188
191- it "tries secure locations first for server bundles" do
192- allow ( File ) . to receive ( :exist? ) . and_call_original
193- allow ( File ) . to receive ( :exist? ) . with ( ssr_generated_path ) . and_return ( true )
194-
195- result = described_class . bundle_js_file_path ( server_bundle_name )
196- expect ( result ) . to eq ( ssr_generated_path )
197- end
198-
199- it "tries generated/server-bundles as second secure location" do
200- allow ( File ) . to receive ( :exist? ) . and_call_original
201- allow ( File ) . to receive ( :exist? ) . with ( ssr_generated_path ) . and_return ( false )
202- allow ( File ) . to receive ( :exist? ) . with ( generated_server_path ) . and_return ( true )
203-
204- result = described_class . bundle_js_file_path ( server_bundle_name )
205- expect ( result ) . to eq ( generated_server_path )
206- end
207-
208- it "falls back to ssr-generated location when no bundle exists anywhere" do
209- allow ( File ) . to receive ( :exist? ) . and_call_original
210- allow ( File ) . to receive ( :exist? ) . and_return ( false )
211-
212- result = described_class . bundle_js_file_path ( server_bundle_name )
213- expect ( result ) . to eq ( ssr_generated_path )
189+ context "without server_bundle_output_path configured" do
190+ before do
191+ mock_missing_manifest_entry ( server_bundle_name )
192+ allow ( ReactOnRails ) . to receive_message_chain ( "configuration.server_bundle_js_file" )
193+ . and_return ( server_bundle_name )
194+ allow ( ReactOnRails ) . to receive_message_chain ( "configuration.server_bundle_output_path" )
195+ . and_return ( nil )
196+ end
197+
198+ it "uses packer public output path" do
199+ result = described_class . bundle_js_file_path ( server_bundle_name )
200+ expect ( result ) . to eq ( File . expand_path ( File . join ( packer_public_output_path , server_bundle_name ) ) )
201+ end
214202 end
215203 end
216204
@@ -222,13 +210,11 @@ def mock_dev_server_running
222210 mock_missing_manifest_entry ( rsc_bundle_name )
223211 allow ( ReactOnRails ) . to receive_message_chain ( "configuration.rsc_bundle_js_file" )
224212 . and_return ( rsc_bundle_name )
225- allow ( ReactOnRails ) . to receive_message_chain ( "configuration.enforce_secure_server_bundles" )
226- . and_return ( false )
227213 allow ( ReactOnRails ) . to receive_message_chain ( "configuration.server_bundle_output_path" )
228214 . and_return ( "ssr-generated" )
229215 end
230216
231- it "treats RSC bundles as server bundles and tries secure locations first" do
217+ it "treats RSC bundles as server bundles and tries configured location first" do
232218 allow ( File ) . to receive ( :exist? ) . and_call_original
233219 allow ( File ) . to receive ( :exist? ) . with ( ssr_generated_path ) . and_return ( true )
234220
0 commit comments