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 +4 -4
- data/lib/diff_test/core_ext.rb +11 -0
- data/lib/diff_test/helper.rb +8 -0
- data/lib/diff_test/impacted_file_tracker.rb +5 -1
- data/lib/diff_test/integrations/minitest/lifecycle.rb +13 -2
- data/lib/diff_test/integrations/rails_js/integration.rb +1 -1
- data/lib/diff_test/test_execution.rb +6 -2
- data/lib/diff_test/test_suite_execution.rb +57 -4
- data/lib/diff_test/trackers/ruby_file.rb +5 -1
- data/lib/diff_test/version.rb +1 -1
- data/lib/diff_test.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71eb34b2f03e6cfb5c88f0382645ab9991273650ab54bf33ca985dd3d244b631
|
4
|
+
data.tar.gz: 140bc0788f6bb66aa6bf75d1d55934feeba868006593ff4b134d75633900a376
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0160b17c695801c363ab06aa98844ac586238df47db23f4fc25a628f49081e2fa76b7abafb49dacf447ad2db3960418d6dd5827442ee4da60da700c76bf77eca
|
7
|
+
data.tar.gz: 707a6088a90723c80715002f2d27cbc87f5833398c4d16b695213efb3af9feaafc8166f68d6cf867d94286e3dacb6d6330701fe8973b5383ee333c053aab0bdd
|
data/lib/diff_test/helper.rb
CHANGED
@@ -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
|
-
|
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 =
|
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 =
|
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
|
|
@@ -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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
|
data/lib/diff_test/version.rb
CHANGED
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
|
+
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-
|
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
|