ruby_ci 0.2.9 → 0.2.11

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: 2920f9bf7f47278319623491a637407d94b46160479c83d0f94d96d1652ba139
4
- data.tar.gz: 9ae3ab078220371e34526bd53d47e2e57aba01fc39fd49709b00fdb43737027b
3
+ metadata.gz: 1ad35fe30f8c4e72703b0ab13fb95996d76cb291955c2401c863f159e06ebea0
4
+ data.tar.gz: 06e89200e0e82e5f7c4c0dd1c2204c5fa63f13f07505f549799f6cfdbbe94326
5
5
  SHA512:
6
- metadata.gz: eff0af87982d50bec4da005de4179b9cdebfc18cc0b8b2bba776d328f37a6c499695f80e9bb73afd2c3a67742b4f12356f037f1d7f9d1ded8e8021f0bb29d444
7
- data.tar.gz: 308527f4679a5489a7ab5b3c387f841869f128ab3e93c438faf78477233e53b08ad2803445d617bf81ad167e2f9103b996014b9bed29c56a3fda6550e7981901
6
+ metadata.gz: 7dc9c4580c9a8b021546ad8b638583ebb18af22ed695ff54c2f378b839257404eab73a31ce6756d6205ea2135d897abbd219cf3807424eb6458860174b4a7911
7
+ data.tar.gz: 8ce9828e871bc0fc185b6a0040e336f8e520e8b813a73166e0c00d91bf70b9cb401399849d84521674e13e63a5c334b7311e2d173af8ba6fa07cc70092f3b6c5
@@ -10,7 +10,7 @@ module RubyCI
10
10
  end
11
11
 
12
12
  def exit_code(examples_passed=false)
13
- run_time = Time.now - (@rspec_started_at || 1.second.ago)
13
+ run_time = Time.now - (@rspec_started_at || 1.seconds.ago)
14
14
  events = @world.non_example_failure ? [['RSPEC_DRYRUN', { failed_after: run_time, test_env_number: ENV["TEST_ENV_NUMBER"], data: 'error' }]] : [['RSPEC_DRYRUN', { succeed_after: run_time, test_env_number: ENV["TEST_ENV_NUMBER"] }]]
15
15
  STDOUT.puts events.inspect
