@@ -461,18 +461,15 @@ def run_add_agent_files(options = {})
461461 end
462462 end
463463
464- it "creates the shakapacker watch wrapper and uses it in Procfiles" do
465- assert_file "bin/shakapacker-watch" do |content |
466- expect ( content ) . to include ( 'bin/shakapacker "$@" &' )
467- expect ( content ) . to include ( "trap cleanup INT TERM" )
468- end
464+ it "uses the standard Shakapacker command when the optional watch binstub is absent" do
465+ assert_no_file "bin/shakapacker-watch"
469466
470467 assert_file "Procfile.dev" do |content |
471- expect ( content ) . to include ( "server-bundle: SERVER_BUNDLE_ONLY=true bin/shakapacker-watch --watch" )
468+ expect ( content ) . to include ( "server-bundle: SERVER_BUNDLE_ONLY=true bin/shakapacker --watch" )
472469 end
473470
474471 assert_file "Procfile.dev-static-assets" do |content |
475- expect ( content ) . to include ( "js: bin/shakapacker-watch --watch" )
472+ expect ( content ) . to include ( "js: bin/shakapacker --watch" )
476473 end
477474 end
478475
@@ -513,6 +510,38 @@ def run_add_agent_files(options = {})
513510 end
514511 end
515512
513+ context "when the Shakapacker watch binstub is already installed" do
514+ shakapacker_watch = <<~RUBY
515+ #!/usr/bin/env ruby
516+ puts "Shakapacker-owned watcher"
517+ RUBY
518+
519+ before ( :all ) do
520+ run_generator_test_with_args ( %w[ ] , package_json : true ) do
521+ simulate_preinstalled_shakapacker ( source_path : "app/javascript" , source_entry_path : "packs" )
522+ simulate_existing_file ( "bin/shakapacker-watch" , shakapacker_watch )
523+ File . chmod ( 0o640 , File . join ( destination_root , "bin/shakapacker-watch" ) )
524+ end
525+ end
526+
527+ it "preserves Shakapacker's binstub under --force" do
528+ assert_file "bin/shakapacker-watch" do |content |
529+ expect ( content ) . to eq ( shakapacker_watch )
530+ end
531+ expect ( File . stat ( File . join ( destination_root , "bin/shakapacker-watch" ) ) . mode & 0o777 ) . to eq ( 0o640 )
532+ end
533+
534+ it "uses Shakapacker's binstub in generated Procfiles" do
535+ assert_file "Procfile.dev" do |content |
536+ expect ( content ) . to include ( "server-bundle: SERVER_BUNDLE_ONLY=true bin/shakapacker-watch --watch" )
537+ end
538+
539+ assert_file "Procfile.dev-static-assets" do |content |
540+ expect ( content ) . to include ( "js: bin/shakapacker-watch --watch" )
541+ end
542+ end
543+ end
544+
516545 context "with a pre-installed custom Shakapacker source root" do
517546 before ( :all ) do
518547 run_generator_test_with_args ( %w[ ] , package_json : true , force : false ) do
@@ -3580,7 +3609,7 @@ class ActiveSupport::TestCase
35803609 assert_file "Procfile.dev" do |content |
35813610 expect ( content ) . to include ( "RSC_BUNDLE_ONLY=true" )
35823611 expect ( content ) . to include ( "rsc-bundle:" )
3583- expect ( content ) . to include ( "bin/shakapacker-watch --watch" )
3612+ expect ( content ) . to include ( "bin/shakapacker --watch" )
35843613 end
35853614 end
35863615
@@ -4760,12 +4789,7 @@ class ActiveSupport::TestCase
47604789
47614790 it "does not chmod copied bin scripts in pretend mode" do
47624791 allow ( install_generator ) . to receive ( :directory )
4763- allow ( install_generator ) . to receive ( :copy_file ) . and_call_original
47644792 allow ( install_generator ) . to receive ( :use_rsc? ) . and_return ( false )
4765- shakapacker_watch_template = File . expand_path (
4766- "../../../lib/generators/react_on_rails/templates/base/base/bin/shakapacker-watch" ,
4767- __dir__
4768- )
47694793
47704794 expect ( install_generator ) . to receive ( :say_status )
47714795 . with ( :gsub , "bin/dev" , true )
@@ -4776,9 +4800,6 @@ class ActiveSupport::TestCase
47764800 expect ( File ) . not_to receive ( :chmod )
47774801
47784802 install_generator . send ( :add_bin_scripts )
4779-
4780- expect ( install_generator ) . to have_received ( :copy_file )
4781- . with ( shakapacker_watch_template , "bin/shakapacker-watch" )
47824803 end
47834804
47844805 it "does not install typescript dependencies in pretend mode" do
@@ -6327,39 +6348,6 @@ class ActiveSupport::TestCase
63276348 expect ( File . stat ( shakapacker_watch_path ) . mode & 0o777 ) . to eq ( 0o640 )
63286349 end
63296350
6330- it "preserves an existing Shakapacker watch binstub when run with --force" do
6331- shakapacker_watch = <<~RUBY
6332- #!/usr/bin/env ruby
6333- puts "Customized watcher"
6334- RUBY
6335- shakapacker_watch_path = File . join ( destination_root , "bin/shakapacker-watch" )
6336- force_generator = described_class . new ( [ ] , { force : true } , destination_root :)
6337- simulate_existing_file ( "bin/shakapacker-watch" , shakapacker_watch )
6338- File . chmod ( 0o640 , shakapacker_watch_path )
6339-
6340- Dir . chdir ( destination_root ) do
6341- force_generator . send ( :add_bin_scripts )
6342- end
6343-
6344- expect ( File . read ( shakapacker_watch_path ) ) . to eq ( shakapacker_watch )
6345- expect ( File . stat ( shakapacker_watch_path ) . mode & 0o777 ) . to eq ( 0o640 )
6346- end
6347-
6348- it "installs the React on Rails Shakapacker watch fallback when the binstub is absent" do
6349- template_path = File . expand_path (
6350- "../../../lib/generators/react_on_rails/templates/base/base/bin/shakapacker-watch" ,
6351- __dir__
6352- )
6353- shakapacker_watch_path = File . join ( destination_root , "bin/shakapacker-watch" )
6354-
6355- Dir . chdir ( destination_root ) do
6356- install_generator . send ( :add_bin_scripts )
6357- end
6358-
6359- expect ( File . read ( shakapacker_watch_path ) ) . to eq ( File . read ( template_path ) )
6360- expect ( File . stat ( shakapacker_watch_path ) . mode & 0o777 ) . to eq ( 0o755 )
6361- end
6362-
63636351 it "detects custom bin/dev files" do
63646352 simulate_existing_file ( "bin/dev" , "#!/usr/bin/env ruby\n puts 'custom'\n " )
63656353
0 commit comments