File tree Expand file tree Collapse file tree 4 files changed +84
-2
lines changed
lib/generators/react_on_rails Expand file tree Collapse file tree 4 files changed +84
-2
lines changed Original file line number Diff line number Diff line change @@ -45,8 +45,8 @@ def copy_base_files
4545 template ( "#{ base_path } /#{ file } .tt" , file )
4646 end
4747
48- # Make the hook script executable
49- File . chmod ( 0o755 , "bin/shakapacker-precompile-hook" ) if File . exist? ( "bin/shakapacker-precompile-hook" )
48+ # Make the hook script executable (copy_file guarantees it exists)
49+ File . chmod ( 0o755 , File . join ( destination_root , "bin/shakapacker-precompile-hook" ) )
5050 end
5151
5252 def copy_js_bundle_files
Original file line number Diff line number Diff line change 77# for auto-bundled components. It's called automatically by Shakapacker
88# when configured in config/shakapacker.yml:
99# precompile_hook: 'bin/shakapacker-precompile-hook'
10+ #
11+ # Emoji Scheme:
12+ # 🔄 = Running/in-progress
13+ # ✅ = Success
14+ # ❌ = Error
15+
16+ # Skip validation during precompile hook execution
17+ # The hook runs early in the build process, potentially before full Rails initialization,
18+ # and doesn't need package version validation since it's part of the build itself
19+ ENV [ "REACT_ON_RAILS_SKIP_VALIDATION" ] = "true"
1020
1121require_relative "../config/environment"
1222
Original file line number Diff line number Diff line change 55
66RSpec . describe ReactOnRails ::Dev ::PackGenerator do
77 describe ".generate" do
8+ context "when shakapacker precompile hook is configured" do
9+ before do
10+ allow ( ReactOnRails ::PackerUtils ) . to receive ( :shakapacker_precompile_hook_configured? ) . and_return ( true )
11+ end
12+
13+ it "skips pack generation in verbose mode" do
14+ expect { described_class . generate ( verbose : true ) }
15+ . to output ( /⏭️ Skipping pack generation/ ) . to_stdout_from_any_process
16+ end
17+
18+ it "skips pack generation silently in quiet mode" do
19+ expect { described_class . generate ( verbose : false ) }
20+ . not_to output . to_stdout_from_any_process
21+ end
22+
23+ it "does not invoke the rake task" do
24+ # Mock the task to ensure it's not called
25+ mock_task = instance_double ( Rake ::Task )
26+ allow ( Rake ::Task ) . to receive ( :[] ) . with ( "react_on_rails:generate_packs" ) . and_return ( mock_task )
27+ allow ( mock_task ) . to receive ( :invoke )
28+
29+ described_class . generate ( verbose : false )
30+
31+ expect ( mock_task ) . not_to have_received ( :invoke )
32+ end
33+ end
34+
835 context "when in Bundler context with Rails available" do
936 let ( :mock_task ) { instance_double ( Rake ::Task ) }
1037 let ( :mock_rails_app ) do
1744 end
1845
1946 before do
47+ # Ensure precompile hook is not configured for these tests
48+ allow ( ReactOnRails ::PackerUtils ) . to receive ( :shakapacker_precompile_hook_configured? ) . and_return ( false )
49+
2050 # Setup Bundler context
2151 stub_const ( "Bundler" , Module . new )
2252 allow ( ENV ) . to receive ( :[] ) . and_call_original
Original file line number Diff line number Diff line change @@ -139,6 +139,48 @@ module ReactOnRails
139139 expect ( described_class . supports_autobundling? ) . to be ( false )
140140 end
141141 end
142+
143+ describe ".shakapacker_precompile_hook_configured?" do
144+ let ( :mock_config ) { instance_double ( "::Shakapacker::Config" ) } # rubocop:disable RSpec/VerifiedDoubleReference
145+
146+ before do
147+ allow ( ::Shakapacker ) . to receive ( :config ) . and_return ( mock_config )
148+ end
149+
150+ context "when precompile_hook is configured" do
151+ it "returns true" do
152+ allow ( mock_config ) . to receive ( :send ) . with ( :data ) . and_return ( { precompile_hook : "bin/hook" } )
153+ expect ( described_class . shakapacker_precompile_hook_configured? ) . to be true
154+ end
155+ end
156+
157+ context "when precompile_hook is not configured" do
158+ it "returns false for nil" do
159+ allow ( mock_config ) . to receive ( :send ) . with ( :data ) . and_return ( { precompile_hook : nil } )
160+ expect ( described_class . shakapacker_precompile_hook_configured? ) . to be false
161+ end
162+
163+ it "returns false for empty string" do
164+ allow ( mock_config ) . to receive ( :send ) . with ( :data ) . and_return ( { precompile_hook : "" } )
165+ expect ( described_class . shakapacker_precompile_hook_configured? ) . to be false
166+ end
167+ end
168+
169+ context "when Shakapacker is not available" do
170+ before { hide_const ( "::Shakapacker" ) }
171+
172+ it "returns false" do
173+ expect ( described_class . shakapacker_precompile_hook_configured? ) . to be false
174+ end
175+ end
176+
177+ context "when config.send raises an error" do
178+ it "returns false" do
179+ allow ( mock_config ) . to receive ( :send ) . and_raise ( NoMethodError )
180+ expect ( described_class . shakapacker_precompile_hook_configured? ) . to be false
181+ end
182+ end
183+ end
142184 end
143185
144186 describe "version constants validation" do
You can’t perform that action at this time.
0 commit comments