lookbook_visual_tester 0.5.2 → 0.5.4
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 +9 -0
- data/README.md +10 -4
- data/lib/lookbook_visual_tester/preview_checker.rb +44 -6
- data/lib/lookbook_visual_tester/runner.rb +2 -0
- data/lib/lookbook_visual_tester/scenario_run.rb +1 -1
- 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: 52de57eac4b35b3aba43c82000005b796b7bfb405fed5914ffda3ff3d6039b2f
|
|
4
|
+
data.tar.gz: a6c8e5faf0af703732a0438766299bb1300879997c64d6cc96188e1a2a3ab47b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 78ee1ea32f42cbf2fe58f4178f03e7db493ab1598d1d80a65918c497bff2cb51778f6413b321ae8cda01248bd1714fd72ec0b44d6a968d33273234de21836d5c
|
|
7
|
+
data.tar.gz: 945d4767c88ec3121c11c6ea83e87ca286a5f5d8a1feb07b1fb10275b0c9139066047a348f9b6ce2f3d06d25f1ae09645a75aeba5dfdd99497cf2def48dddddf
|
data/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
|
+
## [0.5.4] - 2026-01-06
|
|
3
|
+
|
|
4
|
+
### Fixed
|
|
5
|
+
- **Variants URL Generation**: Fixed a bug where setting `VARIANTS` caused a `JSON::ParserError` in Lookbook. Variant parameters are now correctly serialized to JSON in the preview URL.
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
- **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`).
|
|
9
|
+
- **Deep Check**: `rake lookbook:deep_check` now exits with status 1 if any errors or failures are detected.
|
|
10
|
+
|
|
2
11
|
## [0.5.2] - 2026-01-04
|
|
3
12
|
|
|
4
13
|
### Fixed
|
data/README.md
CHANGED
|
@@ -28,8 +28,8 @@ sudo apt-get install imagemagick xclip
|
|
|
28
28
|
|
|
29
29
|
Add to your application's Gemfile:
|
|
30
30
|
```ruby
|
|
31
|
-
group :test do
|
|
32
|
-
gem 'lookbook_visual_tester'
|
|
31
|
+
group :test, :development do
|
|
32
|
+
gem 'lookbook_visual_tester', '~> 0.5.4'
|
|
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
|
```
|
|
@@ -166,7 +166,13 @@ bundle exec rake lookbook:missing
|
|
|
166
166
|
|
|
167
167
|
## Next Steps
|
|
168
168
|
|
|
169
|
-
- **
|
|
169
|
+
- **Enhanced Approval Workflow**: Implement a `rake lookbook:approve` task (and potentially an interactive mode) to verify and promote changes to baselines without manual file operations.
|
|
170
|
+
- **Tolerance Configuration**: Add support for configuring pixel mismatch tolerance levels to reduce flakiness in rendering (anti-aliasing, shadow rendering differences).
|
|
171
|
+
- **Ignore Regions**: Allow defining specific areas of a component to exclude from visual comparison (useful for unavoidable dynamic content).
|
|
172
|
+
- **Markdown Reports**: Generate markdown summaries of test runs suitable for posting automatically as Pull Request comments.
|
|
173
|
+
- **Cloud Storage**: Integration with cloud storage (S3, GCS) for managing baseline images to keep the git repository light.
|
|
174
|
+
- **CI/CD Blueprints**: Detailed guides and reusable actions/steps for integrating with GitHub Actions, GitLab CI, etc.
|
|
175
|
+
- **Multiple Browsers**: Expand driver support beyond Chrome/Ferrum (e.g. Firefox, Safari/Webkit) for cross-browser visual testing.
|
|
170
176
|
|
|
171
177
|
## Contributing
|
|
172
178
|
|
|
@@ -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]}"
|
|
@@ -57,7 +57,7 @@ module LookbookVisualTester
|
|
|
57
57
|
|
|
58
58
|
if display_params.any?
|
|
59
59
|
# Transform display_params { theme: 'dark' } -> { _display: { theme: 'dark' } }
|
|
60
|
-
params[:_display] = display_params
|
|
60
|
+
params[:_display] = display_params.to_json
|
|
61
61
|
end
|
|
62
62
|
|
|
63
63
|
Lookbook::Engine.routes.url_helpers.lookbook_preview_url(
|
|
@@ -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.4
|
|
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
|