diff_test 0.8.4 → 0.8.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 194963612fbe79dd0506ee1d92e500fca33e8aacf6b5fe38b00cb91741a64367
4
- data.tar.gz: 7a8f7a9a4e516cff513ae27247397ac40d35ed697ca5a483aed94a75d60bc668
3
+ metadata.gz: 71eb34b2f03e6cfb5c88f0382645ab9991273650ab54bf33ca985dd3d244b631
4
+ data.tar.gz: 140bc0788f6bb66aa6bf75d1d55934feeba868006593ff4b134d75633900a376
5
5
  SHA512:
6
- metadata.gz: 55bf9771f23900a6f3c0800e090db8dc7884acf9e0432573e25a4e4f75cb5adb20af9f750bb0c04e8a765f91503c4fa10ec559dbb34b77d2802e1a2ffea9c560
7
- data.tar.gz: 6ee7fb4f979941883644d0bf27c29832b613c4e90c66f962beaffe0282b1c9d80761e73009d7da0f823f017c44d8d665ec0a9015222986da1bae53e7c019b03e
6
+ metadata.gz: 0160b17c695801c363ab06aa98844ac586238df47db23f4fc25a628f49081e2fa76b7abafb49dacf447ad2db3960418d6dd5827442ee4da60da700c76bf77eca
7
+ data.tar.gz: 707a6088a90723c80715002f2d27cbc87f5833398c4d16b695213efb3af9feaafc8166f68d6cf867d94286e3dacb6d6330701fe8973b5383ee333c053aab0bdd
@@ -0,0 +1,11 @@
1
+ class BasicObject
2
+ def __basic_object?
3
+ true
4
+ end
5
+ end
6
+
7
+ module Kernel
8
+ def __basic_object?
9
+ false
10
+ end
11
+ end
@@ -66,5 +66,13 @@ module DiffTest
66
66
  def committer_email
67
67
  @committer_email ||= `git log -1 --pretty=%ae`.strip
68
68
  end
69
+
70
+ def bm(*name, &block)
71
+ puts "Starting #{name.join(' ')}------------"
72
+ start = Time.now
73
+ result = yield
74
+ puts "Finished #{name.join(' ')} in #{(Time.now - start).round(2)}s------------"
75
+ result
76
+ end
69
77
  end
70
78
  end
@@ -17,7 +17,11 @@ module DiffTest
17
17
 
18
18
  def save_payload
19
19
  impacted_files.each_with_object({}) do |file_path, payload|
20
- payload[file_path] = FileHashComputer.compute(file_path)
20
+ begin
21
+ payload[file_path] = FileHashComputer.compute(file_path)
22
+ rescue Errno::ENOENT
23
+ nil
24
+ end
21
25
  end
22
26
  end
23
27
 
@@ -7,6 +7,17 @@ module DiffTest
7
7
  end
8
8
 
9
9
  module InstanceMethods
10
+ def relative_test_file_path(runnable_class, runnable_method)
11
+ value = Helper.relative_const_source_path_from_project_root(runnable_class.name) rescue nil
12
+
13
+ unbound_method = runnable_class.instance_method(runnable_method) if runnable_method
14
+ value ||= Helper.relative_path_from_project_root(unbound_method.source_location.first) if unbound_method
15
+
16
+ value
17
+ rescue
18
+ nil
19
+ end
20
+
10
21
  def run
11
22
  return super unless DiffTest.configuration.enabled?
12
23
 
@@ -15,7 +26,7 @@ module DiffTest
15
26
  tests = ::Minitest::Test.runnables.flat_map do |runnable|
16
27
  next if runnable.runnable_methods.empty?
17
28
 
18
- test_file_path = Helper.relative_const_source_path_from_project_root(runnable.name) rescue nil
29
+ test_file_path = relative_test_file_path(runnable, runnable.runnable_methods.first)
19
30
  next unless test_file_path
20
31
 
21
32
  runnable.runnable_methods.map do |test_name|
@@ -39,7 +50,7 @@ module DiffTest
39
50
  return super unless DiffTest::TestSuiteExecution.current.valid?
40
51
 
41
52
  begin
42
- test_file_path = Helper.relative_const_source_path_from_project_root(self.class.name) rescue nil
53
+ test_file_path = relative_test_file_path(self.class, self.name)
43
54
  return super if test_file_path.nil?
44
55
  test_name = self.name
45
56
 
@@ -13,7 +13,7 @@ module DiffTest
13
13
  end
14
14
 
15
15
  def loaded?
16
- supported? && defined?(::Rails)
16
+ supported? && defined?(::Rails) && defined?(::Rails::Railtie)
17
17
  end
18
18
 
19
19
  def integrate
@@ -23,8 +23,8 @@ module DiffTest
23
23
  test: id,
24
24
  result: @result,
25
25
  runtime_ms: runtime_ms,
26
- impacted_files: @impacted_file_tracker.save_payload,
27
- }
26
+ impacted_files: (@impacted_file_tracker.save_payload if passed?),
27
+ }.compact
28
28
  end
29
29
 
30
30
  def id
@@ -62,6 +62,10 @@ module DiffTest
62
62
  @result = :failed
63
63
  end
64
64
 
65
+ def passed?
66
+ @result == :passed
67
+ end
68
+
65
69
  def runtime_ms
66
70
  return 0 if @stopped_at.nil? || @started_at.nil?
67
71
  (@stopped_at - @started_at) * 1000
@@ -9,20 +9,40 @@ module DiffTest
9
9
  end
10
10
 
11
11
  def find_or_create_on_server
