Module: AffectedTests

Defined in:
lib/affected_tests.rb,
lib/affected_tests/differ.rb,
lib/affected_tests/version.rb,
lib/affected_tests/map_merger.rb,
lib/affected_tests/engine/calleree.rb,
lib/affected_tests/engine/coverage.rb,
lib/affected_tests/engine/rotoscope.rb

Defined Under Namespace

Modules: Differ, Engine, MapMerger Classes: Configuration

Constant Summary collapse

VERSION =
"0.8.0"

Class Method Summary collapse

Class Method Details

.build_revisionObject



86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/affected_tests.rb', line 86

def build_revision
  if defined? Rails
    path = Rails.root.join("REVISION")
    if path.exist?
      path.read.chomp
    else
      "UNKNOWN"
    end
  else
    "UNKNOWN"
  end
end

.checkpoint(target_test_path) ⇒ Object



75
76
77
# File 'lib/affected_tests.rb', line 75

def checkpoint(target_test_path)
  @engine.checkpoint(target_test_path)
end

.dumpObject



79
80
81
82
83
84
# File 'lib/affected_tests.rb', line 79

def dump
  data = { revision: @config.revision || build_revision, map: @engine.dump }
  File.write(@config.output_path, JSON.dump(data))
ensure
  @engine.stop_trace if @engine.tracing?
end

.select_engine(engine) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/affected_tests.rb', line 48

def select_engine(engine)
  case engine
  when :rotoscope
    require "rotoscope"
    require "affected_tests/engine/rotoscope"
    AffectedTests::Engine::Rotoscope
  when :calleree
    require "calleree"
    require "affected_tests/engine/calleree"
    AffectedTests::Engine::Calleree
  when :coverage
    require "coverage"
    require "affected_tests/engine/coverage"
    AffectedTests::Engine::Coverage
  else
    raise "Unknown engine: #{engine}"
  end
end

.setup(engine: :rotoscope, project_path:, test_dir_path:, output_path:, revision: nil) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# File 'lib/affected_tests.rb', line 37

def setup(engine: :rotoscope, project_path:, test_dir_path:, output_path:, revision: nil)
  @config = Configuration.new(
    project_path: project_path,
    output_path: output_path,
    revision: revision,
    test_dir_path: test_dir_path
  )

  @engine = select_engine(engine).new(@config)
end

.start_traceObject



67
68
69
# File 'lib/affected_tests.rb', line 67

def start_trace
  @engine.start_trace
end

.stop_traceObject



71
72
73
# File 'lib/affected_tests.rb', line 71

def stop_trace
  @engine.stop_trace
end