lib/puppeteer/js_coverage.rb in puppeteer-ruby-0.36.0 vs lib/puppeteer/js_coverage.rb in puppeteer-ruby-0.37.0

- old
+ new

@@ -10,28 +10,40 @@ @text = text end attr_reader :url, :ranges, :text end + class ItemWithRawScriptCoverage < Item + def initialize(url:, ranges:, text:, raw_script_coverage:) + super(url: url, ranges: ranges, text: text) + @raw_script_coverage = raw_script_coverage + end + attr_reader :raw_script_coverage + end + # @param client [Puppeteer::CDPSession] def initialize(client) @client = client @enabled = false @script_urls = {} @script_sources = {} end - def start(reset_on_navigation: nil, report_anonymous_scripts: nil) + def start( + reset_on_navigation: nil, + report_anonymous_scripts: nil, + include_raw_script_coverage: nil) raise 'JSCoverage is already enabled' if @enabled @reset_on_navigation = if [true, false].include?(reset_on_navigation) reset_on_navigation else true end @report_anonymous_scripts = report_anonymous_scripts || false + @include_raw_script_coverage = include_raw_script_coverage || false @enabled = true @script_urls.clear @script_sources.clear @event_listeners = [] @event_listeners << @client.add_event_listener('Debugger.scriptParsed') do |event| @@ -41,11 +53,11 @@ on_execution_contexts_cleared end await_all( @client.async_send_message('Profiler.enable'), @client.async_send_message('Profiler.startPreciseCoverage', - callCount: false, + callCount: @include_raw_script_coverage, detailed: true, ), @client.async_send_message('Debugger.enable'), @client.async_send_message('Debugger.setSkipAllPauses', skip: true), ) @@ -105,14 +117,23 @@ func['ranges'].each do |range| flatten_ranges << range end end - coverage << Item.new( - url: url, - ranges: convert_to_disjoint_ranges(flatten_ranges), - text: text, - ) + if @include_raw_script_coverage + coverage << ItemWithRawScriptCoverage.new( + url: url, + ranges: convert_to_disjoint_ranges(flatten_ranges), + text: text, + raw_script_coverage: entry, + ) + else + coverage << Item.new( + url: url, + ranges: convert_to_disjoint_ranges(flatten_ranges), + text: text, + ) + end end coverage end end