From 27a976c52843bce19f6eed078bc7df7a3cb79fe8 Mon Sep 17 00:00:00 2001 From: Dan Mayer Date: Tue, 7 May 2019 09:46:37 -0700 Subject: [PATCH 1/2] make static vs dynamic more clear --- lib/coverband/reporters/base.rb | 23 ++++++++++ lib/coverband/reporters/html_report.rb | 51 ++++++++++----------- lib/coverband/reporters/web.rb | 2 +- lib/coverband/utils/html_formatter.rb | 4 +- test/coverband/reporters/html_test.rb | 8 ++-- test/coverband/utils/html_formatter_test.rb | 6 +-- 6 files changed, 56 insertions(+), 38 deletions(-) diff --git a/lib/coverband/reporters/base.rb b/lib/coverband/reporters/base.rb index 06ae5838..485ceb51 100644 --- a/lib/coverband/reporters/base.rb +++ b/lib/coverband/reporters/base.rb @@ -21,6 +21,29 @@ def report(store, _options = {}) scov_style_report end + ### + # Add back files that exist in the project but have no Coverage + # This makes it easy to find and delete files with no references + ### + def fix_reports(reports) + # list all files, even if not tracked by Coverband (0% coverage) + tracked_glob = "#{Coverband.configuration.current_root}/{app,lib,config}/**/*.{rb}" + filtered_report_files = {} + + reports.each_pair do |report_name, report_data| + filtered_report_files[report_name] = {} + report_files = Coverband::Utils::Result.add_not_loaded_files(report_data, tracked_glob) + + # apply coverband filters + report_files.each_pair do |file, data| + next if Coverband.configuration.ignore.any? { |i| file.match(i) } + + filtered_report_files[report_name][file] = data + end + end + filtered_report_files + end + protected def fix_file_names(report_hash, roots) diff --git a/lib/coverband/reporters/html_report.rb b/lib/coverband/reporters/html_report.rb index 4e9fc17b..11e84c14 100644 --- a/lib/coverband/reporters/html_report.rb +++ b/lib/coverband/reporters/html_report.rb @@ -3,13 +3,13 @@ module Coverband module Reporters class HTMLReport < Base - attr_accessor :filtered_report_files, :open_report, :html, :notice, + attr_accessor :filtered_report_files, :open_report, :static, :notice, :base_path, :filename def initialize(store, options = {}) coverband_reports = Coverband::Reporters::Base.report(store, options) self.open_report = options.fetch(:open_report) { true } - self.html = options.fetch(:html) { false } + self.static = options.fetch(:static) { true } # TODO: refactor notice out to top level of web only self.notice = options.fetch(:notice) { nil } self.base_path = options.fetch(:base_path) { nil } @@ -25,39 +25,34 @@ def file_details end def report - if html - Coverband::Utils::HTMLFormatter.new(filtered_report_files, - base_path: base_path, - notice: notice).format_html! + if static? + report_static_site else - Coverband::Utils::HTMLFormatter.new(filtered_report_files).format! - if open_report - `open #{Coverband.configuration.root}/coverage/index.html` - else - Coverband.configuration.logger.info 'report is ready and viewable: open coverage/index.html' - end - - Coverband::Utils::S3Report.instance.persist! if Coverband.configuration.s3_bucket + report_dynamic_html end end - def self.fix_reports(reports) - # list all files, even if not tracked by Coverband (0% coverage) - tracked_glob = "#{Coverband.configuration.current_root}/{app,lib,config}/**/*.{rb}" - filtered_report_files = {} - - reports.each_pair do |report_name, report_data| - filtered_report_files[report_name] = {} - report_files = Coverband::Utils::Result.add_not_loaded_files(report_data, tracked_glob) + private - # apply coverband filters - report_files.each_pair do |file, data| - next if Coverband.configuration.ignore.any? { |i| file.match(i) } + def static? + static + end - filtered_report_files[report_name][file] = data - end + def report_static_site + Coverband::Utils::HTMLFormatter.new(filtered_report_files).format_static_html! + if open_report + `open #{Coverband.configuration.root}/coverage/index.html` + else + Coverband.configuration.logger&.info 'report is ready and viewable: open coverage/index.html' end - filtered_report_files + + Coverband::Utils::S3Report.instance.persist! if Coverband.configuration.s3_bucket + end + + def report_dynamic_html + Coverband::Utils::HTMLFormatter.new(filtered_report_files, + base_path: base_path, + notice: notice).format_dynamic_html! end end end diff --git a/lib/coverband/reporters/web.rb b/lib/coverband/reporters/web.rb index fbebad4f..78f23bde 100644 --- a/lib/coverband/reporters/web.rb +++ b/lib/coverband/reporters/web.rb @@ -56,7 +56,7 @@ def index notice = "Notice: #{Rack::Utils.escape_html(request.params['notice'])}
" notice = request.params['notice'] ? notice : '' Coverband::Reporters::HTMLReport.new(Coverband.configuration.store, - html: true, + static: false, base_path: base_path, notice: notice, open_report: false).report diff --git a/lib/coverband/utils/html_formatter.rb b/lib/coverband/utils/html_formatter.rb index e3b00a15..51025093 100644 --- a/lib/coverband/utils/html_formatter.rb +++ b/lib/coverband/utils/html_formatter.rb @@ -21,11 +21,11 @@ def initialize(report, options = {}) @coverage_result = Coverband::Utils::Results.new(report) if report end - def format! + def format_static_html! format(@coverage_result) end - def format_html! + def format_dynamic_html! format_html(@coverage_result) end diff --git a/test/coverband/reporters/html_test.rb b/test/coverband/reporters/html_test.rb index b6fddf59..7526f96d 100644 --- a/test/coverband/reporters/html_test.rb +++ b/test/coverband/reporters/html_test.rb @@ -20,7 +20,7 @@ def setup @store.send(:save_report, basic_coverage) html = Coverband::Reporters::HTMLReport.new(@store, - html: true, + static: false, open_report: false).report assert_match 'Generated by', html end @@ -29,7 +29,7 @@ def setup @store.send(:save_report, basic_source_fixture_coverage) html = Coverband::Reporters::HTMLReport.new(@store, - html: true, + static: false, open_report: false).report assert_match 'sample.rb', html # in project, but not in coverage data @@ -40,9 +40,9 @@ def setup @store.send(:save_report, basic_coverage) reporter = Coverband::Reporters::HTMLReport.new(@store, - html: false, + static: true, open_report: false) - Coverband::Utils::HTMLFormatter.any_instance.expects(:format!).once + Coverband::Utils::HTMLFormatter.any_instance.expects(:format_static_html!).once reporter.report end diff --git a/test/coverband/utils/html_formatter_test.rb b/test/coverband/utils/html_formatter_test.rb index 671f3821..dee22b7d 100644 --- a/test/coverband/utils/html_formatter_test.rb +++ b/test/coverband/utils/html_formatter_test.rb @@ -24,7 +24,7 @@ def setup filtered_report_files = Coverband::Reporters::Base.report(@store, {}) html = Coverband::Utils::HTMLFormatter.new(filtered_report_files, base_path: base_path, - notice: notice).format_html! + notice: notice).format_dynamic_html! assert_match 'loading source data', html end @@ -38,8 +38,8 @@ def setup @store.send(:save_report, basic_coverage_full_path) filtered_report_files = Coverband::Reporters::Base.report(@store, {}) - Coverband::Utils::HTMLFormatter.new(filtered_report_files).format! + Coverband::Utils::HTMLFormatter.new(filtered_report_files).format_static_html! html = File.read("#{Coverband.configuration.root}/coverage/index.html") - assert_match 'Coverage first seen', html + assert_match 'Coverage first seen', html end end From 6bb8d79b2ab9037f40174ad8c2aff08890b23cb7 Mon Sep 17 00:00:00 2001 From: Dan Mayer Date: Tue, 7 May 2019 20:36:04 -0600 Subject: [PATCH 2/2] clear notice message so it doesn't appear on refreshes and shared links --- public/application.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/public/application.js b/public/application.js index da7faa71..3850eec4 100644 --- a/public/application.js +++ b/public/application.js @@ -1,4 +1,17 @@ $(document).ready(function() { + // remove the url params like notice=message so they don't stick around + window.history.replaceState( + "object or string", + "Coverband", + window.location.pathname + + window.location.href + .substring(window.location.href.lastIndexOf("/") + 1) + .split("?")[0] + ); + $(".notice") + .delay(3000) + .fadeOut("slow"); + $(".del").click(function() { if (!confirm("Do you want to delete")) { return false;