Sha256: ba7fde6f527d309dae717e7ece3b5b5be759627156b91d603c2f1927c92beedc

Contents?: true

Size: 1.5 KB

Versions: 20

Compression:

Stored size: 1.5 KB

Contents

# frozen_string_literal: true
require 'minitest/reporters'

module Minitest
  module Queue
    class BuildStatusRecorder < Minitest::Reporters::BaseReporter
      COUNTERS = %w(
        assertions
        errors
        failures
        skips
        requeues
        total_time
      ).freeze

      class << self
        attr_accessor :failure_formatter
      end
      self.failure_formatter = FailureFormatter

      attr_accessor :requeues

      def initialize(build:, **options)
        super(options)

        @build = build
        self.failures = 0
        self.errors = 0
        self.skips = 0
        self.requeues = 0
      end

      def report
        # noop
      end

      def record(test)
        super

        self.total_time = Minitest.clock_time - start_time
        if test.requeued?
          self.requeues += 1
        elsif test.skipped?
          self.skips += 1
        elsif test.error?
          self.errors += 1
        elsif test.failure
          self.failures += 1
        end

        stats = COUNTERS.zip(COUNTERS.map { |c| send(c) }).to_h
        if (test.failure || test.error?) && !test.skipped?
          build.record_error("#{test.klass}##{test.name}", dump(test), stats: stats)
        else
          build.record_success("#{test.klass}##{test.name}", stats: stats, skip_flaky_record: test.skipped?)
        end
      end

      private

      def dump(test)
        ErrorReport.new(self.class.failure_formatter.new(test).to_h).dump
      end

      attr_reader :build
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
ci-queue-0.58.0 lib/minitest/queue/build_status_recorder.rb
ci-queue-0.57.0 lib/minitest/queue/build_status_recorder.rb
ci-queue-0.56.0 lib/minitest/queue/build_status_recorder.rb
ci-queue-0.55.0 lib/minitest/queue/build_status_recorder.rb
ci-queue-0.52.0 lib/minitest/queue/build_status_recorder.rb
ci-queue-0.51.0 lib/minitest/queue/build_status_recorder.rb
ci-queue-0.50.0 lib/minitest/queue/build_status_recorder.rb
ci-queue-0.49.0 lib/minitest/queue/build_status_recorder.rb
ci-queue-0.48.0 lib/minitest/queue/build_status_recorder.rb
ci-queue-0.47.0 lib/minitest/queue/build_status_recorder.rb
ci-queue-0.46.0 lib/minitest/queue/build_status_recorder.rb
ci-queue-0.45.0 lib/minitest/queue/build_status_recorder.rb
ci-queue-0.44.0 lib/minitest/queue/build_status_recorder.rb
ci-queue-0.43.0 lib/minitest/queue/build_status_recorder.rb
ci-queue-0.42.0 lib/minitest/queue/build_status_recorder.rb
ci-queue-0.41.0 lib/minitest/queue/build_status_recorder.rb
ci-queue-0.40.0 lib/minitest/queue/build_status_recorder.rb
ci-queue-0.39.0 lib/minitest/queue/build_status_recorder.rb
ci-queue-0.38.0 lib/minitest/queue/build_status_recorder.rb
ci-queue-0.37.0 lib/minitest/queue/build_status_recorder.rb