coverband 5.2.6.rc.3 → 5.2.6.rc.4
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 +4 -4
- data/changes.md +1 -0
- data/lib/coverband/reporters/json_report.rb +57 -0
- data/lib/coverband/reporters/web.rb +6 -0
- data/lib/coverband/version.rb +1 -1
- data/lib/coverband.rb +1 -0
- data/test/coverband/reporters/json_test.rb +48 -0
- data/test/test_helper.rb +4 -3
- metadata +5 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 45ab4b4c0eec8a0b642cb2236bb4fbf4b3117ec6af3c4279b37236f360fbeab6
|
|
4
|
+
data.tar.gz: 07010dd790b47cecc8fd5318bc27ec779c8f801a33943694d794a6c23686723f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 054ac7588139476dd9f0b51caa28023f037867eac12a89d523efa0ed220791e340a468f26a1fe5f67661986008449e492be2f005f948377f7d4e728604ed8c86
|
|
7
|
+
data.tar.gz: d1c38bb92fb95e3125cb25eb188cefce1efe86ce68932078cd75a4ae417dd1626263aa3849f45edd37d72cbd86ba72627b78271354c6d6ddd23648859c47e5cf
|
data/changes.md
CHANGED
|
@@ -5,6 +5,7 @@ __NOTE: the current RCs include below, but this might turn into coverband 6.0__
|
|
|
5
5
|
- add support for translation keys
|
|
6
6
|
- refactor non Coverage.so based trackers
|
|
7
7
|
- adds CSP report support (thanks @jwg2s)
|
|
8
|
+
- add JSON reporter (thanks @mark-davenport-fountain)
|
|
8
9
|
|
|
9
10
|
### Coverband 5.2.5
|
|
10
11
|
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Outputs data in json format similar to what is shown in the HTML page
|
|
4
|
+
# Top level and file level coverage numbers
|
|
5
|
+
module Coverband
|
|
6
|
+
module Reporters
|
|
7
|
+
class JSONReport < Base
|
|
8
|
+
attr_accessor :filtered_report_files
|
|
9
|
+
|
|
10
|
+
def initialize(store, options = {})
|
|
11
|
+
coverband_reports = Coverband::Reporters::Base.report(store, options)
|
|
12
|
+
self.filtered_report_files = self.class.fix_reports(coverband_reports)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def report
|
|
16
|
+
report_as_json
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
private
|
|
20
|
+
|
|
21
|
+
def report_as_json
|
|
22
|
+
result = Coverband::Utils::Results.new(filtered_report_files)
|
|
23
|
+
source_files = result.source_files
|
|
24
|
+
{
|
|
25
|
+
**coverage_totals(source_files),
|
|
26
|
+
files: coverage_files(result, source_files)
|
|
27
|
+
}.to_json
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def coverage_totals(source_files)
|
|
31
|
+
{
|
|
32
|
+
total_files: source_files.length,
|
|
33
|
+
lines_of_code: source_files.lines_of_code,
|
|
34
|
+
lines_covered: source_files.covered_lines,
|
|
35
|
+
lines_missed: source_files.missed_lines,
|
|
36
|
+
covered_strength: source_files.covered_strength,
|
|
37
|
+
covered_percent: source_files.covered_percent
|
|
38
|
+
}
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Using a hash indexed by file name for quick lookups
|
|
42
|
+
def coverage_files(result, source_files)
|
|
43
|
+
source_files.each_with_object({}) do |source_file, hash|
|
|
44
|
+
hash[source_file.short_name] = {
|
|
45
|
+
never_loaded: source_file.never_loaded,
|
|
46
|
+
runtime_percentage: result.runtime_relevant_coverage(source_file),
|
|
47
|
+
lines_of_code: source_file.lines.count,
|
|
48
|
+
lines_covered: source_file.covered_lines.count,
|
|
49
|
+
lines_missed: source_file.missed_lines.count,
|
|
50
|
+
covered_percent: source_file.covered_percent,
|
|
51
|
+
covered_strength: source_file.covered_strength
|
|
52
|
+
}
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -90,6 +90,8 @@ module Coverband
|
|
|
90
90
|
[200, coverband_headers(content_type: "text/json"), [debug_data]]
|
|
91
91
|
when %r{\/load_file_details}
|
|
92
92
|
[200, coverband_headers(content_type: "text/json"), [load_file_details]]
|
|
93
|
+
when %r{\/json}
|
|
94
|
+
[200, coverband_headers(content_type: "text/json"), [json]]
|
|
93
95
|
when %r{\/$}
|
|
94
96
|
[200, coverband_headers, [index]]
|
|
95
97
|
else
|
|
@@ -109,6 +111,10 @@ module Coverband
|
|
|
109
111
|
open_report: false).report
|
|
110
112
|
end
|
|
111
113
|
|
|
114
|
+
def json
|
|
115
|
+
Coverband::Reporters::JSONReport.new(Coverband.configuration.store).report
|
|
116
|
+
end
|
|
117
|
+
|
|
112
118
|
def settings
|
|
113
119
|
Coverband::Utils::HTMLFormatter.new(nil, base_path: base_path).format_settings!
|
|
114
120
|
end
|
data/lib/coverband/version.rb
CHANGED
data/lib/coverband.rb
CHANGED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require File.expand_path("../../test_helper", File.dirname(__FILE__))
|
|
4
|
+
|
|
5
|
+
class ReportJSONTest < Minitest::Test
|
|
6
|
+
def setup
|
|
7
|
+
super
|
|
8
|
+
@store = Coverband.configuration.store
|
|
9
|
+
Coverband.configure do |config|
|
|
10
|
+
config.store = @store
|
|
11
|
+
config.root = fixtures_root
|
|
12
|
+
config.ignore = ["notsomething.rb", "lib/*"]
|
|
13
|
+
end
|
|
14
|
+
mock_file_hash
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
test "includes totals" do
|
|
18
|
+
@store.send(:save_report, basic_coverage)
|
|
19
|
+
|
|
20
|
+
json = Coverband::Reporters::JSONReport.new(@store).report
|
|
21
|
+
parsed = JSON.parse(json)
|
|
22
|
+
expected_keys = ["total_files", "lines_of_code", "lines_covered", "lines_missed", "covered_strength", "covered_percent"]
|
|
23
|
+
assert expected_keys - parsed.keys == []
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
test "honors ignore list" do
|
|
27
|
+
@store.send(:save_report, basic_coverage)
|
|
28
|
+
|
|
29
|
+
json = Coverband::Reporters::JSONReport.new(@store).report
|
|
30
|
+
parsed = JSON.parse(json)
|
|
31
|
+
expected_files = ["app/controllers/sample_controller.rb", "app/models/user.rb"]
|
|
32
|
+
assert_equal parsed["files"].keys, expected_files
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
test "includes metrics for files" do
|
|
36
|
+
@store.send(:save_report, basic_coverage)
|
|
37
|
+
|
|
38
|
+
json = Coverband::Reporters::JSONReport.new(@store).report
|
|
39
|
+
parsed = JSON.parse(json)
|
|
40
|
+
|
|
41
|
+
expected_keys = ["never_loaded", "runtime_percentage", "lines_of_code", "lines_covered", "lines_missed", "covered_percent", "covered_strength"]
|
|
42
|
+
|
|
43
|
+
assert_equal parsed["files"].length, 2
|
|
44
|
+
parsed["files"].keys.each do |file|
|
|
45
|
+
assert_equal parsed["files"][file].keys, expected_keys
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
data/test/test_helper.rb
CHANGED
|
@@ -33,6 +33,7 @@ require "coverband/utils/source_file"
|
|
|
33
33
|
require "coverband/utils/lines_classifier"
|
|
34
34
|
require "coverband/utils/results"
|
|
35
35
|
require "coverband/reporters/html_report"
|
|
36
|
+
require "coverband/reporters/json_report"
|
|
36
37
|
require "webmock/minitest"
|
|
37
38
|
|
|
38
39
|
require_relative "unique_files"
|
|
@@ -93,13 +94,13 @@ Mocha::Configuration.prevent(:stubbing_non_existent_method)
|
|
|
93
94
|
def test(name, &block)
|
|
94
95
|
test_name = "test_#{name.gsub(/\s+/, "_")}".to_sym
|
|
95
96
|
defined = begin
|
|
96
|
-
|
|
97
|
+
instance_method(test_name)
|
|
97
98
|
rescue
|
|
98
99
|
false
|
|
99
|
-
|
|
100
|
+
end
|
|
100
101
|
raise "#{test_name} is already defined in #{self}" if defined
|
|
101
102
|
|
|
102
|
-
if
|
|
103
|
+
if block
|
|
103
104
|
define_method(test_name, &block)
|
|
104
105
|
else
|
|
105
106
|
define_method(test_name) do
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: coverband
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 5.2.6.rc.
|
|
4
|
+
version: 5.2.6.rc.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Dan Mayer
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2023-
|
|
12
|
+
date: 2023-03-05 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: benchmark-ips
|
|
@@ -315,6 +315,7 @@ files:
|
|
|
315
315
|
- lib/coverband/reporters/base.rb
|
|
316
316
|
- lib/coverband/reporters/console_report.rb
|
|
317
317
|
- lib/coverband/reporters/html_report.rb
|
|
318
|
+
- lib/coverband/reporters/json_report.rb
|
|
318
319
|
- lib/coverband/reporters/web.rb
|
|
319
320
|
- lib/coverband/utils/absolute_file_converter.rb
|
|
320
321
|
- lib/coverband/utils/configuration_template.rb
|
|
@@ -396,6 +397,7 @@ files:
|
|
|
396
397
|
- test/coverband/reporters/base_test.rb
|
|
397
398
|
- test/coverband/reporters/console_test.rb
|
|
398
399
|
- test/coverband/reporters/html_test.rb
|
|
400
|
+
- test/coverband/reporters/json_test.rb
|
|
399
401
|
- test/coverband/reporters/web_test.rb
|
|
400
402
|
- test/coverband/utils/absolute_file_converter_test.rb
|
|
401
403
|
- test/coverband/utils/dead_methods_test.rb
|
|
@@ -556,6 +558,7 @@ test_files:
|
|
|
556
558
|
- test/coverband/reporters/base_test.rb
|
|
557
559
|
- test/coverband/reporters/console_test.rb
|
|
558
560
|
- test/coverband/reporters/html_test.rb
|
|
561
|
+
- test/coverband/reporters/json_test.rb
|
|
559
562
|
- test/coverband/reporters/web_test.rb
|
|
560
563
|
- test/coverband/utils/absolute_file_converter_test.rb
|
|
561
564
|
- test/coverband/utils/dead_methods_test.rb
|