Class: DiffTest::ShouldRunDecider
- Inherits:
-
Object
- Object
- DiffTest::ShouldRunDecider
- Defined in:
- lib/diff_test/should_run_decider.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ ShouldRunDecider
constructor
A new instance of ShouldRunDecider.
- #should_run?(test_id, system_test:) ⇒ Boolean
Constructor Details
#initialize ⇒ ShouldRunDecider
Returns a new instance of ShouldRunDecider.
3 4 5 6 7 8 |
# File 'lib/diff_test/should_run_decider.rb', line 3 def initialize previous_compatible_test_executions = DiffTest::TestSuiteExecution.current.previous_compatible_test_executions @impacted_file_path_by_id = previous_compatible_test_executions['impacted_file_path_by_id'] @test_suite_executions_by_id = previous_compatible_test_executions['test_suite_executions_by_id'] @test_executions_by_test = previous_compatible_test_executions['test_executions_by_test'] end |
Class Method Details
.current ⇒ Object
47 48 49 |
# File 'lib/diff_test/should_run_decider.rb', line 47 def self.current @current ||= DiffTest::ShouldRunDecider.new end |
.should_run?(test_id, system_test:) ⇒ Boolean
51 52 53 |
# File 'lib/diff_test/should_run_decider.rb', line 51 def self.should_run?(test_id, system_test:) current.should_run?(test_id, system_test: system_test) end |
Instance Method Details
#should_run?(test_id, system_test:) ⇒ Boolean
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 |
# File 'lib/diff_test/should_run_decider.rb', line 10 def should_run?(test_id, system_test:) return { should_run: true } unless @test_executions_by_test previous_test_executions = @test_executions_by_test[test_id] || [] previous_runtime_ms = nil # If there are any previous test executions run whose impacted files are the same as now # Assume its safe to skip has_previous_execution_with_no_impacted_changes = previous_test_executions.any? do |previous_test_execution| hashes_match = previous_test_execution['test_execution_impacted_files'].all? do |test_execution_impacted_file| impacted_file_id = test_execution_impacted_file['impacted_file_id'].to_s file_hash = test_execution_impacted_file['file_hash'].to_s impacted_file_path = @impacted_file_path_by_id[impacted_file_id] DiffTest::FileHashComputer.compute_relative(impacted_file_path) == file_hash end next false unless hashes_match previous_runtime_ms = previous_test_execution['runtime_ms'] next true unless system_test test_suite_execution = @test_suite_executions_by_id[previous_test_execution['test_suite_execution_id'].to_s] next true if test_suite_execution['all_js_files_annotated'] next true if test_suite_execution['js_version_hash'] == DiffTest::TestSuiteExecution.current.js_version_hash false end return { should_run: true } if ENV['DIFF_TEST_ALWAYS_RUN'] == '1' should_run = !has_previous_execution_with_no_impacted_changes { should_run:, previous_runtime_ms:, } end |