12
- response = DiffTest::ApiClient.post("/test_suite_executions", body: payload)
12
+ if ENV['DIFF_TEST_SKIP_API']
13
+ return @id = 'fake-test-suite-execution-id'
14
+ elsif ENV['DIFF_TEST_SKIP_API_CALL']
15
+ payload.to_json
16
+ return @id = 'fake-test-suite-execution-id'
17
+ end
18
+
19
+ response = DiffTest::Helper.bm('create test suite executions') do
20
+ DiffTest::ApiClient.post("/test_suite_executions", body: payload)
21
+ end
22
+
13
23
  raise "Failed to create test suite execution: #{response.inspect}" unless response.success?
14
24
  raise "Failed to create test suite execution: #{response.inspect}" unless response['id'].present?
25
+
15
26
  @id = response['id']
16
27
  end
17
28
 
18
29
  def previous_compatible_test_executions
19
- DiffTest::ApiClient.post("/test_suite_executions/#{id}/previous_compatible_test_executions", body: { tests: @tests })
30
+ if ENV['DIFF_TEST_SKIP_API']
31
+ return {}
32
+ elsif ENV['DIFF_TEST_SKIP_API_CALL']
33
+ { tests: @tests }.to_json
34
+ return {}
35
+ end
36
+
37
+ DiffTest::Helper.bm('previous compatible test executions') do
38
+ DiffTest::ApiClient.post("/test_suite_executions/#{id}/previous_compatible_test_executions", body: { tests: @tests })
39
+ end
20
40
  end
21
41
 
22
42
  def ensure_application_eager_loaded!
23
43
  return if @eager_loaded
24
44
  @eager_loaded = true
25
- ::Rails.application.eager_load! if defined?(::Rails)
45
+ ::Rails.application.eager_load! if defined?(::Rails) && ::Rails.respond_to?(:application)
26
46
  end
27
47
 
28
48
 
@@ -64,9 +84,42 @@ module DiffTest
64
84
  end
65
85
 
66
86
  def save_test_execution_results_on_server
87
+ if ENV['DIFF_TEST_SKIP_API']
88
+ return
89
+ elsif ENV['DIFF_TEST_SKIP_API_CALL']
90
+ @test_executions.map(&:save_payload).to_json
91
+ return
92
+ end
93
+
67
94
  raise "Expected to have at least one test execution" if @test_executions.empty?
68
95
 
69
- response = DiffTest::ApiClient.post("/test_suite_executions/#{id}/test_executions/bulk_create", body: { test_executions: @test_executions.map(&:save_payload) })
96
+ test_executions = @test_executions.map(&:save_payload)
97
+
98
+ impacted_file_hash_and_id_by_path = {}
99
+
100
+ test_executions.each do |test_execution|
101
+ next unless test_execution[:impacted_files]
102
+
103
+ test_execution[:impacted_files].each do |file_path, hash|
104
+ unless impacted_file_hash_and_id_by_path[file_path]
105
+ impacted_file_hash_and_id_by_path[file_path] = [hash, impacted_file_hash_and_id_by_path.size]
106
+ end
107
+ end
108
+
109
+ test_execution[:impacted_file_ids] = test_execution[:impacted_files].keys.map { |file_path| impacted_file_hash_and_id_by_path[file_path][1] }
110
+ test_execution[:impacted_files] = nil
111
+ end
112
+
113
+ impacted_file_path_and_hash_by_id = impacted_file_hash_and_id_by_path.map do |file_path, (hash, id)|
114
+ [id, [file_path, hash]]
115
+ end.to_h
116
+
117
+ DiffTest::Helper.bm('bulk create test executions') do
118
+ DiffTest::ApiClient.post("/test_suite_executions/#{id}/test_executions/bulk_create", body: {
119
+ impacted_file_path_and_hash_by_id: impacted_file_path_and_hash_by_id,
120
+ test_executions: test_executions
121
+ })
122
+ end
70
123
  end
71
124
 
72
125
  def payload
@@ -17,7 +17,11 @@ module DiffTest
17
17
 
18
18
  unless @seen_constants.include?(constant)
19
19
  @seen_constants.add(constant)
20
- constant = constant.attached_object if constant&.singleton_class?
20
+
21
+ if constant&.singleton_class?
22
+ constant = constant.attached_object if constant&.singleton_class?
23
+ next if constant.__basic_object?
24
+ end
21
25
 
22
26
  path = @@location_by_constant[constant]
23
27
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DiffTest
4
- VERSION = "0.8.4"
4
+ VERSION = "0.8.5"
5
5
  end
data/lib/diff_test.rb CHANGED
@@ -31,6 +31,7 @@ module DiffTest
31
31
  def self.integrate!
32
32
  return unless configuration.integratable?
33
33
 
34
+ require_relative 'diff_test/core_ext'
34
35
  DiffTest::Integrations::RailsJs::Integration.instance.integrate_if_ready
35
36
  DiffTest::Integrations::ActiveRecord::Integration.instance.integrate_if_ready
36
37
  DiffTest::Integrations::Minitest::Integration.instance.integrate_if_ready
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diff_test
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.4
4
+ version: 0.8.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Owais
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-04-19 00:00:00.000000000 Z
11
+ date: 2025-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -53,6 +53,7 @@ files:
53
53
  - lib/diff_test.rb
54
54
  - lib/diff_test/api_client.rb
55
55
  - lib/diff_test/configuration.rb
56
+ - lib/diff_test/core_ext.rb
56
57
  - lib/diff_test/file_hash_computer.rb
57
58
  - lib/diff_test/helper.rb
58
59
  - lib/diff_test/impacted_file_tracker.rb