lookbook_visual_tester 0.1.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 +7 -0
- data/.rubocop.yml +8 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/README.md +35 -0
- data/Rakefile +12 -0
- data/lib/lookbook_visual_tester/capybara_setup.rb +15 -0
- data/lib/lookbook_visual_tester/configuration.rb +25 -0
- data/lib/lookbook_visual_tester/image_comparator.rb +49 -0
- data/lib/lookbook_visual_tester/railtie.rb +11 -0
- data/lib/lookbook_visual_tester/report_generator.rb +57 -0
- data/lib/lookbook_visual_tester/scenario_run.rb +45 -0
- data/lib/lookbook_visual_tester/screenshot_taker.rb +63 -0
- data/lib/lookbook_visual_tester/session_manager.rb +17 -0
- data/lib/lookbook_visual_tester/version.rb +5 -0
- data/lib/lookbook_visual_tester.rb +10 -0
- data/lib/tasks/lookbook_visual_tester.rake +99 -0
- data/sig/lookbook_visual_tester.rbs +4 -0
- data/tasks/lookbook_visual_tester.rake +0 -0
- metadata +202 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3f05265af62c730e38c094caa8628914cbfa5cc374dd80a10e0e04eeaa74c9b7
|
4
|
+
data.tar.gz: bdd9e634a4cc0be9ae9b75c68097f5f5d6d92030b4eccbda2ecdab0dff3a7f63
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cf97827f66239e93300fabd2aecb06616ba873fe6b4d870238d3e50349f48d5d69438462303adf28a796fb56006c2f319f6b4f2d766d9ecc46f8d18e755de217
|
7
|
+
data.tar.gz: dbc55c0b4171a656d3b7b1fd41e2a8e8d2cf227d9fb7fa5205d968bfeab958e7f5fca7da557f4a132fa69d653d4d7405d4d1b275fa17ed556da838e8a9ae5e03
|
data/.rubocop.yml
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.2.1
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
9
|
+
nationality, personal appearance, race, caste, color, religion, or sexual
|
10
|
+
identity and orientation.
|
11
|
+
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
13
|
+
diverse, inclusive, and healthy community.
|
14
|
+
|
15
|
+
## Our Standards
|
16
|
+
|
17
|
+
Examples of behavior that contributes to a positive environment for our
|
18
|
+
community include:
|
19
|
+
|
20
|
+
* Demonstrating empathy and kindness toward other people
|
21
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
22
|
+
* Giving and gracefully accepting constructive feedback
|
23
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
24
|
+
and learning from the experience
|
25
|
+
* Focusing on what is best not just for us as individuals, but for the overall
|
26
|
+
community
|
27
|
+
|
28
|
+
Examples of unacceptable behavior include:
|
29
|
+
|
30
|
+
* The use of sexualized language or imagery, and sexual attention or advances of
|
31
|
+
any kind
|
32
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
33
|
+
* Public or private harassment
|
34
|
+
* Publishing others' private information, such as a physical or email address,
|
35
|
+
without their explicit permission
|
36
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
37
|
+
professional setting
|
38
|
+
|
39
|
+
## Enforcement Responsibilities
|
40
|
+
|
41
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
42
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
43
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
44
|
+
or harmful.
|
45
|
+
|
46
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
47
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
48
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
49
|
+
decisions when appropriate.
|
50
|
+
|
51
|
+
## Scope
|
52
|
+
|
53
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
54
|
+
an individual is officially representing the community in public spaces.
|
55
|
+
Examples of representing our community include using an official email address,
|
56
|
+
posting via an official social media account, or acting as an appointed
|
57
|
+
representative at an online or offline event.
|
58
|
+
|
59
|
+
## Enforcement
|
60
|
+
|
61
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
62
|
+
reported to the community leaders responsible for enforcement at
|
63
|
+
[INSERT CONTACT METHOD].
|
64
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
65
|
+
|
66
|
+
All community leaders are obligated to respect the privacy and security of the
|
67
|
+
reporter of any incident.
|
68
|
+
|
69
|
+
## Enforcement Guidelines
|
70
|
+
|
71
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
72
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
73
|
+
|
74
|
+
### 1. Correction
|
75
|
+
|
76
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
77
|
+
unprofessional or unwelcome in the community.
|
78
|
+
|
79
|
+
**Consequence**: A private, written warning from community leaders, providing
|
80
|
+
clarity around the nature of the violation and an explanation of why the
|
81
|
+
behavior was inappropriate. A public apology may be requested.
|
82
|
+
|
83
|
+
### 2. Warning
|
84
|
+
|
85
|
+
**Community Impact**: A violation through a single incident or series of
|
86
|
+
actions.
|
87
|
+
|
88
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
89
|
+
interaction with the people involved, including unsolicited interaction with
|
90
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
91
|
+
includes avoiding interactions in community spaces as well as external channels
|
92
|
+
like social media. Violating these terms may lead to a temporary or permanent
|
93
|
+
ban.
|
94
|
+
|
95
|
+
### 3. Temporary Ban
|
96
|
+
|
97
|
+
**Community Impact**: A serious violation of community standards, including
|
98
|
+
sustained inappropriate behavior.
|
99
|
+
|
100
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
101
|
+
communication with the community for a specified period of time. No public or
|
102
|
+
private interaction with the people involved, including unsolicited interaction
|
103
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
104
|
+
Violating these terms may lead to a permanent ban.
|
105
|
+
|
106
|
+
### 4. Permanent Ban
|
107
|
+
|
108
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
109
|
+
standards, including sustained inappropriate behavior, harassment of an
|
110
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
111
|
+
|
112
|
+
**Consequence**: A permanent ban from any sort of public interaction within the
|
113
|
+
community.
|
114
|
+
|
115
|
+
## Attribution
|
116
|
+
|
117
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
118
|
+
version 2.1, available at
|
119
|
+
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
120
|
+
|
121
|
+
Community Impact Guidelines were inspired by
|
122
|
+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
123
|
+
|
124
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
125
|
+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
|
126
|
+
[https://www.contributor-covenant.org/translations][translations].
|
127
|
+
|
128
|
+
[homepage]: https://www.contributor-covenant.org
|
129
|
+
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
130
|
+
[Mozilla CoC]: https://github.com/mozilla/diversity
|
131
|
+
[FAQ]: https://www.contributor-covenant.org/faq
|
132
|
+
[translations]: https://www.contributor-covenant.org/translations
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# LookbookVisualTester
|
2
|
+
|
3
|
+
This gem was built to serve as a lookbook regression tester, getting prints from previews, comparing them and generating a report of differences.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Install the gem and add to the application's Gemfile by executing:
|
8
|
+
|
9
|
+
```bash
|
10
|
+
bundle add lookbook_visual_tester
|
11
|
+
```
|
12
|
+
|
13
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
14
|
+
|
15
|
+
```bash
|
16
|
+
gem install lookbook_visual_tester
|
17
|
+
```
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
bundle exec rake lookbook_visual_tester:run LOOKBOOK_HOST=https://localhost:5000
|
22
|
+
|
23
|
+
## Development
|
24
|
+
|
25
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
26
|
+
|
27
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/muriloime/lookbook_visual_tester. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/lookbook_visual_tester/blob/main/CODE_OF_CONDUCT.md).
|
32
|
+
|
33
|
+
## Code of Conduct
|
34
|
+
|
35
|
+
Everyone interacting in the LookbookVisualTester project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/lookbook_visual_tester/blob/main/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require "capybara"
|
2
|
+
require "capybara/cuprite"
|
3
|
+
|
4
|
+
module LookbookVisualTester
|
5
|
+
module CapybaraSetup
|
6
|
+
def self.setup
|
7
|
+
Capybara.register_driver :cuprite do |app|
|
8
|
+
Capybara::Cuprite::Driver.new(app, headless: true, browser_options: { "ignore-certificate-errors" => true })
|
9
|
+
end
|
10
|
+
|
11
|
+
Capybara.default_driver = :cuprite
|
12
|
+
Capybara.server = :puma, { Silent: true }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module LookbookVisualTester
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :base_path, :baseline_dir, :current_dir, :diff_dir, :threads ,:host
|
4
|
+
|
5
|
+
DEFAULT_THREADS = 4
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@base_path = Rails.root.join("spec/visual_screenshots")
|
9
|
+
@baseline_dir = @base_path.join("baseline")
|
10
|
+
@current_dir = @base_path.join("current_run")
|
11
|
+
@diff_dir = @base_path.join("diff")
|
12
|
+
@threads = DEFAULT_THREADS
|
13
|
+
|
14
|
+
@host = ENV["LOOKBOOK_HOST"] || "https://localhost:5000"
|
15
|
+
|
16
|
+
[baseline_dir, current_dir, diff_dir].each do |dir|
|
17
|
+
FileUtils.mkdir_p(dir) unless Dir.exist?(dir)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.config
|
23
|
+
@config ||= Configuration.new
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,49 @@
|
|
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
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module LookbookVisualTester
|
2
|
+
class ReportGenerator
|
3
|
+
attr_reader :report_path, :baseline_dir, :current_dir, :diff_dir, :base_path
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@baseline_dir, @current_dir, @diff_dir, @base_path = LookbookVisualTester.config.then do |config|
|
7
|
+
[config.baseline_dir, config.current_dir, config.diff_dir, config.base_path]
|
8
|
+
end
|
9
|
+
|
10
|
+
@report_path = base_path.join("report.html")
|
11
|
+
end
|
12
|
+
|
13
|
+
def generate
|
14
|
+
File.open(report_path, "w") do |file|
|
15
|
+
file.puts "<!DOCTYPE html>"
|
16
|
+
file.puts "<html lang='en'>"
|
17
|
+
file.puts "<head><meta charset='UTF-8'><title>Visual Regression Report</title></head>"
|
18
|
+
file.puts "<body>"
|
19
|
+
file.puts "<h1>Visual Regression Report</h1>"
|
20
|
+
file.puts "<ul>"
|
21
|
+
|
22
|
+
diff_files = Dir.glob(diff_dir.join("*_diff.png"))
|
23
|
+
diff_files.each do |diff_file|
|
24
|
+
filename = File.basename(diff_file)
|
25
|
+
# Extract preview and scenario names
|
26
|
+
preview_scenario = filename.sub("_diff.png", "")
|
27
|
+
preview, scenario = preview_scenario.split("_", 2)
|
28
|
+
|
29
|
+
baseline_image = baseline_dir.join("#{preview}_#{scenario}.png")
|
30
|
+
current_image = current_dir.join("#{preview}_#{scenario}.png")
|
31
|
+
|
32
|
+
file.puts "<li>"
|
33
|
+
file.puts "<h2>#{preview.titleize} - #{scenario.titleize}</h2>"
|
34
|
+
file.puts "<div style='display: flex; gap: 10px;'>"
|
35
|
+
|
36
|
+
baseline_image_path = Pathname.new(baseline_image)
|
37
|
+
current_image_path = Pathname.new(current_image)
|
38
|
+
diff_file_path = Pathname.new(diff_file)
|
39
|
+
|
40
|
+
file.puts "<div><h3>Baseline</h3><img src='#{baseline_image_path.relative_path_from(base_path)}' alt='Baseline'></div>"
|
41
|
+
file.puts "<div><h3>Current</h3><img src='#{current_image_path.relative_path_from(base_path)}' alt='Current'></div>"
|
42
|
+
file.puts "<div><h3>Diff</h3><img src='#{diff_file_path.relative_path_from(base_path)}' alt='Diff'></div>"
|
43
|
+
file.puts "</div>"
|
44
|
+
file.puts "</li>"
|
45
|
+
end
|
46
|
+
|
47
|
+
file.puts "<li>No differences found!</li>" if diff_files.empty?
|
48
|
+
|
49
|
+
file.puts "</ul>"
|
50
|
+
file.puts "</body>"
|
51
|
+
file.puts "</html>"
|
52
|
+
end
|
53
|
+
|
54
|
+
@report_path
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require "lookbook_visual_tester/configuration"
|
2
|
+
|
3
|
+
module LookbookVisualTester
|
4
|
+
class ScenarioRun
|
5
|
+
attr_reader :scenario, :preview
|
6
|
+
|
7
|
+
def initialize(scenario)
|
8
|
+
@scenario = scenario
|
9
|
+
@preview = scenario.preview
|
10
|
+
|
11
|
+
puts " Scenario: #{scenario_name}"
|
12
|
+
end
|
13
|
+
|
14
|
+
def preview_name
|
15
|
+
preview.name.underscore
|
16
|
+
end
|
17
|
+
|
18
|
+
def scenario_name
|
19
|
+
scenario.name.underscore
|
20
|
+
end
|
21
|
+
|
22
|
+
def filename
|
23
|
+
"#{preview_name}_#{scenario_name}.png"
|
24
|
+
end
|
25
|
+
|
26
|
+
def diff_filename
|
27
|
+
"#{preview_name}_#{scenario_name}_diff.png"
|
28
|
+
end
|
29
|
+
|
30
|
+
def current_path
|
31
|
+
LookbookVisualTester.config.current_dir.join(filename)
|
32
|
+
end
|
33
|
+
|
34
|
+
def baseline_path
|
35
|
+
LookbookVisualTester.config.baseline_dir.join(filename)
|
36
|
+
end
|
37
|
+
|
38
|
+
def preview_url
|
39
|
+
Lookbook::Engine.routes.url_helpers.lookbook_preview_url(
|
40
|
+
path: preview.lookup_path + "/" + scenario.name,
|
41
|
+
host: LookbookVisualTester.config.host
|
42
|
+
)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require "lookbook_visual_tester/session_manager"
|
2
|
+
require "capybara/cuprite"
|
3
|
+
require "fileutils"
|
4
|
+
|
5
|
+
module LookbookVisualTester
|
6
|
+
class ScreenshotTaker
|
7
|
+
attr_reader :session, :logger
|
8
|
+
|
9
|
+
CLIPBOARD = 'clipboard'
|
10
|
+
|
11
|
+
def initialize(logger: Kernel)
|
12
|
+
Capybara.register_driver :cuprite do |app|
|
13
|
+
Capybara::Cuprite::Driver.new(
|
14
|
+
app,
|
15
|
+
window_size: [1400, 1400],
|
16
|
+
browser_options: { "ignore-certificate-errors" => nil },
|
17
|
+
timeout: 20,
|
18
|
+
process_timeout: 20
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
22
|
+
Capybara.default_driver = :cuprite
|
23
|
+
Capybara.default_max_wait_time = 15
|
24
|
+
@session = Capybara::Session.new(:cuprite)
|
25
|
+
@logger = logger
|
26
|
+
end
|
27
|
+
|
28
|
+
def capture(preview_url, path = CLIPBOARD)
|
29
|
+
FileUtils.mkdir_p(File.dirname(path))
|
30
|
+
|
31
|
+
session.visit(preview_url)
|
32
|
+
|
33
|
+
# Wait for network requests to complete
|
34
|
+
# session.driver.network_idle?
|
35
|
+
|
36
|
+
# Additional wait for any JavaScript animations
|
37
|
+
sleep 1
|
38
|
+
if path == CLIPBOARD
|
39
|
+
save_to_clipboard
|
40
|
+
else
|
41
|
+
save_screenshot(path)
|
42
|
+
end
|
43
|
+
rescue StandardError => e
|
44
|
+
logger.puts "Error capturing screenshot for #{preview_url}: #{e.message}"
|
45
|
+
raise e
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
def save_to_clipboard
|
50
|
+
Tempfile.create(['screenshot', '.png']) do |file|
|
51
|
+
session.save_screenshot(file.path)
|
52
|
+
|
53
|
+
# Example: Copy to clipboard (Linux xclip)
|
54
|
+
system("xclip -selection clipboard -t image/png -i #{file.path}")
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def save_screenshot(path)
|
59
|
+
session.save_screenshot(path)
|
60
|
+
logger.puts " Screenshot saved to #{path}"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# Setup Capybara
|
2
|
+
require "singleton"
|
3
|
+
require "capybara"
|
4
|
+
require "capybara/cuprite"
|
5
|
+
|
6
|
+
module LookbookVisualTester
|
7
|
+
class SessionManager
|
8
|
+
include Singleton
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
CapybaraSetup.setup
|
12
|
+
@session = Capybara::Session.new(:cuprite)
|
13
|
+
end
|
14
|
+
|
15
|
+
attr_reader :session
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# lib/lookbook_visual_tester.rb
|
3
|
+
|
4
|
+
require_relative "lookbook_visual_tester/version"
|
5
|
+
require_relative "lookbook_visual_tester/railtie" if defined?(Rails)
|
6
|
+
|
7
|
+
module LookbookVisualTester
|
8
|
+
class Error < StandardError; end
|
9
|
+
# Your code goes here...
|
10
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
# lib/tasks/lookbook_visual_tester.rake
|
2
|
+
require "fileutils"
|
3
|
+
require "mini_magick"
|
4
|
+
require "ruby-prof"
|
5
|
+
require "concurrent-ruby"
|
6
|
+
|
7
|
+
require "lookbook_visual_tester/report_generator"
|
8
|
+
require "lookbook_visual_tester/screenshot_taker"
|
9
|
+
require "lookbook_visual_tester/image_comparator"
|
10
|
+
require "lookbook_visual_tester/scenario_run"
|
11
|
+
|
12
|
+
namespace :lookbook_visual_tester do
|
13
|
+
desc "Profile the lookbook_visual_tester:run task"
|
14
|
+
task profile: :environment do
|
15
|
+
RubyProf.start
|
16
|
+
Rake::Task["lookbook_visual_tester:run"].invoke
|
17
|
+
result = RubyProf.stop
|
18
|
+
|
19
|
+
printer = RubyProf::FlatPrinter.new(result)
|
20
|
+
printer.print(STDOUT)
|
21
|
+
end
|
22
|
+
|
23
|
+
desc "Run and copy to clipboard first scenario matching the given name"
|
24
|
+
task :copy, [:name] => :environment do |t, args|
|
25
|
+
# example on how to run: `rake lookbook_visual_tester:copy["Button"]`
|
26
|
+
|
27
|
+
screenshot_taker = LookbookVisualTester::ScreenshotTaker.new
|
28
|
+
previews = Lookbook.previews
|
29
|
+
|
30
|
+
regex = Regexp.new(args[:name].chars.join(".*"), Regexp::IGNORECASE)
|
31
|
+
matched_previews = previews.select { |preview| regex.match?(preview.name.underscore) }
|
32
|
+
if matched_previews.empty?
|
33
|
+
puts "No Lookbook previews found matching #{args[:name]}"
|
34
|
+
exit
|
35
|
+
end
|
36
|
+
matched_previews.each do |preview|
|
37
|
+
preview.scenarios.each do |scenario|
|
38
|
+
scenario_run = LookbookVisualTester::ScenarioRun.new(scenario)
|
39
|
+
screenshot_taker.capture(scenario_run.preview_url)
|
40
|
+
exit
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
desc "Run visual regression tests for Lookbook previews"
|
46
|
+
task run: :environment do
|
47
|
+
screenshot_taker = LookbookVisualTester::ScreenshotTaker.new
|
48
|
+
image_comparator = LookbookVisualTester::ImageComparator.new
|
49
|
+
report = LookbookVisualTester::ReportGenerator.new
|
50
|
+
|
51
|
+
previews = Lookbook.previews
|
52
|
+
|
53
|
+
if previews.empty?
|
54
|
+
puts "No Lookbook previews found."
|
55
|
+
exit
|
56
|
+
end
|
57
|
+
|
58
|
+
pool = Concurrent::FixedThreadPool.new(LookbookVisualTester.config.threads)
|
59
|
+
previews.each do |preview|
|
60
|
+
preview_name = preview.name.underscore
|
61
|
+
puts "Processing Preview: #{preview_name}"
|
62
|
+
|
63
|
+
preview.scenarios.each do |scenario|
|
64
|
+
Concurrent::Promises.future_on(pool) do
|
65
|
+
scenario_run = LookbookVisualTester::ScenarioRun.new(scenario)
|
66
|
+
|
67
|
+
screenshot_taker.capture(scenario_run.preview_url, scenario_run.current_path)
|
68
|
+
puts " Visiting URL: #{preview_url}"
|
69
|
+
|
70
|
+
image_comparator.compare(scenario_run)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
pool.shutdown
|
76
|
+
pool.wait_for_termination
|
77
|
+
report_path = report.generate
|
78
|
+
puts "Visual regression report generated at #{report_path}"
|
79
|
+
end
|
80
|
+
|
81
|
+
desc "Update baseline screenshots with current_run screenshots"
|
82
|
+
task update_baseline: :environment do
|
83
|
+
base_path = Rails.root.join("spec/visual_screenshots")
|
84
|
+
baseline_dir = base_path.join("baseline")
|
85
|
+
current_dir = base_path.join("current_run")
|
86
|
+
|
87
|
+
unless current_dir.exist?
|
88
|
+
puts "Current run directory does not exist. Run the visual regression tests first."
|
89
|
+
exit
|
90
|
+
end
|
91
|
+
|
92
|
+
Dir.glob(current_dir.join("*.png")).each do |current_file|
|
93
|
+
filename = File.basename(current_file)
|
94
|
+
baseline_file = baseline_dir.join(filename)
|
95
|
+
FileUtils.cp(current_file, baseline_file)
|
96
|
+
puts "Baseline updated for #{filename}"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
File without changes
|
metadata
ADDED
@@ -0,0 +1,202 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lookbook_visual_tester
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Murilo Vasconcelos
|
8
|
+
bindir: exe
|
9
|
+
cert_chain: []
|
10
|
+
date: 2025-02-21 00:00:00.000000000 Z
|
11
|
+
dependencies:
|
12
|
+
- !ruby/object:Gem::Dependency
|
13
|
+
name: capybara
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - ">="
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '0'
|
19
|
+
type: :runtime
|
20
|
+
prerelease: false
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
requirements:
|
23
|
+
- - ">="
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: '0'
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: cuprite
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
- !ruby/object:Gem::Dependency
|
41
|
+
name: concurrent-ruby
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
type: :runtime
|
48
|
+
prerelease: false
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
- !ruby/object:Gem::Dependency
|
55
|
+
name: lookbook
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
type: :runtime
|
62
|
+
prerelease: false
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
name: mini_magick
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
type: :runtime
|
76
|
+
prerelease: false
|
77
|
+
version_requirements: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
- !ruby/object:Gem::Dependency
|
83
|
+
name: rails
|
84
|
+
requirement: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
type: :runtime
|
90
|
+
prerelease: false
|
91
|
+
version_requirements: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
- !ruby/object:Gem::Dependency
|
97
|
+
name: ruby-prof
|
98
|
+
requirement: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
type: :runtime
|
104
|
+
prerelease: false
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: bundler
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - "~>"
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '2.0'
|
117
|
+
type: :development
|
118
|
+
prerelease: false
|
119
|
+
version_requirements: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - "~>"
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '2.0'
|
124
|
+
- !ruby/object:Gem::Dependency
|
125
|
+
name: rake
|
126
|
+
requirement: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - "~>"
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '13.0'
|
131
|
+
type: :development
|
132
|
+
prerelease: false
|
133
|
+
version_requirements: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - "~>"
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '13.0'
|
138
|
+
- !ruby/object:Gem::Dependency
|
139
|
+
name: rspec
|
140
|
+
requirement: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - "~>"
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '3.10'
|
145
|
+
type: :development
|
146
|
+
prerelease: false
|
147
|
+
version_requirements: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - "~>"
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '3.10'
|
152
|
+
description: A Rails gem that captures screenshots of Lookbook component previews,
|
153
|
+
compares them against baseline images, and highlights visual differences to assist
|
154
|
+
in safe refactoring.
|
155
|
+
email:
|
156
|
+
- muriloime@gmail.com
|
157
|
+
executables: []
|
158
|
+
extensions: []
|
159
|
+
extra_rdoc_files: []
|
160
|
+
files:
|
161
|
+
- ".rubocop.yml"
|
162
|
+
- ".ruby-version"
|
163
|
+
- CHANGELOG.md
|
164
|
+
- CODE_OF_CONDUCT.md
|
165
|
+
- README.md
|
166
|
+
- Rakefile
|
167
|
+
- lib/lookbook_visual_tester.rb
|
168
|
+
- lib/lookbook_visual_tester/capybara_setup.rb
|
169
|
+
- lib/lookbook_visual_tester/configuration.rb
|
170
|
+
- lib/lookbook_visual_tester/image_comparator.rb
|
171
|
+
- lib/lookbook_visual_tester/railtie.rb
|
172
|
+
- lib/lookbook_visual_tester/report_generator.rb
|
173
|
+
- lib/lookbook_visual_tester/scenario_run.rb
|
174
|
+
- lib/lookbook_visual_tester/screenshot_taker.rb
|
175
|
+
- lib/lookbook_visual_tester/session_manager.rb
|
176
|
+
- lib/lookbook_visual_tester/version.rb
|
177
|
+
- lib/tasks/lookbook_visual_tester.rake
|
178
|
+
- sig/lookbook_visual_tester.rbs
|
179
|
+
- tasks/lookbook_visual_tester.rake
|
180
|
+
homepage: https://github.com/muriloime/lookbook_visual_tester
|
181
|
+
licenses:
|
182
|
+
- MIT
|
183
|
+
metadata:
|
184
|
+
homepage_uri: https://github.com/muriloime/lookbook_visual_tester
|
185
|
+
rdoc_options: []
|
186
|
+
require_paths:
|
187
|
+
- lib
|
188
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
189
|
+
requirements:
|
190
|
+
- - ">="
|
191
|
+
- !ruby/object:Gem::Version
|
192
|
+
version: 3.0.0
|
193
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
194
|
+
requirements:
|
195
|
+
- - ">="
|
196
|
+
- !ruby/object:Gem::Version
|
197
|
+
version: '0'
|
198
|
+
requirements: []
|
199
|
+
rubygems_version: 3.6.2
|
200
|
+
specification_version: 4
|
201
|
+
summary: Visual regression testing for Lookbook previews in Rails applications.
|
202
|
+
test_files: []
|