lookbook_visual_tester 0.5.2 → 0.5.3
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/CHANGELOG.md +6 -0
- data/README.md +2 -2
- data/lib/lookbook_visual_tester/preview_checker.rb +44 -6
- data/lib/lookbook_visual_tester/runner.rb +2 -0
- data/lib/lookbook_visual_tester/version.rb +1 -1
- data/lib/tasks/lookbook_visual_tester.rake +1 -0
- metadata +1 -2
- data/lib/lookbook_visual_tester/image_comparator.rb +0 -49
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 61d8ae85e5897ffcb0dd53078b753a02cfc118e9cf5990ebbf27b40c5778bc4a
|
|
4
|
+
data.tar.gz: afcd716247590085bf7dbb99c36e146f45a350f349c1c2fda5dad9d7c8441192
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e22889eacb81f638d7ba65ab1e8682d0e1ec7e22903f67b950912ef5f670eb3ec13dca31ba21e52ef6cac3e73ce6da11179a7ec35e37eb44b5392e4f99ac6004
|
|
7
|
+
data.tar.gz: e5f18347bff022b59a7b6504c2a2cd0b64e279b587b9dc92f4a0001f7056cc63e8affa58167799cac8ef2fa434718d973ea6fbd375f54a6697240f5b1bc050bf
|
data/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
# Changelog
|
|
2
|
+
## [0.5.3] - 2026-01-04
|
|
3
|
+
|
|
4
|
+
### Fixed
|
|
5
|
+
- **Deep Check**: `rake lookbook:deep_check` now correctly detects and fails when a preview returns `nil` (implicit rendering) but the corresponding template is missing (`ViewComponent::MissingPreviewTemplateError`).
|
|
6
|
+
- **Deep Check**: `rake lookbook:deep_check` now exits with status 1 if any errors or failures are detected.
|
|
7
|
+
|
|
2
8
|
## [0.5.2] - 2026-01-04
|
|
3
9
|
|
|
4
10
|
### Fixed
|
data/README.md
CHANGED
|
@@ -29,7 +29,7 @@ sudo apt-get install imagemagick xclip
|
|
|
29
29
|
Add to your application's Gemfile:
|
|
30
30
|
```ruby
|
|
31
31
|
group :test do
|
|
32
|
-
gem 'lookbook_visual_tester'
|
|
32
|
+
gem 'lookbook_visual_tester', '~> 0.5.3'
|
|
33
33
|
end
|
|
34
34
|
```
|
|
35
35
|
|
|
@@ -153,7 +153,7 @@ bundle exec rake lookbook:check
|
|
|
153
153
|
```
|
|
154
154
|
|
|
155
155
|
#### Deep Check (Render)
|
|
156
|
-
effectively renders all previews to catch runtime and
|
|
156
|
+
effectively renders all previews to catch runtime errors, missing templates, and other failures. Exits with status 1 if any errors are found.
|
|
157
157
|
```bash
|
|
158
158
|
bundle exec rake lookbook:deep_check
|
|
159
159
|
```
|
|
@@ -131,14 +131,22 @@ module LookbookVisualTester
|
|
|
131
131
|
example_name = example.name
|
|
132
132
|
|
|
133
133
|
begin
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
134
|
+
# Use ViewComponent::Preview logic to get the component to render
|
|
135
|
+
# This handles the case where the method returns nil (implicit template)
|
|
136
|
+
# and returns a component that renders the template.
|
|
137
|
+
if preview_class.respond_to?(:preview_example)
|
|
138
|
+
result = preview_class.preview_example(example_name)
|
|
139
|
+
puts "DEBUG: preview_example('#{example_name}') returned: #{result.inspect} (class: #{result.class})"
|
|
140
|
+
else
|
|
141
|
+
# Fallback for older VC or non-standard setups
|
|
142
|
+
preview_instance = preview_class.new
|
|
143
|
+
unless preview_instance.respond_to?(example_name)
|
|
144
|
+
return CheckResult.new(preview_name: preview.name, example_name: example_name,
|
|
145
|
+
status: :passed)
|
|
146
|
+
end
|
|
147
|
+
result = preview_instance.public_send(example_name)
|
|
138
148
|
end
|
|
139
149
|
|
|
140
|
-
result = preview_instance.public_send(example_name)
|
|
141
|
-
|
|
142
150
|
if result.respond_to?(:render_in)
|
|
143
151
|
# Mock current_user/pundit if needed on the component itself if possible
|
|
144
152
|
# But mainly we render it with a view context
|
|
@@ -157,6 +165,36 @@ module LookbookVisualTester
|
|
|
157
165
|
result.render_in(view_context)
|
|
158
166
|
elsif result.is_a?(String)
|
|
159
167
|
# Rendered string, good.
|
|
168
|
+
elsif result.nil?
|
|
169
|
+
# If result is nil, it implies an implicit template rendering.
|
|
170
|
+
# We need to verify that the template exists.
|
|
171
|
+
|
|
172
|
+
# Try to find the template file based on conventions
|
|
173
|
+
# Convention: preview_file_dir/preview_file_name/example_name.html.erb
|
|
174
|
+
|
|
175
|
+
# We need the preview file path. Lookbook::Preview might not expose it easily
|
|
176
|
+
# but the class might have source_location.
|
|
177
|
+
|
|
178
|
+
method = preview_class.instance_method(example_name)
|
|
179
|
+
source_file = method.source_location&.first
|
|
180
|
+
|
|
181
|
+
found_template = false
|
|
182
|
+
if source_file
|
|
183
|
+
dir = File.dirname(source_file)
|
|
184
|
+
filename = File.basename(source_file, '.rb')
|
|
185
|
+
template_dir = File.join(dir, filename)
|
|
186
|
+
|
|
187
|
+
extensions = ['.html.erb', '.html.haml', '.html.slim']
|
|
188
|
+
path = File.join(template_dir, "#{example_name}")
|
|
189
|
+
|
|
190
|
+
found_template = extensions.any? { |ext| File.exist?("#{path}#{ext}") }
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
unless found_template
|
|
194
|
+
raise ViewComponent::MissingPreviewTemplateError.new("Preview #{example_name} returned nil and no template found at #{path}.* (checked erb, haml, slim)") if defined?(ViewComponent::MissingPreviewTemplateError)
|
|
195
|
+
|
|
196
|
+
raise "Preview returned nil and no template found at #{path}.*"
|
|
197
|
+
end
|
|
160
198
|
end
|
|
161
199
|
|
|
162
200
|
CheckResult.new(preview_name: preview.name, example_name: example_name, status: :passed)
|
|
@@ -179,6 +179,8 @@ module LookbookVisualTester
|
|
|
179
179
|
if result[:error] == 'Baseline not found'
|
|
180
180
|
# First run, maybe auto-approve or just report
|
|
181
181
|
puts ' [NEW] Baseline not found. Saved current as potential baseline.'
|
|
182
|
+
FileUtils.mkdir_p(File.dirname(baseline_path))
|
|
183
|
+
FileUtils.cp(current_path, baseline_path)
|
|
182
184
|
status = :new
|
|
183
185
|
else
|
|
184
186
|
puts " [ERROR] #{result[:error]}"
|
|
@@ -21,6 +21,7 @@ namespace :lookbook do
|
|
|
21
21
|
checker = LookbookVisualTester::PreviewChecker.new
|
|
22
22
|
results = checker.deep_check
|
|
23
23
|
LookbookVisualTester::CheckReporter.start([results])
|
|
24
|
+
exit 1 if results.any? { |r| r.status == :failed }
|
|
24
25
|
end
|
|
25
26
|
|
|
26
27
|
desc 'Find components missing previews'
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: lookbook_visual_tester
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.5.
|
|
4
|
+
version: 0.5.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Murilo Vasconcelos
|
|
@@ -187,7 +187,6 @@ files:
|
|
|
187
187
|
- lib/lookbook_visual_tester/configuration.rb
|
|
188
188
|
- lib/lookbook_visual_tester/driver.rb
|
|
189
189
|
- lib/lookbook_visual_tester/drivers/ferrum_driver.rb
|
|
190
|
-
- lib/lookbook_visual_tester/image_comparator.rb
|
|
191
190
|
- lib/lookbook_visual_tester/json_output_handler.rb
|
|
192
191
|
- lib/lookbook_visual_tester/preview_checker.rb
|
|
193
192
|
- lib/lookbook_visual_tester/railtie.rb
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
require 'lookbook_visual_tester/configuration'
|
|
2
|
-
|
|
3
|
-
module LookbookVisualTester
|
|
4
|
-
class ImageComparator
|
|
5
|
-
attr_reader :baseline_dir, :current_dir, :diff_dir
|
|
6
|
-
|
|
7
|
-
def initialize
|
|
8
|
-
@baseline_dir = LookbookVisualTester.config.baseline_dir
|
|
9
|
-
@current_dir = LookbookVisualTester.config.current_dir
|
|
10
|
-
@diff_dir = LookbookVisualTester.config.diff_dir
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def compare(scenario_run)
|
|
14
|
-
filename = scenario_run.filename
|
|
15
|
-
|
|
16
|
-
current_path = current_dir.join(filename)
|
|
17
|
-
baseline_path = baseline_dir.join(filename)
|
|
18
|
-
diff_path = diff_dir.join(scenario_run.diff_filename)
|
|
19
|
-
|
|
20
|
-
if baseline_path.exist?
|
|
21
|
-
baseline_image = MiniMagick::Image.open(baseline_path)
|
|
22
|
-
current_image = MiniMagick::Image.open(current_path)
|
|
23
|
-
|
|
24
|
-
unless baseline_image.dimensions == current_image.dimensions
|
|
25
|
-
puts ' Image dimensions do not match. Skipping comparison.'
|
|
26
|
-
return
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
begin
|
|
30
|
-
compare_command = "compare -metric AE \"#{baseline_path}\" \"#{current_path}\" \"#{diff_path}\" 2>&1"
|
|
31
|
-
result = `#{compare_command}`
|
|
32
|
-
distortion = result.strip.to_i
|
|
33
|
-
|
|
34
|
-
if distortion > 0
|
|
35
|
-
puts " Differences found! Diff image saved to #{diff_path}"
|
|
36
|
-
else
|
|
37
|
-
puts ' No differences detected.'
|
|
38
|
-
File.delete(diff_path) if diff_path.exist?
|
|
39
|
-
end
|
|
40
|
-
rescue StandardError => e
|
|
41
|
-
puts " Error comparing images: #{e.message}"
|
|
42
|
-
end
|
|
43
|
-
else
|
|
44
|
-
FileUtils.cp(current_path, baseline_path)
|
|
45
|
-
puts " Baseline image created at #{baseline_path}"
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|