Sha256: 40052a65c167d95de0f1ae2c7d2d53f48fc86af86aabf8607f483cf7db0fa863

Contents?: true

Size: 1.57 KB

Versions: 10

Compression:

Stored size: 1.57 KB

Contents

# You can replace this implementation with your own for use by the
# ReactOnRails::TestHelper.ensure_assets_compiled helper
module ReactOnRails
  module TestHelper
    class WebpackProcessChecker
      def initialize
        @printed_once = {}
      end

      def running?
        client_running = check_running_for_type("client")
        return client_running unless Utils.server_rendering_is_enabled?

        server_running = check_running_for_type("server")
        fail_if_only_running_for_one_type(client_running, server_running)

        client_running && server_running
      end

      private

      # We only want to do this if server rendering is enabled.
      def fail_if_only_running_for_one_type(client_running, server_running)
        return unless client_running ^ server_running
        fail "\n\nError: detected webpack is not running for both types of assets:\n"\
         "***Webpack Client Process Running?: #{client_running}\n"\
         "***Webpack Server Process Running?: #{server_running}"
      end

      def check_running_for_type(type)
        type = type.to_sym

        response = `pgrep -fl 'bin/webpack\s(\\-w|\\-\\-watch)\s\\-\\-config\s.*#{type}.*\\.js'`
        is_running = Utils.last_process_completed_successfully?

        if is_running
          if @printed_once.empty?
            puts "\nDetected Webpack processes running to rebuild your generated files:"
          end
          unless @printed_once[type]
            puts "#{type}:  #{response}"
            @printed_once[type] = true
          end
        end

        is_running
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
react_on_rails-3.0.6 lib/react_on_rails/test_helper/webpack_process_checker.rb
react_on_rails-3.0.5 lib/react_on_rails/test_helper/webpack_process_checker.rb
react_on_rails-3.0.4 lib/react_on_rails/test_helper/webpack_process_checker.rb
react_on_rails-3.0.3 lib/react_on_rails/test_helper/webpack_process_checker.rb
react_on_rails-3.0.2 lib/react_on_rails/test_helper/webpack_process_checker.rb
react_on_rails-3.0.1 lib/react_on_rails/test_helper/webpack_process_checker.rb
react_on_rails-3.0.0 lib/react_on_rails/test_helper/webpack_process_checker.rb
react_on_rails-3.0.0.rc.2 lib/react_on_rails/test_helper/webpack_process_checker.rb
react_on_rails-3.0.0.rc.1 lib/react_on_rails/test_helper/webpack_process_checker.rb
react_on_rails-3.0.0.beta.1 lib/react_on_rails/test_helper/webpack_process_checker.rb