simplecov-html 0.12.2 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 521389c06ee24e47f7547ed6711ed500672dde0c9489802d77f0a626536bc7a3
4
- data.tar.gz: 209a5a8e7dad6f2840efb3d7c3c05ce13ef9a64ff05550016b22157f56aeade2
3
+ metadata.gz: 39f6a1e464a4a4dc7f8909490225ad044486055ae1cefe8978738c95651c9ad8
4
+ data.tar.gz: b406a23cdb0e57671df0e919073aabb7147b0166521c630ac39ab3c0bf659af4
5
5
  SHA512:
6
- metadata.gz: 7f9f0eb594a25f55bb3a5f16ecc9e46392a71c959754e36b976403943b81090f6e68bc125f4447ebc5ff9b253c52865e9e63678b03528f286ad48327b18429c3
7
- data.tar.gz: 962890a18f9615e03c8a4b3e06392a315a8c7194cad69b7a0a3a32a0a9760f7ebc640a418a8f12d76207883e480c8c22e748a96d44348a9484dd7bb1d04cda39
6
+ metadata.gz: 9cecd560f071e8b9f37b7fa70354c49748704f69d318a35e844cfe03848fba01b01bdb4d4e973c5219d0aeda318e5f4abc143e78d4beaeca13b27e1ae94594b5
7
+ data.tar.gz: 51b3f7d1541d4a9bddb1e05a20a0c03dc6cde3885c366b914dfd4bdb4dbdea2283a26bfd648b631e1deda38acd4cd6d91d131c3271b6fafe95e4d82272328d6f
data/.tool-versions CHANGED
@@ -1 +1 @@
1
- ruby 2.6.5
1
+ ruby 2.7.1
data/CHANGELOG.md CHANGED
@@ -1,8 +1,33 @@
1
+ 0.13.0 (2024-09-08)
2
+ ==================
3
+
4
+ ## Enhancements
5
+ * Cache erb templates when generating report. See [#114](https://github.com/simplecov-ruby/simplecov-html/pull/114) (thanks [@fatkodima](https://github.com/fatkodima)).
6
+ * Print branch coverage with line coverage. See [#103](https://github.com/simplecov-ruby/simplecov-html/pull/103) (thanks [@jeremyevans](https://github.com/jeremyevans)).
7
+ * Add line number anchors. Thanks [@jantman](https://github.com/jantman) for the proposal [#49](https://github.com/simplecov-ruby/simplecov-html/issues/49) and [@nishidayuya](https://github.com/nishidayuya) for the patch [#106](https://github.com/simplecov-ruby/simplecov-html/pull/106)!
8
+ * Add inline assets option. See [#107](https://github.com/simplecov-ruby/simplecov-html/pull/107) (thanks [@frankh](https://github.com/frankh)).
9
+ * Make close button look better. See [#140](https://github.com/simplecov-ruby/simplecov-html/pull/140) (thanks [@anthony0030](https://github.com/anthony0030)).
10
+ * Avoid "permission denied" errors by removing the destination before copying assets [#135](https://github.com/simplecov-ruby/simplecov-html/pull/135) (thanks [@tomeon](https://github.com/tomeon)).
11
+ * Improve clarity of line and branch coverage format. See [#125](https://github.com/simplecov-ruby/simplecov-html/pull/125) (thanks [@joshuapinter](https://github.com/joshuapinter)).
12
+
13
+ ## Bugfixes
14
+ * Avoid loading favicon.png that does not exist. See [#123](https://github.com/simplecov-ruby/simplecov-html/pull/123) (thanks [@yyamanoi1222](https://github.com/yyamanoi1222)).
15
+
16
+ ## Misc
17
+ * Reduced gem size by not including development-only files.
18
+ * Bundle jQuery 3.7.1. See [#108](https://github.com/simplecov-ruby/simplecov-html/issues/108) (thanks [@jgarland79](https://github.com/jgarland79) for reporting the issue).
19
+
20
+ 0.12.3 (2020-09-23)
21
+ ==================
22
+
23
+ ## Bugfixes
24
+ * Relax ruby version requirement to work with Ruby 3.0 (next version, current `ruby-head`). Thanks [@byroot](https://github.com/byroot).
25
+
1
26
  0.12.2 (2020-02-27)
2
27
  ==================
3
28
 
4
29
  ## Bugfixes
5
- * Refreshing the page while a source file is open works again. Thanks [@HansBug](https://github.com/HansBug) for the report [#94](https://github.com/colszowka/simplecov-html/issues/94) and [@Tietew](https://github.com/Tietew) for the fix!
30
+ * Refreshing the page while a source file is open works again. Thanks [@HansBug](https://github.com/HansBug) for the report [#94](https://github.com/simplecov-ruby/simplecov-html/issues/94) and [@Tietew](https://github.com/Tietew) for the fix!
6
31
 
7
32
  0.12.1 (2020-02-23)
8
33
  ==================
@@ -30,6 +55,8 @@ Yes it looks different, no it's not a redesign - just a side effect of lots of d
30
55
  * make sure encoding errors won't crash the formatter
31
56
  * When viewing a short source file while you have a big file list you will no longer be able to scroll on after the source file has ended
32
57
 
58
+
59
+
33
60
  0.11.0 (2020-01-28)
34
61
  =======
35
62
 
@@ -65,11 +92,11 @@ Changes ruby support to 2.4+, adds branch coverage support. Meant to be used wit
65
92
 
66
93
  ## Bugfixes
67
94
 
68
- * Allow usage with frozen-string-literal-enabled. See [#56](https://github.com/colszowka/simplecov-html/pull/56) (thanks @pat)
95
+ * Allow usage with frozen-string-literal-enabled. See [#56](https://github.com/simplecov-ruby/simplecov-html/pull/56) (thanks @pat)
69
96
 
70
97
  0.10.1 (2017-05-17)
71
98
  ========
72
99
 
73
100
  ## Bugfixes
74
101
 
75
- * circumvent a regression that happens in the new JRuby 9.1.9.0 release. See [#53](https://github.com/colszowka/simplecov-html/pull/53) thanks @koic
102
+ * circumvent a regression that happens in the new JRuby 9.1.9.0 release. See [#53](https://github.com/simplecov-ruby/simplecov-html/pull/53) thanks @koic
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  Default HTML formatter for SimpleCov
2
2
  ====================================
3
3
 
4
- ***Note: To learn more about SimpleCov, check out the main repo at https://github.com/colszowka/simplecov***
4
+ ***Note: To learn more about SimpleCov, check out the main repo at https://github.com/simplecov-ruby/simplecov***
5
5
 
6
6
  Generates a nice HTML report of your SimpleCov ruby code coverage results on Ruby 2.4+ using client-side Javascript
7
7
  quite extensively.
data/Rakefile CHANGED
@@ -3,7 +3,7 @@
3
3
  require "bundler"
4
4
  Bundler::GemHelper.install_tasks
5
5
 
6
- # See https://github.com/colszowka/simplecov/issues/171
6
+ # See https://github.com/simplecov-ruby/simplecov/issues/171
7
7
  desc "Set permissions on all files so they are compatible with both user-local and system-wide installs"
8
8
  task :fix_permissions do
9
9
  system 'bash -c "find . -type f -exec chmod 644 {} \; && find . -type d -exec chmod 755 {} \;"'
@@ -27,18 +27,27 @@ rescue LoadError
27
27
  end
28
28
  end
29
29
 
30
- task :default => [:test, :rubocop]
30
+ task default: [:test, :rubocop]
31
31
 
32
32
  namespace :assets do
33
33
  desc "Compiles all assets"
34
34
  task :compile do
35
35
  puts "Compiling assets"
36
36
  require "sprockets"
37
+ require "sprockets/sass_processor"
38
+
39
+ Sprockets.register_processor("text/css") do |input|
40
+ {data: input[:data].gsub(/(?<!-|_)url\(['"]?(.+?)['"]?\)/) { "asset-data-url(\"#{Regexp.last_match(1)}\")" }}
41
+ end
42
+
43
+ Sprockets.register_processor "text/css", Sprockets::ScssProcessor
44
+
37
45
  assets = Sprockets::Environment.new do |env|
38
46
  env.append_path "assets/javascripts"
39
47
  env.append_path "assets/stylesheets"
48
+ env.append_path "public"
40
49
  env.js_compressor = :uglify
41
- env.css_compressor = :yui
50
+ env.css_compressor = :scss
42
51
  end
43
52
  assets["application.js"].write_to("public/application.js")
44
53
  assets["application.css"].write_to("public/application.css")
@@ -3,7 +3,7 @@
3
3
  module SimpleCov
4
4
  module Formatter
5
5
  class HTMLFormatter
6
- VERSION = "0.12.2"
6
+ VERSION = "0.13.0"
7
7
  end
8
8
  end
9
9
  end
@@ -5,12 +5,13 @@ require "cgi"
5
5
  require "fileutils"
6
6
  require "digest/sha1"
7
7
  require "time"
8
+ require "base64"
8
9
 
9
10
  # Ensure we are using a compatible version of SimpleCov
10
11
  major, minor, patch = SimpleCov::VERSION.scan(/\d+/).first(3).map(&:to_i)
11
12
  if major < 0 || minor < 9 || patch < 0
12
- raise "The version of SimpleCov you are using is too old. "\
13
- "Please update with `gem install simplecov` or `bundle update simplecov`"
13
+ raise "The version of SimpleCov you are using is too old. " \
14
+ "Please update with `gem install simplecov` or `bundle update simplecov`"
14
15
  end
15
16
 
16
17
  module SimpleCov
@@ -18,11 +19,16 @@ module SimpleCov
18
19
  class HTMLFormatter
19
20
  def initialize
20
21
  @branchable_result = SimpleCov.branch_coverage?
22
+ @templates = {}
23
+ @inline_assets = !ENV["SIMPLECOV_INLINE_ASSETS"].nil?
24
+ @public_assets_dir = File.join(File.dirname(__FILE__), "../public/")
21
25
  end
22
26
 
23
27
  def format(result)
24
- Dir[File.join(File.dirname(__FILE__), "../public/*")].each do |path|
25
- FileUtils.cp_r(path, asset_output_path)
28
+ unless @inline_assets
29
+ Dir[File.join(@public_assets_dir, "*")].each do |path|
30
+ FileUtils.cp_r(path, asset_output_path, remove_destination: true)
31
+ end
26
32
  end
27
33
 
28
34
  File.open(File.join(output_path, "index.html"), "wb") do |file|
@@ -31,9 +37,7 @@ module SimpleCov
31
37
  puts output_message(result)
32
38
  end
33
39
 
34
- def output_message(result)
35
- "Coverage report generated for #{result.command_name} to #{output_path}. #{result.covered_lines} / #{result.total_lines} LOC (#{result.covered_percent.round(2)}%) covered."
36
- end
40
+ private
37
41
 
38
42
  def branchable_result?
39
43
  # cached in initialize because we truly look it up a whole bunch of times
@@ -50,11 +54,16 @@ module SimpleCov
50
54
  end
51
55
  end
52
56
 
53
- private
57
+ def output_message(result)
58
+ output = "Coverage report generated for #{result.command_name} to #{output_path}."
59
+ output += "\nLine Coverage: #{result.covered_percent.round(2)}% (#{result.covered_lines} / #{result.total_lines})"
60
+ output += "\nBranch Coverage: #{result.coverage_statistics[:branch].percent.round(2)}% (#{result.covered_branches} / #{result.total_branches})" if branchable_result?
61
+ output
62
+ end
54
63
 
55
64
  # Returns the an erb instance for the template of given name
56
65
  def template(name)
57
- ERB.new(File.read(File.join(File.dirname(__FILE__), "../views/", "#{name}.erb")))
66
+ @templates[name] ||= ERB.new(File.read(File.join(File.dirname(__FILE__), "../views/", "#{name}.erb")))
58
67
  end
59
68
 
60
69
  def output_path
@@ -70,9 +79,28 @@ module SimpleCov
70
79
  end
71
80
 
72
81
  def assets_path(name)
82
+ return asset_inline(name) if @inline_assets
83
+
73
84
  File.join("./assets", SimpleCov::Formatter::HTMLFormatter::VERSION, name)
74
85
  end
75
86
 
87
+ # Only have a few content types, just hardcode them
88
+ CONTENT_TYPES = {
89
+ ".js" => "text/javascript",
90
+ ".png" => "image/png",
91
+ ".gif" => "image/gif",
92
+ ".css" => "text/css",
93
+ }.freeze
94
+
95
+ def asset_inline(name)
96
+ path = File.join(@public_assets_dir, name)
97
+ base64_content = Base64.strict_encode64 File.read(path)
98
+
99
+ content_type = CONTENT_TYPES[File.extname(name)]
100
+
101
+ "data:#{content_type};base64,#{base64_content}"
102
+ end
103
+
76
104
  # Returns the html for the given source_file
77
105
  def formatted_source_file(source_file)
78
106
  template("source_file").result(binding)
@@ -82,11 +110,11 @@ module SimpleCov
82
110
 
83
111
  # Returns a table containing the given source files
84
112
  def formatted_file_list(title, source_files)
85
- title_id = title.gsub(/^[^a-zA-Z]+/, "").gsub(/[^a-zA-Z0-9\-\_]/, "")
113
+ title_id = title.gsub(/^[^a-zA-Z]+/, "").gsub(/[^a-zA-Z0-9\-_]/, "")
86
114
  # Silence a warning by using the following variable to assign to itself:
87
115
  # "warning: possibly useless use of a variable in void context"
88
116
  # The variable is used by ERB via binding.
89
- title_id = title_id
117
+ title_id = title_id # rubocop:disable Lint/SelfAssignment
90
118
  template("file_list").result(binding)
91
119
  end
92
120