Module: Minitest

Defined in:
lib/minitest/fastci_plugin.rb,
lib/minitest/reporters/fastci_reporter.rb

Defined Under Namespace

Modules: Reporters

Class Method Summary collapse

Class Method Details

.plugin_fastci_init(options) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/minitest/fastci_plugin.rb', line 4

def self.plugin_fastci_init(options)
  if ENV['FAST_CI_SECRET_KEY'].present?
    FastCI.configure { |c| c.run_key = "minitest" }
    Minitest.class_eval do
      class<< self
        def __run reporter, options
          suites = Minitest::Runnable.runnables
          tests = {}
          suit_paths = {}
          suites.each do |suite|
            path = "./#{Object.const_source_location(suite.name)[0].gsub(Regexp.new("^#{::Rails.root}/"), '')}"
            next if path.starts_with?('./vendor/bundle')
            tests[path] ||= { run_time: 0.0, file_status: 'pending', test_count: suite.runnable_methods.count, test_counters: { failed: 0, passed: 0, pending: 0 }, '1' => {} }
            suit_paths[path] = suite
            suite.runnable_methods.each_with_index do |method, ix|
              description = method.split(':')[1..-1].join(':')
              tests[path]['1'][(ix + 1).to_s] ||= { status: 'pending', description: description }
            end
          end
    
          FastCI.minitest_ws.on(:enq_request) do
            tests
          end
    
          FastCI.minitest_ws.on(:deq) do |api_tests|
            run_suites = api_tests.map do |test_path|
              suit_paths[test_path]
            end
            parallel, serial = run_suites.partition { |s| s.test_order == :parallel }

            serial.map { |suite| suite.run reporter, options }
            parallel.map { |suite| suite.run reporter, options }
            
            fc_reporter = reporter.report.select {|r| r.class == Minitest::Reporters::FastCIReporter }.first
            fc_reporter.test_results
          end
          FastCI.minitest_await
        end
      end
    end

    Minitest.reporter << Minitest::Reporters::FastCIReporter.new
  end
end