From 0372349142ce8ae173775c488c15ce766b7c5e07 Mon Sep 17 00:00:00 2001 From: Dan Mayer Date: Mon, 2 Dec 2019 21:25:12 -0700 Subject: [PATCH] fix issue #356 by having debug data and coverage data one is raw redis data for debugging, the other is enriched like the HTML report including filtering and #nocov comments --- lib/coverband/reporters/html_report.rb | 10 ++++++++++ lib/coverband/reporters/web.rb | 10 ++++++++++ lib/coverband/utils/html_formatter.rb | 8 ++++++++ views/data.erb | 1 + views/nav.erb | 3 ++- 5 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 views/data.erb diff --git a/lib/coverband/reporters/html_report.rb b/lib/coverband/reporters/html_report.rb index 11dc5c66..7000ff2f 100644 --- a/lib/coverband/reporters/html_report.rb +++ b/lib/coverband/reporters/html_report.rb @@ -32,6 +32,10 @@ def report end end + def report_data + report_dynamic_data + end + private def static? @@ -54,6 +58,12 @@ def report_dynamic_html base_path: base_path, notice: notice).format_dynamic_html! end + + def report_dynamic_data + Coverband::Utils::HTMLFormatter.new(filtered_report_files, + base_path: base_path, + notice: notice).format_dynamic_data! + end end end end diff --git a/lib/coverband/reporters/web.rb b/lib/coverband/reporters/web.rb index 1c7666d4..656f85b5 100644 --- a/lib/coverband/reporters/web.rb +++ b/lib/coverband/reporters/web.rb @@ -55,6 +55,8 @@ def call(env) [200, { 'Content-Type' => 'text/json' }, [view_tracker_data]] when %r{\/view_tracker} [200, { 'Content-Type' => 'text/html' }, [view_tracker]] + when %r{\/enriched_debug_data} + [200, { 'Content-Type' => 'text/json' }, [enriched_debug_data]] when %r{\/debug_data} [200, { 'Content-Type' => 'text/json' }, [debug_data]] when %r{\/load_file_details} @@ -97,6 +99,14 @@ def debug_data Coverband.configuration.store.get_coverage_report.to_json end + def enriched_debug_data + Coverband::Reporters::HTMLReport.new(Coverband.configuration.store, + static: false, + base_path: base_path, + notice: '', + open_report: false).report_data + end + def load_file_details filename = request.params['filename'] Coverband::Reporters::HTMLReport.new(Coverband.configuration.store, diff --git a/lib/coverband/utils/html_formatter.rb b/lib/coverband/utils/html_formatter.rb index a5401ac4..df9159f3 100644 --- a/lib/coverband/utils/html_formatter.rb +++ b/lib/coverband/utils/html_formatter.rb @@ -29,6 +29,10 @@ def format_dynamic_html! format_html(@coverage_result) end + def format_dynamic_data! + format_data(@coverage_result) + end + def format_settings! format_settings end @@ -71,6 +75,10 @@ def format_html(result) template('layout').result(binding) end + def format_data(result) + template('data').result(binding) + end + # Returns the an erb instance for the template of given name def template(name) ERB.new(File.read(File.join(File.dirname(__FILE__), '../../../views/', "#{name}.erb"))) diff --git a/views/data.erb b/views/data.erb new file mode 100644 index 00000000..456aa235 --- /dev/null +++ b/views/data.erb @@ -0,0 +1 @@ +<%= result.source_files.to_json %> diff --git a/views/nav.erb b/views/nav.erb index e6d7546e..d3a60249 100644 --- a/views/nav.erb +++ b/views/nav.erb @@ -6,7 +6,8 @@ <%= button("#{base_path}clear", 'clear coverage report', delete: true) %> <% end %> <% if Coverband.configuration.web_debug %> - Coverage Data   + Debug Data   + Coverage Data   <% end %> <% if notice.to_s.length > 0 %>