@@ -82,6 +82,12 @@ class DangerXcodeSummary < Plugin
8282 # @return [Boolean]
8383 attr_accessor :strict
8484
85+ # Defines if parallelized test runs from the same target should be collapsed into one message.
86+ # Defaults to `false`
87+ # @param [Boolean] value
88+ # @return [Boolean]
89+ attr_accessor :collapse_parallelized_tests
90+
8591 # rubocop:disable Lint/DuplicateMethods
8692 def project_root
8793 root = @project_root || Dir . pwd
@@ -121,6 +127,10 @@ def strict
121127 @strict . nil? || @strict
122128 end
123129
130+ def collapse_parallelized_tests
131+ @collapse_parallelized_tests || false
132+ end
133+
124134 # Pick a Dangerfile plugin for a chosen request_source and cache it
125135 # based on https://github.com/danger/danger/blob/master/lib/danger/plugin_support/plugin.rb#L31
126136 #
@@ -211,26 +221,63 @@ def sort_and_log_warnings(all_warnings)
211221
212222 def messages ( xcode_summary )
213223 if test_summary
214- test_messages = xcode_summary . action_test_plan_summaries . map do |test_plan_summaries |
224+ test_runs = xcode_summary . action_test_plan_summaries . map do |test_plan_summaries |
215225 test_plan_summaries . summaries . map do |summary |
216226 summary . testable_summaries . map do |test_summary |
217227 test_summary . tests . filter_map do |action_test_object |
218228 if action_test_object . instance_of? XCResult ::ActionTestSummaryGroup
219229 subtests = action_test_object . all_subtests
220230 subtests_duration = subtests . map ( &:duration ) . sum
221- test_text_infix = subtests . count == 1 ? 'test' : 'tests'
231+
222232 failed_tests_count = subtests . reject { |test | test . test_status == 'Success' } . count
223233 expected_failed_tests_count = subtests . select { |test | test . test_status == 'Expected Failure' } . count
224234
225- "#{ test_summary . target_name } : Executed #{ subtests . count } #{ test_text_infix } , " \
226- "with #{ failed_tests_count } failures (#{ expected_failed_tests_count } expected) in " \
227- "#{ subtests_duration . round ( 3 ) } (#{ action_test_object . duration . round ( 3 ) } ) seconds"
235+ {
236+ target_name : test_summary . target_name ,
237+ test_count : subtests . count ,
238+ failed_tests_count : failed_tests_count ,
239+ expected_failed_tests_count : expected_failed_tests_count ,
240+ tests_duration : subtests_duration ,
241+ action_duration : action_test_object . duration
242+ }
228243 end
229244 end
230245 end
231246 end
232247 end
233- test_messages . flatten . uniq . compact . map ( &:strip )
248+
249+ flattened_test_runs = test_runs . flatten . uniq . compact
250+
251+ if collapse_parallelized_tests
252+ test_runs_by_target = flattened_test_runs . group_by { |test_run | test_run [ :target_name ] }
253+ flattened_test_runs = test_runs_by_target . map do |target_name , test_runs |
254+ test_runs . reduce do |acc , test_run |
255+ acc . merge (
256+ test_count : acc [ :test_count ] + test_run [ :test_count ] ,
257+ failed_tests_count : acc [ :failed_tests_count ] + test_run [ :failed_tests_count ] ,
258+ expected_failed_tests_count : acc [ :expected_failed_tests_count ] + test_run [ :expected_failed_tests_count ] ,
259+ tests_duration : acc [ :tests_duration ] + test_run [ :tests_duration ] ,
260+ action_duration : acc [ :action_duration ] + test_run [ :action_duration ]
261+ )
262+ end
263+ end
264+ end
265+
266+ test_messages = flattened_test_runs . map do |test_run |
267+ target_name = test_run [ :target_name ]
268+ test_count = test_run [ :test_count ]
269+ failed_tests_count = test_run [ :failed_tests_count ]
270+ expected_failed_tests_count = test_run [ :expected_failed_tests_count ]
271+ subtests_duration = test_run [ :tests_duration ]
272+ action_duration = test_run [ :action_duration ]
273+ test_text_infix = test_count == 1 ? 'test' : 'tests'
274+
275+ "#{ target_name } : Executed #{ test_count } #{ test_text_infix } , " \
276+ "with #{ failed_tests_count } failures (#{ expected_failed_tests_count } expected) in " \
277+ "#{ subtests_duration . round ( 3 ) } (#{ action_duration . round ( 3 ) } ) seconds"
278+ end
279+
280+ test_messages . map ( &:strip )
234281 else
235282 [ ]
236283 end
0 commit comments