Class: FeatureMap::Private::TestPyramid::Mapper

Inherits:
Object
  • Object
show all
Defined in:
lib/feature_map/private/test_pyramid/mapper.rb

Class Method Summary collapse

Class Method Details

.examples_by_feature(examples_path, assignments) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/feature_map/private/test_pyramid/mapper.rb', line 6

def examples_by_feature(examples_path, assignments)
  return {} if examples_path =~ /.skip$/

  examples_file = File.read(examples_path)
  normalized_assignments = assignments.transform_values { |feature| feature['files'] || [] }

  case examples_path
  when /\.rspec$/
    examples = JSON.parse(examples_file)&.fetch('examples', [])
    TestPyramid::RspecMapper.map_tests_by_assignment(
      examples,
      normalized_assignments
    )
  when /\.jest$/
    examples = JSON.parse(examples_file)&.fetch('testResults', [])
    TestPyramid::JestMapper.map_tests_by_assignment(
      examples,
      normalized_assignments
    )
  else
    raise "Unhandled filetype for unit path: #{examples_path}"
  end
end