Class: DiffTest::TestSuiteExecution

Inherits:
Object
  • Object
show all
Defined in:
lib/diff_test/test_suite_execution.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tests:) ⇒ TestSuiteExecution

Returns a new instance of TestSuiteExecution.



6
7
8
9
# File 'lib/diff_test/test_suite_execution.rb', line 6

def initialize(tests:)
  @tests = tests.compact
  @test_executions = []
end

Class Method Details

.currentObject



65
66
67
# File 'lib/diff_test/test_suite_execution.rb', line 65

def self.current
  @current
end

.current=(value) ⇒ Object



69
70
71
# File 'lib/diff_test/test_suite_execution.rb', line 69

def self.current=(value)
  @current = value
end

.find_or_create(tests) ⇒ Object



73
74
75
76
77
78
# File 'lib/diff_test/test_suite_execution.rb', line 73

def self.find_or_create(tests)
  self.current ||= new(tests:)

  self.current.find_or_create_on_server
  self.current
end

Instance Method Details

#ensure_application_eager_loaded!Object



42
43
44
45
46
# File 'lib/diff_test/test_suite_execution.rb', line 42

def ensure_application_eager_loaded!
  return if @eager_loaded
  @eager_loaded = true
  ::Rails.application.eager_load! if defined?(::Rails) && ::Rails.respond_to?(:application)
end

#find_or_create_on_serverObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/diff_test/test_suite_execution.rb', line 11

def find_or_create_on_server
  if ENV['DIFF_TEST_SKIP_API']
    return @id = 'fake-test-suite-execution-id'
  elsif ENV['DIFF_TEST_SKIP_API_CALL']
    payload.to_json
    return @id = 'fake-test-suite-execution-id'
  end

  response = DiffTest::Helper.bm('create test suite executions') do
    DiffTest::ApiClient.post("/test_suite_executions", body: payload)
  end

  raise "Failed to create test suite execution: #{response.inspect}" unless response.success?
  raise "Failed to create test suite execution: #{response.inspect}" unless response['id'].present?

  @id = response['id']
end

#js_version_hashObject



61
62
63
# File 'lib/diff_test/test_suite_execution.rb', line 61

def js_version_hash
  @js_version_hash ||= DiffTest::JsVersionHashComputer.compute
end

#previous_compatible_test_executionsObject



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/diff_test/test_suite_execution.rb', line 29

def previous_compatible_test_executions
  if ENV['DIFF_TEST_SKIP_API']
    return {}
  elsif ENV['DIFF_TEST_SKIP_API_CALL']
    { tests: @tests }.to_json
    return {}
  end

  DiffTest::Helper.bm('previous compatible test executions') do
    DiffTest::ApiClient.post("/test_suite_executions/#{id}/previous_compatible_test_executions", body: { tests: @tests })
  end
end

#record_test_execution(test_execution) ⇒ Object



49
50
51
# File 'lib/diff_test/test_suite_execution.rb', line 49

def record_test_execution(test_execution)
  @test_executions << test_execution
end

#saveObject



57
58
59
# File 'lib/diff_test/test_suite_execution.rb', line 57

def save
  save_test_execution_results_on_server if valid?
end

#valid?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/diff_test/test_suite_execution.rb', line 53

def valid?
  @id.present?
end