<commit_before>require "capybara"

module Konacha
  class Runner
    def self.start
      new.run
    end

    attr_reader :reporter

    def initialize
      @reporter = Konacha::Reporter.new(*formatters)
    end

    def run
      reporter.start

      begin
        session.visit('/')

        events_consumed = 0
        done = false
        begin
          sleep 0.1
          events = JSON.parse(session.evaluate_script('Konacha.getEvents()'))
          if events
            events[events_consumed..-1].each do |event|
              done = true if event['event'] == 'end'
              reporter.process_mocha_event(event)
            end

            events_consumed = events.length
          end
        end until done
      rescue => e
        raise e, "Error communicating with browser process: #{e}", e.backtrace
      end

      reporter.finish
      reporter.passed?
    end

    def session
      @session ||= Capybara::Session.new(Konacha.driver, Konacha.application)
    end

    private
    def formatters
      if ENV['FORMAT']
        ENV['FORMAT'].split(',').map do |string|
          string.match(/^(.*?[^:]+):?([^:]+)?$/)
          klass, path = $1, $2
          eval(klass).new(path ? File.open(path, 'w') : STDOUT)
        end
      else
        [Konacha::Formatter.new(STDOUT)]
      end
    end
  end
end
<commit_msg>Remove support for per-formatter output direction<commit_after>require "capybara"

module Konacha
  class Runner
    def self.start
      new.run
    end

    attr_reader :reporter

    def initialize
      @reporter = Konacha::Reporter.new(*formatters)
    end

    def run
      reporter.start

      begin
        session.visit('/')

        events_consumed = 0
        done = false
        begin
          sleep 0.1
          events = JSON.parse(session.evaluate_script('Konacha.getEvents()'))
          if events
            events[events_consumed..-1].each do |event|
              done = true if event['event'] == 'end'
              reporter.process_mocha_event(event)
            end

            events_consumed = events.length
          end
        end until done
      rescue => e
        raise e, "Error communicating with browser process: #{e}", e.backtrace
      end

      reporter.finish
      reporter.passed?
    end

    def session
      @session ||= Capybara::Session.new(Konacha.driver, Konacha.application)
    end

    private
    def formatters
      if ENV['FORMAT']
        ENV['FORMAT'].split(',').map do |string|
          eval(string).new(STDOUT)
        end
      else
        [Konacha::Formatter.new(STDOUT)]
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.10371220818982013, 'fraction_numerical': 0.003827018752391887, 'mean_word_length': 1.825945945945946, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5682154', 'n_tokens_mistral': 801, 'n_tokens_neox': 762, 'n_words': 185}