class ReactOnRails::TestHelper::EnsureAssetsCompiled
Attributes
has_been_run[RW]
webpack_assets_compiler[R]
webpack_assets_status_checker[R]
Public Class Methods
new(webpack_assets_status_checker: nil, webpack_assets_compiler: nil)
click to toggle source
# File lib/react_on_rails/test_helper/ensure_assets_compiled.rb, line 15 def initialize(webpack_assets_status_checker: nil, webpack_assets_compiler: nil) @webpack_assets_status_checker = webpack_assets_status_checker @webpack_assets_compiler = webpack_assets_compiler end
Public Instance Methods
call()
click to toggle source
Several Scenarios:
-
No webpack watch processes for static assets and files are missing or out of date.
-
Only webpack watch process for server bundle as we’re the hot reloading setup.
-
For whatever reason, the watch processes are running, but some clean script removed the generated bundles.
# File lib/react_on_rails/test_helper/ensure_assets_compiled.rb, line 26 def call # Only check this ONCE during a test run return if self.class.has_been_run # Be sure we don't do this again. self.class.has_been_run = true ReactOnRails::Locales.compile stale_gen_files = webpack_assets_status_checker.stale_generated_webpack_files # All done if no stale files! return if stale_gen_files.empty? ReactOnRails::PacksGenerator.instance.generate_packs_if_stale if ReactOnRails.configuration.auto_load_bundle # Inform the developer that we're ensuring gen assets are ready. puts_start_compile_check_message(stale_gen_files) webpack_assets_compiler.compile_assets end
puts_start_compile_check_message(stale_files)
click to toggle source
# File lib/react_on_rails/test_helper/ensure_assets_compiled.rb, line 48 def puts_start_compile_check_message(stale_files) puts <<~MSG Detected the following stale generated files: #{stale_files.join("\n ")} React on Rails will ensure your JavaScript generated files are up to date, using your `#{ReactOnRails::Utils.prepend_cd_node_modules_directory(ReactOnRails.configuration.build_test_command)}` command. MSG end