fastlane-plugin-flutter_tests 0.1.0 → 0.1.1

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: 562ded41eefa236b1db186681fe484aec6643c64160107a0e29c9a055e658e7f
4
- data.tar.gz: 7c7e8561a0bdd1e80495642c2aad38601371e68a59ab6e3c74c3edab48179e00
3
+ metadata.gz: 7c6b440f953fc91d3c8c62244e2fa370a5627be5bd10fbb1b2b869b51d436173
4
+ data.tar.gz: 2be21cbbb17644f0389b410b28466c968a8f231d7374c1b5a927907d0ac40435
5
5
  SHA512:
6
- metadata.gz: 3b83d6ed1199bd3fecae918e80b0f0b1cf1617e7fb857111344960e91f760ce8c914d920103253d8033ac40c7fda2e5a6f153d8d73ac87ed9e66f3d42b3d5ee4
7
- data.tar.gz: 9d8c086f8806dcf94d27b50862cebaa98e780a48795c64f7a0abee02ca1fc870d12a6af0fc4b3e6195e2205fc5dd99815ad98ad5f1e0c3115107f358fa9a2216
6
+ metadata.gz: 21f033edbc4738a67cf7348290b3e984ed47c93af3bafa42220a9a0d323e86e2b293fe95d5c2445135d98131a71522dd41c9aa262447349f565ba66099e9cdf3
7
+ data.tar.gz: c3f07e418887a032153c0a49419a185346c8580f0b5ee9df8b8a5f6ef64185d789e6d45f3e423988956ede7eb6bb849170597b612edf15d0b39dd5d17abaad0c
@@ -15,11 +15,14 @@ module Fastlane
15
15
  @test_successful = ''
16
16
  @test_error = nil
17
17
  @test_stacktrace = nil
18
+ @test_was_skipped = false
19
+ @test_was_printed = false
18
20
  end
19
21
 
20
- def mark_as_done(success, error, stacktrace)
22
+ def mark_as_done(success, skipped, error, stacktrace)
21
23
  @test_done = true
22
24
  @test_successful = success
25
+ @test_was_skipped = skipped
23
26
  @test_error = error
24
27
  unless stacktrace.nil?
25
28
  stacktrace = stacktrace.gsub(/ {2,}/, "\n")
@@ -35,14 +38,33 @@ module Fastlane
35
38
  @test_id
36
39
  end
37
40
 
38
- def _generate_message(print_errors)
39
- default_message = "[#{@test_successful}] #{@test_name}"
40
- if print_errors and @test_successful != 'success'
41
+ def can_print
42
+ !@test_was_printed
43
+ end
44
+
45
+ def get_status
46
+ if @test_was_skipped
47
+ 'skipped'
48
+ else
49
+ @test_successful
50
+ end
51
+ end
52
+
53
+ def _generate_message
54
+ tag = @test_was_skipped ? 'skipped' : @test_successful
55
+
56
+ default_message = "[#{tag}] #{@test_name}"
57
+ if @test_successful != 'success'
41
58
  default_message += "\n[ERROR] -> #{@test_error}\n[STACKTRACE]\n#{@test_stacktrace}"
42
59
  end
43
60
 
44
- if %w[success error].include?(@test_successful)
45
- color = @test_successful == 'success' ? 32 : 31
61
+ if %w[success error].include?(@test_successful) || @test_was_skipped
62
+ color = if @test_was_skipped
63
+ 34 # Skipped tests are displayed in blue
64
+ else
65
+ # Successful tests are in green and the failed in red
66
+ @test_successful == 'success' ? 32 : 31
67
+ end
46
68
 
47
69
  "\e[#{color}m#{default_message}\e[0m"
48
70
  else
@@ -50,8 +72,9 @@ module Fastlane
50
72
  end
51
73
  end
52
74
 
53
- def print(print_errors)
54
- UI.message(_generate_message(print_errors))
75
+ def print
76
+ UI.message(_generate_message)
77
+ @test_was_printed = true
55
78
  end
56
79
  end
57
80
 
@@ -60,18 +83,56 @@ module Fastlane
60
83
  @launched_tests = Hash.new { |hash, key| hash[key] = nil }
61
84
  end
62
85
 
86
+ # Wraps the message to color it
87
+ #
88
+ # @param message [String] the message that has to be wrapped
89
+ # @param color [Integer] the color of the message (34 -> blue, 32 -> green, 31 -> red)
90
+ def _colorize(message, color)
91
+ "\e[#{color}m#{message}\e[0m"
92
+ end
93
+
63
94
  # Launches all the unit tests contained in the project
64
95
  # folder
