Class: ReactOnRails::TestHelper::DevAssetsDetector
- Inherits:
-
Object
- Object
- ReactOnRails::TestHelper::DevAssetsDetector
- Defined in:
- lib/react_on_rails/test_helper/dev_assets_detector.rb
Overview
Detects whether development webpack assets can be reused for tests, avoiding redundant compilation when ‘bin/dev static` is already running.
When ‘bin/dev static` runs webpack in watch mode, it writes compiled assets to the development output directory (e.g., public/packs). If those assets are fresh (newer than all source files) and not HMR artifacts, tests can reuse them instead of running a separate build_test_command.
This makes ‘bundle exec rspec` “just work” when `bin/dev static` is running, with no environment variables or extra commands needed.
Class Method Summary collapse
-
.try_activate_dev_assets! ⇒ Object
Attempts to detect and activate development assets for test use.
Instance Method Summary collapse
-
#check ⇒ Object
Checks if development assets are reusable for tests.
Class Method Details
.try_activate_dev_assets! ⇒ Object
Attempts to detect and activate development assets for test use.
When successful:
-
Overrides Shakapacker’s test config to point at dev output
-
Clears manifest cache so tests read the dev manifest
-
Returns true
When dev assets aren’t usable (HMR mode, stale, missing):
-
Returns false with no side effects
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/react_on_rails/test_helper/dev_assets_detector.rb', line 31 def try_activate_dev_assets! reset_hmr_warning_state! detector = new result = detector.check return false unless result return false unless apply_shakapacker_override!(result) (result) true rescue StandardError => e warn "React on Rails: Dev asset detection failed: #{e.}" if ENV["DEBUG"] false end |
Instance Method Details
#check ⇒ Object
Checks if development assets are reusable for tests.
Returns a hash with dev output info if reusable, nil otherwise.
100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/react_on_rails/test_helper/dev_assets_detector.rb', line 100 def check shakapacker_yml = load_shakapacker_yml return nil unless shakapacker_yml dev_output = resolve_dev_output(shakapacker_yml) return nil unless dev_output manifest_path = dev_output[:dev_full_path].join("manifest.json") return nil unless manifest_usable?(manifest_path) dev_output.merge(manifest_path: manifest_path) end |