16
16
  json_events = {
@@ -0,0 +1,247 @@
1
+ # frozen_string_literal: true
2
+ require "stringio"
3
+
4
+ module RubyCI
5
+ class RspecRunFormatter
6
+ RSpec::Core::Formatters.register self,
7
+ :start,
8
+ :example_group_started,
9
+ :example_started,
10
+ :example_passed,
11
+ :example_failed,
12
+ :example_pending,
13
+ :example_group_finished,
14
+ :close
15
+
16
+ def initialize(output)
17
+ @output = output
18
+ @event_output = {}
19
+ @is_failed = false
20
+ @current_path = []
21
+ @current_path_started_at = []
22
+ @max_heap_live_num = 0
23
+ @dup_stdout = STDOUT.clone
24
+ @events = []
25
+
26
+ $stdout = StringIO.new()
27
+
28
+ @log_thread = Thread.new do
29
+ loop do
30
+ sleep 10
31
+ check_heap_live_num
32
+ @should_send_events = true
33
+ end
34
+ end
35
+ end
36
+
37
+ def time_now
38
+ time_frozen? ? Timecop.return { Time.now } : Time.now
39
+ end
40
+
41
+ def time_frozen?
42
+ return unless defined?(Timecop)
43
+ Timecop.frozen?
44
+ end
45
+
46
+ def rspec_runner_index
47
+ ENV["TEST_ENV_NUMBER"]
48
+ end
49
+
50
+ def send_events
51
+ @should_send_events = false
52
+
53
+ if @events.length > 0
54
+ json_events = {
55
+ build_id: RubyCI.configuration.orig_build_id,
56
+ compressed_data: Base64.strict_encode64(Zlib::Deflate.deflate(JSON.fast_generate(@events), 9)),
57
+ }
58
+
59
+ RubyCI.send_events(json_events)
60
+
61
+ @events = []
62
+ end
63
+ end
64
+
65
+ def check_heap_live_num
66
+ @max_heap_live_num = [@max_heap_live_num, GC.stat[:heap_live_slots] || GC.stat[:heap_live_num]].max
67
+ end
68
+
69
+ def passed?
70
+ !@is_failed
71
+ end
72
+
73
+ def start(start_notification)
74
+ @output.print "Starting rspec run"
75
+ # $stderr = $stdout
76
+
77
+ data = {
78
+ load_time: start_notification.load_time,
79
+ example_count: start_notification.count,
80
+ started_at: time_now.to_s
81
+ }
82
+
83
+ return if running_only_failed? ||
84
+ running_gem_or_engine? ||
85
+ ENV["EXTRA_SLOWER_RUN"]
86
+
87
+ msg(:start, data)
88
+ end
89
+
90
+ def close(null_notification)
91
+ @output.print "Finished rspec run"
92
+ # check_heap_live_num
93
+ msg(:gc_stat, GC.stat.merge(max_heap_live_num: @max_heap_live_num))
94
+ unless running_only_failed? || ENV["EXTRA_SLOWER_RUN"] || running_gem_or_engine?
95
+ msg(:close, {final_output: get_output})
96
+ end
97
+ send_events
98
+ $stdout = @dup_stdout
99
+ end
100
+
101
+ def example_group_started(group_notification)
102
+ metadata = group_notification.group.metadata
103
+ @current_path_started_at << time_now
104
+
105
+ if @current_path.size == 0
106
+ @example_failed_index = 0
107
+ file_path = metadata[:file_path].gsub("./".freeze, "".freeze)
108
+ file_path = [ENV["DIR_PREFIX"], file_path].join("/") if ENV["DIR_PREFIX"]
109
+ @current_path << file_path
110
+ end
111
+
112
+ @current_path << id(metadata)
113
+
114
+ msg(:group_started, [
115
+ path_with_file(group_notification.group),
116
+ {
117
+ line_number: metadata[:line_number],
118
+ description: metadata[:description],
119
+ }
120
+ ])
121
+ end
122
+
123
+ def example_started(example_notification)
124
+ @output_before = get_output
125
+ end
126
+
127
+ def example_passed(example_notification)
128
+ metadata = example_notification.example.metadata
129
+ broadcast_example_finished(serialize_example(metadata, "passed".freeze), example_notification.example)
130
+ @output.print RSpec::Core::Formatters::ConsoleCodes.wrap('.', :success)
131
+ end
132
+
133
+ def example_failed(example_notification)
134
+ @example_failed_index += 1
135
+ metadata = example_notification.example.metadata
136
+ fully_formatted = example_notification.fully_formatted(@example_failed_index, ::RSpec::Core::Formatters::ConsoleCodes)
137
+
138
+ broadcast_example_finished(
139
+ serialize_example(metadata, "failed".freeze, fully_formatted),
140
+ example_notification.example
141
+ )
142
+ @output.print RSpec::Core::Formatters::ConsoleCodes.wrap('F', :failure)
143
+ end
144
+
145
+ def example_pending(example_notification)
146
+ metadata = example_notification.example.metadata
147
+ broadcast_example_finished(
148
+ serialize_example(metadata, "pending".freeze),
149
+ example_notification.example
150
+ )
151
+ @output.print RSpec::Core::Formatters::ConsoleCodes.wrap('*', :pending)
152
+ end
153
+
154
+ def example_group_finished(group_notification)
155
+ run_time = time_now - @current_path_started_at.pop
156
+ if (run_time < 0) || (run_time > 2400)
157
+ run_time = 0.525
158
+ end
159
+ msg(:group_finished, [path_with_file(group_notification.group), {run_time: run_time}])
160
+ # msg(:group_finished, [@current_path.map(&:to_s), {run_time: run_time}])
161
+ @current_path.pop
162
+ @current_path.pop if @current_path.size == 1 # Remove the file_path at the beggining
163
+ end
164
+
165
+ def path_with_file(group)
166
+ file_path = group.parent_groups.last.file_path.gsub("./".freeze, "".freeze)
167
+
168
+ group.metadata[:scoped_id].split(":").unshift(file_path)
169
+ end
170
+
171
+ private
172
+
173
+ def running_gem_or_engine?
174
+ !!ENV["DIR_PREFIX"]
175
+ end
176
+
177
+ def running_only_failed?
178
+ !!ENV["RERUN_FAILED_FILES"]
179
+ end
180
+
181
+ def serialize_example(metadata, status, fully_formatted = nil)
182
+ run_time = metadata[:execution_result].run_time
183
+ if (run_time < 0) || (run_time > 2400)
184
+ run_time = 0.525
185
+ end
186
+
187
+ result = {
188
+ id: id(metadata),
189
+ status: status,
190
+ line_number: metadata[:line_number].to_s,
191
+ description: metadata[:description],
192
+ run_time: run_time,
193
+ fully_formatted: fully_formatted,
194
+ scoped_id: metadata[:scoped_id],
195
+ }.compact
196
+
197
+ result[:gem_or_engine] = true if running_gem_or_engine?
198
+
199
+ if running_only_failed?
200
+ result[:reruned] = true
201
+ elsif status == "failed" && !running_gem_or_engine?
202
+ File.write('tmp/rspec_failures', "#{@current_path.first}[#{metadata[:scoped_id]}]", mode: 'a+')
203
+ end
204
+
205
+ if status == "failed"
206
+ img_path = metadata.dig(:screenshot, :image) ||
207
+ fully_formatted&.scan(/\[Screenshot Image\]: (.*)$/).flatten.first&.strip&.chomp ||
208
+ fully_formatted&.scan(/\[Screenshot\]: (.*)$/).flatten.first&.strip&.chomp
209
+
210
+ if img_path && File.exist?(img_path)
211
+ STDOUT.puts "SCREENSHOT!"
212
+ result[:screenshots_base64] ||= []
213
+ result[:screenshots_base64] << Base64.strict_encode64(File.read(img_path))
214
+ end
215
+ end
216
+ @last_example_finished_at = time_now
217
+ # TODO annalyze this: run_time: metadata[:execution_result].run_time,
218
+ result
219
+ end
220
+
221
+ def msg(event, data)
222
+ @events << ["rspec_#{event}".upcase, [rspec_runner_index, data]]
223
+ end
224
+
225
+ def id(metadata)
226
+ metadata[:scoped_id].split(":").last || raise("No scoped id")
227
+ end
228
+
229
+ def broadcast_example_finished(data, example)
230
+ msg(:example_finished, [
231
+ path_with_file(example.example_group),
232
+ data.merge(output_inside: get_output, output_before: @output_before)
233
+ ])
234
+
235
+ send_events if @should_send_events
236
+ end
237
+
238
+ def get_output
239
+ return if $stdout.pos == 0
240
+ $stdout.rewind
241
+ res = $stdout.read
242
+ $stdout.flush
243
+ $stdout.rewind
244
+ res
245
+ end
246
+ end
247
+ end
@@ -88,7 +88,7 @@ module RubyCI
88
88
  end
89
89
 
90
90
  def exit_code(examples_passed=false)
91
- run_time = Time.now - (@rspec_started_at || 1.second.ago)
91
+ run_time = Time.now - (@rspec_started_at || 1.seconds.ago)
92
92
  events = @world.non_example_failure ? [['RSPEC_RUN', { failed_after: run_time, test_env_number: ENV["TEST_ENV_NUMBER"] }]] : [['RSPEC_RUN', { succeed_after: run_time, test_env_number: ENV["TEST_ENV_NUMBER"] }]]
93
93
  json_events = {
94
94
  build_id: RubyCI.configuration.orig_build_id,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubyCI
4
- VERSION = "0.2.9"
4
+ VERSION = "0.2.11"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_ci
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.9
4
+ version: 0.2.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ale ∴
@@ -128,6 +128,7 @@ files:
128
128
  - lib/ruby_ci/extract_definitions.rb
129
129
  - lib/ruby_ci/rspec_dryrun_formatter.rb
130
130
  - lib/ruby_ci/rspec_formatter.rb
131
+ - lib/ruby_ci/rspec_run_formatter.rb
131
132
  - lib/ruby_ci/ruby_critic/cli/application.rb
132
133
  - lib/ruby_ci/runner_prepend.rb
133
134
  - lib/ruby_ci/simple_cov.rb