@@ -222,6 +222,218 @@ module ReactOnRailsPro
222222 it { expect ( printable_cache_key ) . to eq ( "1_2_3_4_5" ) }
223223 end
224224
225+ describe ".rsc_support_enabled?" do
226+ context "when RSC support is enabled" do
227+ before do
228+ allow ( ReactOnRailsPro . configuration ) . to receive ( :enable_rsc_support ) . and_return ( true )
229+ described_class . instance_variable_set ( :@rsc_support_enabled , nil )
230+ end
231+
232+ it "returns true" do
233+ expect ( described_class . rsc_support_enabled? ) . to be ( true )
234+ end
235+ end
236+
237+ context "when RSC support is disabled" do
238+ before do
239+ allow ( ReactOnRailsPro . configuration ) . to receive ( :enable_rsc_support ) . and_return ( false )
240+ described_class . instance_variable_set ( :@rsc_support_enabled , nil )
241+ end
242+
243+ it "returns false" do
244+ expect ( described_class . rsc_support_enabled? ) . to be ( false )
245+ end
246+ end
247+ end
248+
249+ describe ".rsc_bundle_js_file_path" do
250+ before do
251+ described_class . instance_variable_set ( :@rsc_bundle_path , nil )
252+ allow ( ReactOnRailsPro . configuration ) . to receive ( :rsc_bundle_js_file ) . and_return ( "rsc-bundle.js" )
253+ end
254+
255+ after do
256+ described_class . instance_variable_set ( :@rsc_bundle_path , nil )
257+ end
258+
259+ it "calls bundle_js_file_path with the rsc_bundle_js_file name" do
260+ allow ( ReactOnRails ::Utils ) . to receive ( :bundle_js_file_path ) . with ( "rsc-bundle.js" )
261+ . and_return ( "/some/path/rsc-bundle.js" )
262+
263+ result = described_class . rsc_bundle_js_file_path
264+
265+ expect ( ReactOnRails ::Utils ) . to have_received ( :bundle_js_file_path ) . with ( "rsc-bundle.js" )
266+ expect ( result ) . to eq ( "/some/path/rsc-bundle.js" )
267+ end
268+
269+ it "caches the path when not in development" do
270+ allow ( Rails . env ) . to receive ( :development? ) . and_return ( false )
271+ allow ( ReactOnRails ::Utils ) . to receive ( :bundle_js_file_path ) . with ( "rsc-bundle.js" )
272+ . and_return ( "/some/path/rsc-bundle.js" )
273+
274+ result1 = described_class . rsc_bundle_js_file_path
275+ result2 = described_class . rsc_bundle_js_file_path
276+
277+ expect ( ReactOnRails ::Utils ) . to have_received ( :bundle_js_file_path ) . once . with ( "rsc-bundle.js" )
278+ expect ( result1 ) . to eq ( "/some/path/rsc-bundle.js" )
279+ expect ( result2 ) . to eq ( "/some/path/rsc-bundle.js" )
280+ end
281+
282+ it "does not cache the path in development" do
283+ allow ( Rails . env ) . to receive ( :development? ) . and_return ( true )
284+ allow ( ReactOnRails ::Utils ) . to receive ( :bundle_js_file_path ) . with ( "rsc-bundle.js" )
285+ . and_return ( "/some/path/rsc-bundle.js" )
286+
287+ result1 = described_class . rsc_bundle_js_file_path
288+ result2 = described_class . rsc_bundle_js_file_path
289+
290+ expect ( ReactOnRails ::Utils ) . to have_received ( :bundle_js_file_path ) . twice . with ( "rsc-bundle.js" )
291+ expect ( result1 ) . to eq ( "/some/path/rsc-bundle.js" )
292+ expect ( result2 ) . to eq ( "/some/path/rsc-bundle.js" )
293+ end
294+ end
295+
296+ describe ".react_client_manifest_file_path" do
297+ before do
298+ described_class . instance_variable_set ( :@react_client_manifest_path , nil )
299+ allow ( ReactOnRailsPro . configuration ) . to receive ( :react_client_manifest_file )
300+ . and_return ( "react-client-manifest.json" )
301+ end
302+
303+ after do
304+ described_class . instance_variable_set ( :@react_client_manifest_path , nil )
305+ end
306+
307+ context "when using packer" do
308+ let ( :public_output_path ) { "/path/to/public/webpack/dev" }
309+
310+ before do
311+ allow ( ::Shakapacker ) . to receive_message_chain ( "config.public_output_path" )
312+ . and_return ( Pathname . new ( public_output_path ) )
313+ allow ( ::Shakapacker ) . to receive_message_chain ( "config.public_path" )
314+ . and_return ( Pathname . new ( "/path/to/public" ) )
315+ end
316+
317+ context "when dev server is running" do
318+ before do
319+ allow ( ::Shakapacker ) . to receive ( :dev_server ) . and_return (
320+ instance_double (
321+ ::Shakapacker ::DevServer ,
322+ running? : true ,
323+ protocol : "http" ,
324+ host_with_port : "localhost:3035"
325+ )
326+ )
327+ end
328+
329+ it "returns manifest URL with dev server path" do
330+ expected_url = "http://localhost:3035/webpack/dev/react-client-manifest.json"
331+ expect ( described_class . react_client_manifest_file_path ) . to eq ( expected_url )
332+ end
333+ end
334+
335+ context "when dev server is not running" do
336+ before do
337+ allow ( ::Shakapacker ) . to receive_message_chain ( "dev_server.running?" )
338+ . and_return ( false )
339+ end
340+
341+ it "returns file path to the manifest" do
342+ expected_path = File . join ( public_output_path , "react-client-manifest.json" )
343+ expect ( described_class . react_client_manifest_file_path ) . to eq ( expected_path )
344+ end
345+ end
346+ end
347+
348+ it "caches the path when not in development" do
349+ allow ( Rails . env ) . to receive ( :development? ) . and_return ( false )
350+ allow ( ReactOnRails ::PackerUtils ) . to receive ( :asset_uri_from_packer )
351+ . with ( "react-client-manifest.json" )
352+ . and_return ( "/some/path/react-client-manifest.json" )
353+
354+ result1 = described_class . react_client_manifest_file_path
355+ result2 = described_class . react_client_manifest_file_path
356+
357+ expect ( ReactOnRails ::PackerUtils ) . to have_received ( :asset_uri_from_packer ) . once
358+ expect ( result1 ) . to eq ( "/some/path/react-client-manifest.json" )
359+ expect ( result2 ) . to eq ( "/some/path/react-client-manifest.json" )
360+ end
361+
362+ it "does not cache the path in development" do
363+ allow ( Rails . env ) . to receive ( :development? ) . and_return ( true )
364+ allow ( ReactOnRails ::PackerUtils ) . to receive ( :asset_uri_from_packer )
365+ . with ( "react-client-manifest.json" )
366+ . and_return ( "/some/path/react-client-manifest.json" )
367+
368+ result1 = described_class . react_client_manifest_file_path
369+ result2 = described_class . react_client_manifest_file_path
370+
371+ expect ( ReactOnRails ::PackerUtils ) . to have_received ( :asset_uri_from_packer ) . twice
372+ expect ( result1 ) . to eq ( "/some/path/react-client-manifest.json" )
373+ expect ( result2 ) . to eq ( "/some/path/react-client-manifest.json" )
374+ end
375+ end
376+
377+ describe ".react_server_client_manifest_file_path" do
378+ let ( :asset_name ) { "react-server-client-manifest.json" }
379+
380+ before do
381+ described_class . instance_variable_set ( :@react_server_manifest_path , nil )
382+ allow ( ReactOnRailsPro . configuration ) . to receive ( :react_server_client_manifest_file ) . and_return ( asset_name )
383+ allow ( Rails . env ) . to receive ( :development? ) . and_return ( false )
384+ end
385+
386+ after do
387+ described_class . instance_variable_set ( :@react_server_manifest_path , nil )
388+ end
389+
390+ it "calls bundle_js_file_path with the correct asset name and returns its value" do
391+ allow ( ReactOnRails ::Utils ) . to receive ( :bundle_js_file_path ) . with ( asset_name )
392+ . and_return ( "/some/path/#{ asset_name } " )
393+
394+ result = described_class . react_server_client_manifest_file_path
395+
396+ expect ( ReactOnRails ::Utils ) . to have_received ( :bundle_js_file_path ) . with ( asset_name )
397+ expect ( result ) . to eq ( "/some/path/#{ asset_name } " )
398+ end
399+
400+ it "caches the path when not in development" do
401+ allow ( ReactOnRails ::Utils ) . to receive ( :bundle_js_file_path ) . with ( asset_name )
402+ . and_return ( "/some/path/#{ asset_name } " )
403+
404+ result1 = described_class . react_server_client_manifest_file_path
405+ result2 = described_class . react_server_client_manifest_file_path
406+
407+ expect ( ReactOnRails ::Utils ) . to have_received ( :bundle_js_file_path ) . once . with ( asset_name )
408+ expect ( result1 ) . to eq ( "/some/path/#{ asset_name } " )
409+ expect ( result2 ) . to eq ( "/some/path/#{ asset_name } " )
410+ end
411+
412+ it "does not cache the path in development" do
413+ allow ( Rails . env ) . to receive ( :development? ) . and_return ( true )
414+ allow ( ReactOnRails ::Utils ) . to receive ( :bundle_js_file_path ) . with ( asset_name )
415+ . and_return ( "/some/path/#{ asset_name } " )
416+
417+ result1 = described_class . react_server_client_manifest_file_path
418+ result2 = described_class . react_server_client_manifest_file_path
419+
420+ expect ( ReactOnRails ::Utils ) . to have_received ( :bundle_js_file_path ) . twice . with ( asset_name )
421+ expect ( result1 ) . to eq ( "/some/path/#{ asset_name } " )
422+ expect ( result2 ) . to eq ( "/some/path/#{ asset_name } " )
423+ end
424+
425+ context "when manifest file name is nil" do
426+ before do
427+ allow ( ReactOnRailsPro . configuration ) . to receive ( :react_server_client_manifest_file ) . and_return ( nil )
428+ end
429+
430+ it "raises an error" do
431+ expect { described_class . react_server_client_manifest_file_path }
432+ . to raise_error ( ReactOnRailsPro ::Error , /react_server_client_manifest_file is nil/ )
433+ end
434+ end
435+ end
436+
225437 describe ".pro_attribution_comment" do
226438 context "when license is valid and not in grace period" do
227439 before do
0 commit comments