65
- def run(flutter_command, print_errors)
96
+ def run(flutter_command, print_only_failed, print_stats)
66
97
  Open3.popen3("#{flutter_command} test --machine") do |stdin, stdout, stderr, thread|
67
98
  stdout.each_line do |line|
68
- parse_json_output(line, print_errors)
99
+ parse_json_output(line, print_only_failed)
100
+ end
101
+ end
102
+
103
+ if print_stats
104
+ stats = Hash.new { |hash, key| hash[key] = 0 }
105
+ @launched_tests.values.each do |item|
106
+ unless item.nil?
107
+ stats[item.get_status] += 1
108
+ end
109
+ end
110
+
111
+ skipped_tests = stats['skipped'].nil? ? 0 : stats['skipped']
112
+ failed_tests = stats['error'].nil? ? 0 : stats['error']
113
+ successful_tests = stats['success'].nil? ? 0 : stats['success']
114
+ table = [
115
+ %w[Successful Failed Skipped],
116
+ [successful_tests, failed_tests, skipped_tests]
117
+ ]
118
+
119
+ messages = ["Ran #{@launched_tests.values.count { |e| !e.nil? }} tests"]
120
+ colors = { 0 => 32, 1 => 31, 2 => 34 }
121
+ max_length = 0
122
+ (0..2).each do |i|
123
+ msg = "#{table[0][i]}:\t#{table[1][i]}"
124
+ max_length = [max_length, msg.length].max
125
+ messages.append(_colorize(msg, colors[i]))
69
126
  end
127
+
128
+ UI.message('-' * max_length)
129
+ messages.each { |m| UI.message(m) }
130
+ UI.message('-' * max_length)
70
131
  end
71
132
  end
72
133
 
73
134
  # Parses the json output given by [self.run]
74
- def parse_json_output(line, print_errors)
135
+ def parse_json_output(line, print_only_failed)
75
136
  unless line.to_s.strip.empty?
76
137
  output = JSON.parse(line)
77
138
  unless output.kind_of?(Array)
@@ -89,18 +150,19 @@ module Fastlane
89
150
  when 'testDone'
90
151
  test_id = output['testID']
91
152
  test_item = @launched_tests[test_id]
92
- unless test_item.nil?
93
- @launched_tests.delete(test_id)
94
- test_item.mark_as_done(output['result'], nil, nil)
95
- test_item.print(print_errors)
153
+ if !test_item.nil? && test_item.can_print
154
+ was_skipped = output['skipped']
155
+ test_item.mark_as_done(output['result'], was_skipped, nil, nil)
156
+ if was_skipped || !print_only_failed
157
+ test_item.print
158
+ end
96
159
  end
97
160
  when 'error'
98
161
  test_id = output['testID']
99
162
  test_item = @launched_tests[test_id]
100
- unless test_item.nil?
101
- @launched_tests.delete(test_id)
102
- test_item.mark_as_done('error', output['error'], output['stackTrace'])
103
- test_item.print(print_errors)
163
+ if !test_item.nil? && test_item.can_print
164
+ test_item.mark_as_done('error', false, output['error'], output['stackTrace'])
165
+ test_item.print
104
166
  end
105
167
  else
106
168
  # ignored
@@ -115,7 +177,7 @@ module Fastlane
115
177
  end
116
178
 
117
179
  def self.run(params)
118
- TestRunner.new.run(params[:flutter_command], params[:print_errors])
180
+ TestRunner.new.run(params[:flutter_command], params[:print_only_failed], params[:print_stats])
119
181
  end
120
182
 
121
183
  def self.description
@@ -145,12 +207,19 @@ module Fastlane
145
207
  type: String
146
208
  ),
147
209
  FastlaneCore::ConfigItem.new(
148
- key: :print_errors,
210
+ key: :print_only_failed,
149
211
  default_value: true,
150
- description: 'Specifies if it should print the error of failed tests',
212
+ description: 'Specifies if it should only print the failed and the skipped tests',
151
213
  optional: false,
152
214
  type: Boolean
153
- )
215
+ ),
216
+ FastlaneCore::ConfigItem.new(
217
+ key: :print_stats,
218
+ default_value: true,
219
+ description: 'If defined, it will print how many tests were done/skipped/failed',
220
+ optional: false,
221
+ type: Boolean
222
+ ),
154
223
  ]
155
224
  end
156
225
 
@@ -1,5 +1,5 @@
1
1
  module Fastlane
2
2
  module FlutterTests
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastlane-plugin-flutter_tests
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - smaso
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-16 00:00:00.000000000 Z
11
+ date: 2022-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler