Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup PR #254

Merged
merged 2 commits into from May 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 23 additions & 0 deletions lib/coverband/reporters/base.rb
Expand Up @@ -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)
danmayer marked this conversation as resolved.
Show resolved Hide resolved
# 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)
Expand Down
51 changes: 23 additions & 28 deletions lib/coverband/reporters/html_report.rb
Expand Up @@ -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 }
Expand All @@ -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?
danmayer marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down
2 changes: 1 addition & 1 deletion lib/coverband/reporters/web.rb
Expand Up @@ -56,7 +56,7 @@ def index
notice = "<strong>Notice:</strong> #{Rack::Utils.escape_html(request.params['notice'])}<br/>"
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
Expand Down
4 changes: 2 additions & 2 deletions lib/coverband/utils/html_formatter.rb
Expand Up @@ -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

Expand Down
13 changes: 13 additions & 0 deletions 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;
Expand Down
8 changes: 4 additions & 4 deletions test/coverband/reporters/html_test.rb
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down
6 changes: 3 additions & 3 deletions test/coverband/utils/html_formatter_test.rb
Expand Up @@ -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

Expand All @@ -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