likadan 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/likadan +6 -8
- data/lib/likadan-diffs.html.erb +1 -1
- data/lib/likadan_action.rb +7 -7
- data/lib/likadan_runner.rb +16 -7
- data/lib/likadan_server.rb +2 -2
- data/lib/likadan_uploader.rb +1 -1
- data/lib/likadan_utils.rb +11 -5
- data/lib/public/likadan-runner.js +2 -5
- data/lib/views/review.erb +4 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e2e0f6a6e6e21240adecd24471d2a8633a657332
|
4
|
+
data.tar.gz: 17d021b98744e745dcd915e2c00f04d44c812925
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e877633500eedfee6579a70a5df97a6e87698b105d7c31df4a30363165a9909ce091874eabb0e4e5d9d826d1b46b43d613818fb996da11c9e9f353f7fffe66d7
|
7
|
+
data.tar.gz: 234e8b43b05bff6fdf4a7d5af3650989ab6bb2b2e6179720c16590105017a710e0b40a6b25c0e798ca726019ce72456db2c386342e9e0be922234e5a8b277625
|
data/bin/likadan
CHANGED
@@ -8,12 +8,10 @@ require 'fileutils'
|
|
8
8
|
action = ARGV[0] || 'run'
|
9
9
|
case action
|
10
10
|
when 'run'
|
11
|
-
Thread.
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
exit
|
16
|
-
end
|
11
|
+
Thread.abort_on_exception = true
|
12
|
+
Thread.new do
|
13
|
+
require 'likadan_runner'
|
14
|
+
exit
|
17
15
|
end
|
18
16
|
require 'likadan_server'
|
19
17
|
|
@@ -28,8 +26,8 @@ when 'clean'
|
|
28
26
|
|
29
27
|
when 'approve', 'reject'
|
30
28
|
abort 'Missing example name' unless example_name = ARGV[1]
|
31
|
-
abort 'Missing viewport
|
32
|
-
LikadanAction.new(example_name,
|
29
|
+
abort 'Missing viewport name' unless viewport_name = ARGV[2]
|
30
|
+
LikadanAction.new(example_name, viewport_name).send(action)
|
33
31
|
|
34
32
|
when 'upload_diffs'
|
35
33
|
# `upload_diffs` returns a URL to a static html file
|
data/lib/likadan-diffs.html.erb
CHANGED
data/lib/likadan_action.rb
CHANGED
@@ -2,15 +2,15 @@ require 'likadan_utils'
|
|
2
2
|
require 'fileutils'
|
3
3
|
|
4
4
|
class LikadanAction
|
5
|
-
def initialize(example_name,
|
5
|
+
def initialize(example_name, viewport_name)
|
6
6
|
@example_name = example_name
|
7
|
-
@
|
7
|
+
@viewport_name = viewport_name
|
8
8
|
end
|
9
9
|
|
10
10
|
def approve
|
11
|
-
diff_path = LikadanUtils.path_to(@example_name, @
|
12
|
-
baseline_path = LikadanUtils.path_to(@example_name, @
|
13
|
-
candidate_path = LikadanUtils.path_to(@example_name, @
|
11
|
+
diff_path = LikadanUtils.path_to(@example_name, @viewport_name, 'diff.png')
|
12
|
+
baseline_path = LikadanUtils.path_to(@example_name, @viewport_name, 'baseline.png')
|
13
|
+
candidate_path = LikadanUtils.path_to(@example_name, @viewport_name, 'candidate.png')
|
14
14
|
|
15
15
|
FileUtils.rm(diff_path, force: true)
|
16
16
|
|
@@ -20,8 +20,8 @@ class LikadanAction
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def reject
|
23
|
-
diff_path = LikadanUtils.path_to(@example_name, @
|
24
|
-
candidate_path = LikadanUtils.path_to(@example_name, @
|
23
|
+
diff_path = LikadanUtils.path_to(@example_name, @viewport_name, 'diff.png')
|
24
|
+
candidate_path = LikadanUtils.path_to(@example_name, @viewport_name, 'candidate.png')
|
25
25
|
|
26
26
|
FileUtils.rm(diff_path, force: true)
|
27
27
|
FileUtils.rm(candidate_path, force: true)
|
data/lib/likadan_runner.rb
CHANGED
@@ -9,27 +9,36 @@ require 'chunky_png'
|
|
9
9
|
require 'likadan_utils'
|
10
10
|
require 'fileutils'
|
11
11
|
|
12
|
+
def resolve_viewports(example)
|
13
|
+
configured_viewports = LikadanUtils.config['viewports']
|
14
|
+
|
15
|
+
(example['options']['viewports'] || [configured_viewports.first.first]).map do |viewport|
|
16
|
+
configured_viewports[viewport].merge('name' => viewport)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
12
20
|
driver = Selenium::WebDriver.for LikadanUtils.config['driver'].to_sym
|
13
21
|
begin
|
14
22
|
driver.navigate.to LikadanUtils.construct_url('/')
|
15
23
|
|
16
24
|
while current = driver.execute_script('return window.likadan.next()') do
|
17
|
-
current
|
25
|
+
resolve_viewports(current).each do |viewport|
|
18
26
|
# Resize window to the right size before rendering
|
19
|
-
driver.manage.window.resize_to(width,
|
27
|
+
driver.manage.window.resize_to(viewport['width'], viewport['height'])
|
20
28
|
|
21
29
|
# Render the example
|
22
30
|
rendered = driver.execute_script('return window.likadan.renderCurrent()')
|
23
31
|
if error = rendered['error']
|
24
32
|
puts <<-EOS
|
25
|
-
Error while rendering "#{current['name']}" @#{
|
33
|
+
Error while rendering "#{current['name']}" @#{viewport['name']}:
|
26
34
|
#{rendered['error']}
|
27
35
|
Debug by pointing your browser to
|
28
36
|
#{LikadanUtils.construct_url('/', name: current['name'])}
|
29
37
|
EOS
|
30
38
|
next
|
31
39
|
end
|
32
|
-
output_file = LikadanUtils.path_to(
|
40
|
+
output_file = LikadanUtils.path_to(
|
41
|
+
current['name'], viewport['name'], 'candidate.png')
|
33
42
|
|
34
43
|
# Create the folder structure if it doesn't already exist
|
35
44
|
unless File.directory?(dirname = File.dirname(output_file))
|
@@ -45,10 +54,10 @@ begin
|
|
45
54
|
rendered['height'])
|
46
55
|
cropped.save(output_file)
|
47
56
|
|
48
|
-
print "Checking \"#{current['name']}\" at #{
|
57
|
+
print "Checking \"#{current['name']}\" at [#{viewport['name']}]... "
|
49
58
|
|
50
59
|
# Run the diff if needed
|
51
|
-
baseline_file = LikadanUtils.path_to(current['name'],
|
60
|
+
baseline_file = LikadanUtils.path_to(current['name'], viewport['name'], 'baseline.png')
|
52
61
|
|
53
62
|
if File.exist? baseline_file
|
54
63
|
comparison = Diffux::SnapshotComparer.new(
|
@@ -57,7 +66,7 @@ begin
|
|
57
66
|
).compare!
|
58
67
|
|
59
68
|
if img = comparison[:diff_image]
|
60
|
-
diff_output = LikadanUtils.path_to(current['name'],
|
69
|
+
diff_output = LikadanUtils.path_to(current['name'], viewport['name'], 'diff.png')
|
61
70
|
img.save(diff_output)
|
62
71
|
puts "#{comparison[:diff_in_percent].round(1)}% (#{diff_output})"
|
63
72
|
else
|
data/lib/likadan_server.rb
CHANGED
@@ -29,12 +29,12 @@ class LikadanServer < Sinatra::Base
|
|
29
29
|
end
|
30
30
|
|
31
31
|
post '/reject' do
|
32
|
-
LikadanAction.new(params[:name], params[:
|
32
|
+
LikadanAction.new(params[:name], params[:viewport]).reject
|
33
33
|
redirect back
|
34
34
|
end
|
35
35
|
|
36
36
|
post '/approve' do
|
37
|
-
LikadanAction.new(params[:name], params[:
|
37
|
+
LikadanAction.new(params[:name], params[:viewport]).approve
|
38
38
|
redirect back
|
39
39
|
end
|
40
40
|
|
data/lib/likadan_uploader.rb
CHANGED
@@ -18,7 +18,7 @@ class LikadanUploader
|
|
18
18
|
bucket.save(location: :us)
|
19
19
|
|
20
20
|
diff_images = current_snapshots[:diffs].map do |diff|
|
21
|
-
image = bucket.objects.build("#{diff[:name]}_#{diff[:
|
21
|
+
image = bucket.objects.build("#{diff[:name]}_#{diff[:viewport]}.png")
|
22
22
|
image.content = open(diff[:file])
|
23
23
|
image.content_type = 'image/png'
|
24
24
|
image.save
|
data/lib/likadan_utils.rb
CHANGED
@@ -9,6 +9,12 @@ class LikadanUtils
|
|
9
9
|
'stylesheets' => [],
|
10
10
|
'port' => 4567,
|
11
11
|
'driver' => :firefox,
|
12
|
+
'viewports' => {
|
13
|
+
'desktop' => {
|
14
|
+
'width' => 1024,
|
15
|
+
'height' => 768
|
16
|
+
}
|
17
|
+
}
|
12
18
|
}.merge(YAML.load(ERB.new(File.read(
|
13
19
|
ENV['LIKADAN_CONFIG_FILE'] || '.likadan.yaml')).result))
|
14
20
|
end
|
@@ -17,11 +23,11 @@ class LikadanUtils
|
|
17
23
|
name.gsub(/[^a-zA-Z0-9\-_]/, '_')
|
18
24
|
end
|
19
25
|
|
20
|
-
def self.path_to(name,
|
26
|
+
def self.path_to(name, viewport_name, file_name)
|
21
27
|
File.join(
|
22
28
|
config['snapshots_folder'],
|
23
29
|
normalize_name(name),
|
24
|
-
"@#{
|
30
|
+
"@#{viewport_name}",
|
25
31
|
file_name
|
26
32
|
)
|
27
33
|
end
|
@@ -39,11 +45,11 @@ class LikadanUtils
|
|
39
45
|
|
40
46
|
def self.current_snapshots
|
41
47
|
prepare_file = lambda do |file|
|
42
|
-
|
43
|
-
name_dir = File.expand_path('..',
|
48
|
+
viewport_dir = File.expand_path('..', file)
|
49
|
+
name_dir = File.expand_path('..', viewport_dir)
|
44
50
|
{
|
45
51
|
name: File.basename(name_dir),
|
46
|
-
|
52
|
+
viewport: File.basename(viewport_dir).sub('@', ''),
|
47
53
|
file: file,
|
48
54
|
}
|
49
55
|
end
|
@@ -4,14 +4,11 @@ window.likadan = {
|
|
4
4
|
currentExample: undefined,
|
5
5
|
currentRenderedElement: undefined,
|
6
6
|
|
7
|
-
define: function(name, func,
|
7
|
+
define: function(name, func, options) {
|
8
8
|
this.defined.push({
|
9
9
|
name: name,
|
10
10
|
func: func,
|
11
|
-
|
12
|
-
options: options || {
|
13
|
-
snapshotEntireScreen: false
|
14
|
-
}
|
11
|
+
options: options || {}
|
15
12
|
});
|
16
13
|
},
|
17
14
|
|
data/lib/views/review.erb
CHANGED
@@ -16,16 +16,16 @@
|
|
16
16
|
<h2>DIFFS</h2>
|
17
17
|
<% @snapshots[:diffs].each do |diff| %>
|
18
18
|
<h3>
|
19
|
-
<%= diff[:name] %> @ <%= diff[:
|
19
|
+
<%= diff[:name] %> @ <%= diff[:viewport] %>
|
20
20
|
</h3>
|
21
21
|
<p><img src="/resource?file=<%= ERB::Util.url_encode(diff[:file]) %>"></p>
|
22
22
|
<form style="display: inline-block"
|
23
|
-
action="/approve?name=<%= diff[:name] %>&
|
23
|
+
action="/approve?name=<%= diff[:name] %>&viewport=<%= diff[:viewport] %>"
|
24
24
|
method="POST">
|
25
25
|
<button type="submit">Approve</button>
|
26
26
|
</form>
|
27
27
|
<form style="display: inline-block"
|
28
|
-
action="/reject?name=<%= diff[:name] %>&
|
28
|
+
action="/reject?name=<%= diff[:name] %>&viewport=<%= diff[:viewport] %>"
|
29
29
|
method="POST">
|
30
30
|
<button type="submit">Reject</button>
|
31
31
|
</form>
|
@@ -36,7 +36,7 @@
|
|
36
36
|
<h2>BASELINES</h2>
|
37
37
|
<% @snapshots[:baselines].each do |baseline| %>
|
38
38
|
<h3>
|
39
|
-
<%= baseline[:name] %> @ <%= baseline[:
|
39
|
+
<%= baseline[:name] %> @ <%= baseline[:viewport] %>
|
40
40
|
</h3>
|
41
41
|
<p><img src="/resource?file=<%= ERB::Util.url_encode(baseline[:file]) %>"></p>
|
42
42
|
<% end %>
|