danger-junit 0.7.2 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Gemfile.lock +35 -27
- data/README.md +5 -0
- data/lib/junit/gem_version.rb +1 -1
- data/lib/junit/plugin.rb +74 -24
- data/spec/fixtures/fastlane_trainer.xml +3 -1
- data/spec/junit_spec.rb +34 -4
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7bf7c5a5328e43b8014cb99e27f27987b17a3c9562e509f71f509bba2139bf83
|
4
|
+
data.tar.gz: b75de0c8814196c011e44d3fd553696cf2d8c621c0bb8914c14b3dd40ebab0cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da893811b7e22728066d62ef78c6028618c722486abb4649408cbb9ea1476f9e229ea2fc924f209bf576801372f97e6ddaddefed41847b7316b88a06dfdde9aa
|
7
|
+
data.tar.gz: 0dd551a5209f12bc66638ea19cc6e70660feab9b811bc5b4bcb2e5a774ae5d8973837dfab5953674762532b14fb2ba54e42fb95847dfac0fdac87e16bd8b8308
|
data/Gemfile.lock
CHANGED
@@ -1,44 +1,47 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
danger-junit (0.
|
5
|
-
danger (
|
4
|
+
danger-junit (1.0.1)
|
5
|
+
danger (> 2.0)
|
6
6
|
ox (~> 2.0)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
addressable (2.
|
11
|
+
addressable (2.7.0)
|
12
|
+
public_suffix (>= 2.0.2, < 5.0)
|
12
13
|
ast (2.3.0)
|
13
14
|
builder (3.2.2)
|
14
|
-
claide (1.0.
|
15
|
-
claide-plugins (0.9.
|
15
|
+
claide (1.0.3)
|
16
|
+
claide-plugins (0.9.2)
|
16
17
|
cork
|
17
18
|
nap
|
18
19
|
open4 (~> 1.3)
|
19
20
|
coderay (1.1.1)
|
20
|
-
|
21
|
-
cork (0.
|
22
|
-
|
23
|
-
danger (
|
21
|
+
colored2 (3.1.2)
|
22
|
+
cork (0.3.0)
|
23
|
+
colored2 (~> 3.1)
|
24
|
+
danger (5.9.0)
|
24
25
|
claide (~> 1.0)
|
25
|
-
claide-plugins (
|
26
|
-
|
26
|
+
claide-plugins (>= 0.9.2)
|
27
|
+
colored2 (~> 3.1)
|
27
28
|
cork (~> 0.1)
|
28
|
-
faraday (~> 0)
|
29
|
+
faraday (~> 0.9)
|
29
30
|
faraday-http-cache (~> 1.0)
|
30
|
-
git (~> 1)
|
31
|
+
git (~> 1.5)
|
31
32
|
kramdown (~> 1.5)
|
32
|
-
|
33
|
+
no_proxy_fix
|
34
|
+
octokit (~> 4.7)
|
33
35
|
terminal-table (~> 1)
|
34
36
|
diff-lcs (1.2.5)
|
35
|
-
faraday (0.
|
37
|
+
faraday (0.17.3)
|
36
38
|
multipart-post (>= 1.2, < 3)
|
37
|
-
faraday-http-cache (1.3.
|
39
|
+
faraday-http-cache (1.3.1)
|
38
40
|
faraday (~> 0.8)
|
39
41
|
ffi (1.9.14)
|
40
42
|
formatador (0.2.5)
|
41
|
-
git (1.
|
43
|
+
git (1.7.0)
|
44
|
+
rchardet (~> 1.8)
|
42
45
|
guard (2.14.0)
|
43
46
|
formatador (>= 0.2.4)
|
44
47
|
listen (>= 2.7, < 4.0)
|
@@ -53,22 +56,24 @@ GEM
|
|
53
56
|
guard (~> 2.1)
|
54
57
|
guard-compat (~> 1.1)
|
55
58
|
rspec (>= 2.99.0, < 4.0)
|
56
|
-
kramdown (1.
|
59
|
+
kramdown (1.17.0)
|
57
60
|
listen (3.0.7)
|
58
61
|
rb-fsevent (>= 0.9.3)
|
59
62
|
rb-inotify (>= 0.9.7)
|
60
63
|
lumberjack (1.0.10)
|
61
64
|
method_source (0.8.2)
|
62
|
-
multipart-post (2.
|
65
|
+
multipart-post (2.1.1)
|
63
66
|
nap (1.1.0)
|
64
67
|
nenv (0.3.0)
|
68
|
+
no_proxy_fix (0.1.2)
|
65
69
|
notiffany (0.1.1)
|
66
70
|
nenv (~> 0.1)
|
67
71
|
shellany (~> 0.0)
|
68
|
-
octokit (4.
|
69
|
-
|
72
|
+
octokit (4.16.0)
|
73
|
+
faraday (>= 0.9)
|
74
|
+
sawyer (~> 0.8.0, >= 0.5.3)
|
70
75
|
open4 (1.3.4)
|
71
|
-
ox (2.
|
76
|
+
ox (2.13.2)
|
72
77
|
parser (2.3.1.2)
|
73
78
|
ast (~> 2.2)
|
74
79
|
powerpack (0.1.1)
|
@@ -76,11 +81,13 @@ GEM
|
|
76
81
|
coderay (~> 1.1.0)
|
77
82
|
method_source (~> 0.8.1)
|
78
83
|
slop (~> 3.4)
|
84
|
+
public_suffix (4.0.5)
|
79
85
|
rainbow (2.1.0)
|
80
86
|
rake (10.5.0)
|
81
87
|
rb-fsevent (0.9.7)
|
82
88
|
rb-inotify (0.9.7)
|
83
89
|
ffi (>= 0.5.0)
|
90
|
+
rchardet (1.8.0)
|
84
91
|
rspec (3.5.0)
|
85
92
|
rspec-core (~> 3.5.0)
|
86
93
|
rspec-expectations (~> 3.5.0)
|
@@ -104,12 +111,13 @@ GEM
|
|
104
111
|
ruby-progressbar (~> 1.7)
|
105
112
|
unicode-display_width (~> 1.0, >= 1.0.1)
|
106
113
|
ruby-progressbar (1.8.1)
|
107
|
-
sawyer (0.
|
108
|
-
addressable (>= 2.3.5
|
109
|
-
faraday (
|
114
|
+
sawyer (0.8.2)
|
115
|
+
addressable (>= 2.3.5)
|
116
|
+
faraday (> 0.8, < 2.0)
|
110
117
|
shellany (0.0.1)
|
111
118
|
slop (3.6.0)
|
112
|
-
terminal-table (1.
|
119
|
+
terminal-table (1.7.0)
|
120
|
+
unicode-display_width (~> 1.1)
|
113
121
|
thor (0.19.1)
|
114
122
|
unicode-display_width (1.1.0)
|
115
123
|
yard (0.9.5)
|
@@ -131,4 +139,4 @@ DEPENDENCIES
|
|
131
139
|
yard (~> 0.8)
|
132
140
|
|
133
141
|
BUNDLED WITH
|
134
|
-
1.
|
142
|
+
1.17.3
|
data/README.md
CHANGED
@@ -72,6 +72,7 @@ fail("Tests failed") unless junit.failures.empty?
|
|
72
72
|
<pre>
|
73
73
|
junit.parse "/path/to/output.xml"
|
74
74
|
junit.show_skipped_tests = true
|
75
|
+
junit.skipped_headers = [:name, :file]
|
75
76
|
junit.report</pre>
|
76
77
|
</blockquote>
|
77
78
|
|
@@ -109,6 +110,10 @@ message "#{slowest_test[:time]} took #{slowest_test[:time]} seconds"
|
|
109
110
|
`headers` - An array of symbols that become the columns of your tests,
|
110
111
|
if `nil`, the default, it will be all of the attributes.
|
111
112
|
|
113
|
+
`skipped_headers` - An array of symbols that become the columns of your skipped tests,
|
114
|
+
if `nil`, the default, it will be all of the attributes for a single parse
|
115
|
+
or all of the common attributes between multiple files
|
116
|
+
|
112
117
|
|
113
118
|
|
114
119
|
#### Methods
|
data/lib/junit/gem_version.rb
CHANGED
data/lib/junit/plugin.rb
CHANGED
@@ -14,6 +14,16 @@ module Danger
|
|
14
14
|
# junit.parse "/path/to/output.xml"
|
15
15
|
# junit.report
|
16
16
|
#
|
17
|
+
# @example Parse multiple XML files by passing multiple file names
|
18
|
+
#
|
19
|
+
# junit.parse_files "/path/to/integration-tests.xml", "/path/to/unit-tests.xml"
|
20
|
+
# junit.report
|
21
|
+
#
|
22
|
+
# @example Parse multiple XML files by passing an array
|
23
|
+
# result_files = %w(/path/to/integration-tests.xml /path/to/unit-tests.xml)
|
24
|
+
# junit.parse_files result_files
|
25
|
+
# junit.report
|
26
|
+
#
|
17
27
|
# @example Let the plugin parse the XML file, and report yourself
|
18
28
|
#
|
19
29
|
# junit.parse "/path/to/output.xml"
|
@@ -76,28 +86,48 @@ module Danger
|
|
76
86
|
attr_accessor :show_skipped_tests
|
77
87
|
|
78
88
|
# An array of symbols that become the columns of your tests,
|
79
|
-
# if `nil`, the default, it will be all of the attributes
|
89
|
+
# if `nil`, the default, it will be all of the attributes for a single parse
|
90
|
+
# or all of the common attributes between multiple files
|
80
91
|
#
|
81
92
|
# @return [Array<Symbol>]
|
82
93
|
attr_accessor :headers
|
83
94
|
|
95
|
+
# An array of symbols that become the columns of your skipped tests,
|
96
|
+
# if `nil`, the default, it will be all of the attributes for a single parse
|
97
|
+
# or all of the common attributes between multiple files
|
98
|
+
#
|
99
|
+
# @return [Array<Symbol>]
|
100
|
+
attr_accessor :skipped_headers
|
101
|
+
|
84
102
|
# Parses an XML file, which fills all the attributes,
|
85
103
|
# will `raise` for errors
|
86
104
|
# @return [void]
|
87
105
|
def parse(file)
|
106
|
+
parse_files(file)
|
107
|
+
end
|
108
|
+
|
109
|
+
# Parses multiple XML files, which fills all the attributes,
|
110
|
+
# will `raise` for errors
|
111
|
+
# @return [void]
|
112
|
+
def parse_files(*files)
|
88
113
|
require 'ox'
|
89
|
-
|
114
|
+
@tests = []
|
115
|
+
failed_tests = []
|
90
116
|
|
91
|
-
|
92
|
-
|
117
|
+
Array(files).flatten.each do |file|
|
118
|
+
raise "No JUnit file was found at #{file}" unless File.exist? file
|
93
119
|
|
94
|
-
|
95
|
-
|
120
|
+
xml_string = File.read(file)
|
121
|
+
doc = Ox.parse(xml_string)
|
96
122
|
|
97
|
-
|
98
|
-
|
123
|
+
suite_root = doc.nodes.first.value == 'testsuites' ? doc.nodes.first : doc
|
124
|
+
@tests += suite_root.nodes.map(&:nodes).flatten.select { |node| node.kind_of?(Ox::Element) && node.value == 'testcase' }
|
99
125
|
|
100
|
-
|
126
|
+
failed_suites = suite_root.nodes.select { |suite| suite[:failures].to_i > 0 || suite[:errors].to_i > 0 }
|
127
|
+
failed_tests += failed_suites.map(&:nodes).flatten.select { |node| node.kind_of?(Ox::Element) && node.value == 'testcase' }
|
128
|
+
end
|
129
|
+
|
130
|
+
@failures = failed_tests.select do |test|
|
101
131
|
test.nodes.count > 0
|
102
132
|
end.select do |test|
|
103
133
|
node = test.nodes.first
|
@@ -127,32 +157,52 @@ module Danger
|
|
127
157
|
# @return [void]
|
128
158
|
def report
|
129
159
|
return if failures.nil? # because danger calls `report` before loading a file
|
130
|
-
|
160
|
+
if show_skipped_tests && skipped.count > 0
|
161
|
+
warn("Skipped #{skipped.count} tests.")
|
162
|
+
|
163
|
+
message = "### Skipped: \n\n"
|
164
|
+
message << get_report_content(skipped, skipped_headers)
|
165
|
+
markdown message
|
166
|
+
|
167
|
+
end
|
131
168
|
|
132
169
|
unless failures.empty? && errors.empty?
|
133
170
|
fail('Tests have failed, see below for more information.', sticky: false)
|
134
|
-
message = "### Tests: \n\n"
|
135
171
|
|
172
|
+
message = "### Tests: \n\n"
|
136
173
|
tests = (failures + errors)
|
137
|
-
|
138
|
-
attributes = keys.map(&:to_s).map(&:capitalize)
|
139
|
-
|
140
|
-
# Create the headers
|
141
|
-
message << attributes.join(' | ') + "|\n"
|
142
|
-
message << attributes.map { |_| '---' }.join(' | ') + "|\n"
|
143
|
-
|
144
|
-
# Map out the keys to the tests
|
145
|
-
tests.each do |test|
|
146
|
-
row_values = keys.map { |key| test.attributes[key] }.map { |v| auto_link(v) }
|
147
|
-
message << row_values.join(' | ') + "|\n"
|
148
|
-
end
|
149
|
-
|
174
|
+
message << get_report_content(tests, headers)
|
150
175
|
markdown message
|
151
176
|
end
|
152
177
|
end
|
153
178
|
|
154
179
|
private
|
155
180
|
|
181
|
+
def get_report_content(tests, headers)
|
182
|
+
message = ''
|
183
|
+
common_attributes = tests.map{|test| test.attributes.keys }.inject(&:&)
|
184
|
+
|
185
|
+
# check the provided headers are available
|
186
|
+
unless headers.nil?
|
187
|
+
not_available_headers = headers.select { |header| not common_attributes.include?(header) }
|
188
|
+
raise "Some of headers provided aren't available in the JUnit report (#{not_available_headers})" unless not_available_headers.empty?
|
189
|
+
end
|
190
|
+
|
191
|
+
keys = headers || common_attributes
|
192
|
+
attributes = keys.map(&:to_s).map(&:capitalize)
|
193
|
+
|
194
|
+
# Create the headers
|
195
|
+
message << attributes.join(' | ') + "|\n"
|
196
|
+
message << attributes.map { |_| '---' }.join(' | ') + "|\n"
|
197
|
+
|
198
|
+
# Map out the keys to the tests
|
199
|
+
tests.each do |test|
|
200
|
+
row_values = keys.map { |key| test.attributes[key] }.map { |v| auto_link(v) }
|
201
|
+
message << row_values.join(' | ') + "|\n"
|
202
|
+
end
|
203
|
+
message
|
204
|
+
end
|
205
|
+
|
156
206
|
def auto_link(value)
|
157
207
|
if File.exist?(value) && defined?(@dangerfile.github)
|
158
208
|
github.html_link(value, full_path: false)
|
@@ -1,5 +1,7 @@
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
2
2
|
<testsuites tests="2" failures="1">
|
3
|
+
<testsuite name="EmptyTests" tests="0" failures="0">
|
4
|
+
</testsuite>
|
3
5
|
<testsuite name="ThemojiUITests" tests="2" failures="1">
|
4
6
|
<testcase classname="ThemojiUITests" name="testExample()">
|
5
7
|
</testcase>
|
@@ -8,4 +10,4 @@
|
|
8
10
|
</failure>
|
9
11
|
</testcase>
|
10
12
|
</testsuite>
|
11
|
-
</testsuites>
|
13
|
+
</testsuites>
|
data/spec/junit_spec.rb
CHANGED
@@ -55,7 +55,7 @@ module Danger
|
|
55
55
|
|
56
56
|
output = @junit.status_report[:markdowns].first
|
57
57
|
row = '| Danger::CISource::CircleCI validates when circle all env vars are set | ./spec/lib/danger/ci_sources/circle_spec.rb | 0.012097|'
|
58
|
-
expect(output).to include(row)
|
58
|
+
expect(output.to_s).to include(row)
|
59
59
|
end
|
60
60
|
|
61
61
|
it 'shows a known markdown row' do
|
@@ -65,7 +65,7 @@ module Danger
|
|
65
65
|
|
66
66
|
output = @junit.status_report[:markdowns].first
|
67
67
|
row = "Time|\n"
|
68
|
-
expect(output).to include(row)
|
68
|
+
expect(output.to_s).to include(row)
|
69
69
|
end
|
70
70
|
|
71
71
|
it 'shows a warning for skipped' do
|
@@ -78,14 +78,44 @@ module Danger
|
|
78
78
|
end
|
79
79
|
|
80
80
|
it 'links paths that are files' do
|
81
|
-
allow(@dangerfile.github).to receive(:pr_json).and_return(head
|
81
|
+
allow(@dangerfile.github).to receive(:pr_json).and_return('head' => { 'repo' => { 'html_url' => 'https://github.com/thing/thingy' } })
|
82
82
|
allow(@dangerfile.github).to receive(:head_commit).and_return('hello')
|
83
83
|
|
84
84
|
@junit.parse 'spec/fixtures/danger-junit-fail.xml'
|
85
85
|
@junit.report
|
86
86
|
|
87
87
|
outputs = @junit.status_report[:markdowns].first
|
88
|
-
expect(outputs).to include('github.com/thing/thingy')
|
88
|
+
expect(outputs.to_s).to include('github.com/thing/thingy')
|
89
|
+
end
|
90
|
+
|
91
|
+
describe 'parsing multiple files' do
|
92
|
+
it 'gets the right results for multiple files' do
|
93
|
+
@junit.parse_files 'spec/fixtures/rspec_fail.xml', 'spec/fixtures/fastlane_trainer.xml'
|
94
|
+
|
95
|
+
expect(@junit.failures.count).to eq 1 + 1
|
96
|
+
expect(@junit.passes.count).to eq 190 + 1
|
97
|
+
expect(@junit.errors.count).to eq 0 + 0
|
98
|
+
expect(@junit.skipped.count).to eq 7 + 0
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'gets the right results for an array of files' do
|
102
|
+
files = %w(spec/fixtures/rspec_fail.xml spec/fixtures/fastlane_trainer.xml)
|
103
|
+
@junit.parse_files files
|
104
|
+
|
105
|
+
expect(@junit.failures.count).to eq 1 + 1
|
106
|
+
expect(@junit.passes.count).to eq 190 + 1
|
107
|
+
expect(@junit.errors.count).to eq 0 + 0
|
108
|
+
expect(@junit.skipped.count).to eq 7 + 0
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'defaults to reporting common attributes for multiple files' do
|
112
|
+
@junit.parse_files 'spec/fixtures/rspec_fail.xml', 'spec/fixtures/eigen_fail.xml'
|
113
|
+
|
114
|
+
@junit.report
|
115
|
+
|
116
|
+
outputs = @junit.status_report[:markdowns].first
|
117
|
+
expect(outputs.to_s).to include('Classname | Name')
|
118
|
+
end
|
89
119
|
end
|
90
120
|
end
|
91
121
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: danger-junit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Orta Therox
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-07-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: danger
|
@@ -225,8 +225,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
225
225
|
- !ruby/object:Gem::Version
|
226
226
|
version: '0'
|
227
227
|
requirements: []
|
228
|
-
|
229
|
-
rubygems_version: 2.2.2
|
228
|
+
rubygems_version: 3.1.2
|
230
229
|
signing_key:
|
231
230
|
specification_version: 4
|
232
231
|
summary: Get automatic inline test reporting for JUnit-conforming XML files
|