Class: Jscov::Collector
- Inherits:
-
Object
- Object
- Jscov::Collector
- Defined in:
- lib/jscov/collector.rb
Instance Method Summary collapse
- #browser_logs ⇒ Object
- #coverages ⇒ Object
- #dump_coverage ⇒ Object
-
#initialize(session, logs) ⇒ Collector
constructor
A new instance of Collector.
- #parse(message) ⇒ Object
- #supported_driver? ⇒ Boolean
Constructor Details
#initialize(session, logs) ⇒ Collector
Returns a new instance of Collector.
6 7 8 9 |
# File 'lib/jscov/collector.rb', line 6 def initialize(session, logs) @session = session || Capybara.current_session @logs = logs end |
Instance Method Details
#browser_logs ⇒ Object
34 35 36 37 |
# File 'lib/jscov/collector.rb', line 34 def browser_logs logs = @session.driver.browser.logs.get(:browser) (@logs || []) + logs end |
#coverages ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/jscov/collector.rb', line 11 def coverages return [] unless supported_driver? dump_coverage browser_logs .map { |log| parse(log.) } .compact .map { |cov| Coverage.new(cov) } end |
#dump_coverage ⇒ Object
27 28 29 30 31 32 |
# File 'lib/jscov/collector.rb', line 27 def dump_coverage code = <<~JS typeof __jscov_dumpCoverage === 'function' && __jscov_dumpCoverage() JS @session.execute_script(code) end |
#parse(message) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/jscov/collector.rb', line 39 def parse() json_string = [/__jscov" (.*)/, 1] return if json_string.nil? json = JSON.parse(json_string) JSON.parse(json) rescue JSON::ParserError nil end |
#supported_driver? ⇒ Boolean
22 23 24 25 |
# File 'lib/jscov/collector.rb', line 22 def supported_driver? @session.driver.is_a?(Capybara::Selenium::Driver) && @session.driver.browser.respond_to?(:logs) end |