happo 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 73690fa08fbd1338fc72d65f287329375b2a57ef
4
- data.tar.gz: 8ff2614642f52154b7dbf7faccb75f01d98acdd5
3
+ metadata.gz: 5bc8376eac8e1bfacd86ac884e2123f2e5c26241
4
+ data.tar.gz: 1f4bdd2c779cd2568dcec63659c73068a37386e2
5
5
  SHA512:
6
- metadata.gz: aa3ca88236618c91bad015f6d44188bf8799a1b5952d1f1e2c10745d2fcf425911605d089785bd6f1527d0b242615200d85ea7e076c4942379ef2ba8f8d6489c
7
- data.tar.gz: ad36897001417b3dfe313e2c6ebf3448b9a6c42064c23ccf14a571c16c290505ec4d8ae2387aa4c7642b99e27431eb11eb74f1c7098e1d85232cbed65c01a203
6
+ metadata.gz: 13fad1aaf10906ad8c6583927d272d01ef2ab23fb75f74220b252cf53f496b37fb86149684014739ed9ed0779ab764dafb02a6f3a41d2d5049dfdb5f7609a38e
7
+ data.tar.gz: 2212b4bc094addb155238555da89797d4e89d4b48eccf3399a92a84d77d4af69f5b3555a3799dbab8c29d64a0bbde90df2d912bdee3fa2f08119b7af2c09ec17
data/bin/happo CHANGED
@@ -9,8 +9,6 @@ Commands:
9
9
  debug
10
10
  review
11
11
  clean
12
- approve
13
- reject
14
12
  upload_diffs
15
13
  --help
16
14
  --version
@@ -39,13 +37,6 @@ when 'clean'
39
37
  FileUtils.remove_entry_secure Happo::Utils.config['snapshots_folder']
40
38
  end
41
39
 
42
- when 'approve', 'reject'
43
- example_description = ARGV[1]
44
- abort 'Missing example description' unless example_description
45
- viewport_name = ARGV[2]
46
- abort 'Missing viewport name' unless viewport_name
47
- Happo::Action.new(example_description, viewport_name).send(action)
48
-
49
40
  when 'upload_diffs'
50
41
  # `upload_diffs` returns a URL to a static html file
51
42
  puts Happo::Uploader.new.upload_diffs
@@ -2,7 +2,3 @@ body {
2
2
  background-color: #f0f0f0;
3
3
  font-family: helvetica, arial;
4
4
  }
5
-
6
- form {
7
- display: inline-block;
8
- }
data/lib/happo/runner.rb CHANGED
@@ -144,35 +144,49 @@ begin
144
144
  log.log '.', false
145
145
  end
146
146
 
147
- # Run the diff if needed
148
- baseline_path = Happo::Utils.path_to(
149
- description, viewport['name'], 'baseline.png')
150
-
151
- if File.exist? baseline_path
152
- # A baseline image exists, so we want to compare the new snapshot
153
- # against the baseline.
147
+ # This is potentially expensive code that is run in a tight loop for every
148
+ # snapshot that we will be taking. With that in mind, we want to do as
149
+ # little work here as possible to keep runs fast. Therefore, we have
150
+ # landed on the following algorithm:
151
+ #
152
+ # 1. Delete previous.png if it exists.
153
+ # 2. Compare the current snapshot in memory against current.png if it
154
+ # exists.
155
+ # 3. If there is a diff, move current.png to previous.png and write out
156
+ # diff.png to disk and the current snapshot to current.png.
157
+ # 4. If there is no diff, return, leaving the old current.png in place.
158
+ previous_image_path = Happo::Utils.path_to(
159
+ description, viewport['name'], 'previous.png')
160
+ current_image_path = Happo::Utils.path_to(
161
+ description, viewport['name'], 'current.png')
162
+ diff_image_path = Happo::Utils.path_to(
163
+ description, viewport['name'], 'diff.png')
164
+
165
+ # We no longer need the old previous.png and diff.png, so lets remove them
166
+ # to keep things clean.
167
+ File.delete previous_image_path if File.exist? previous_image_path
168
+ File.delete diff_image_path if File.exist? diff_image_path
169
+
170
+ if File.exist? current_image_path
154
171
  comparison = Happo::SnapshotComparer.new(
155
- ChunkyPNG::Image.from_file(baseline_path),
172
+ ChunkyPNG::Image.from_file(current_image_path),
156
173
  screenshot
157
174
  ).compare!
158
175
  log.log '.', false
159
176
 
160
177
  if comparison[:diff_image]
161
178
  # There was a visual difference between the new snapshot and the
162
- # baseline, so we want to write the diff image and the new snapshot
179
+ # previous, so we want to write the diff image and the new snapshot
163
180
  # image to disk. This will allow it to be reviewed by someone.
164
- diff_path = Happo::Utils.path_to(
165
- description, viewport['name'], 'diff.png')
166
- comparison[:diff_image].save(diff_path, :fast_rgba)
181
+ comparison[:diff_image].save(diff_image_path, :fast_rgba)
167
182
  log.log '.', false
168
183
 
169
- candidate_path = Happo::Utils.path_to(
170
- description, viewport['name'], 'candidate.png')
171
- screenshot.save(candidate_path, :fast_rgba)
184
+ File.rename(current_image_path, previous_image_path)
185
+ screenshot.save(current_image_path, :fast_rgba)
172
186
  log.log '.', false
173
187
 
174
188
  percent = comparison[:diff_in_percent].round(1)
175
- log.log log.cyan(" #{percent}% (#{candidate_path})")
189
+ log.log log.cyan(" #{percent}% (#{current_image_path})")
176
190
  result_summary[:diff_examples] << {
177
191
  description: description,
178
192
  viewport: viewport['name']
@@ -187,16 +201,15 @@ begin
187
201
  }
188
202
  end
189
203
  else
190
- # There was no baseline image yet, so we want to start by saving a new
191
- # baseline image.
204
+ # There was no snapshot yet, so we want to start by saving a new one.
192
205
 
193
206
  # Create the folder structure if it doesn't already exist
194
- unless File.directory?(dirname = File.dirname(baseline_path))
207
+ unless File.directory?(dirname = File.dirname(current_image_path))
195
208
  FileUtils.mkdir_p(dirname)
196
209
  end
197
- screenshot.save(baseline_path, :fast_rgba)
210
+ screenshot.save(current_image_path, :fast_rgba)
198
211
  log.log '.', false
199
- log.log " First snapshot created (#{baseline_path})"
212
+ log.log " First snapshot created (#{current_image_path})"
200
213
  result_summary[:new_examples] << {
201
214
  description: description,
202
215
  viewport: viewport['name']
data/lib/happo/server.rb CHANGED
@@ -53,16 +53,6 @@ module Happo
53
53
  end
54
54
  end
55
55
 
56
- post '/reject' do
57
- Happo::Action.new(params[:description], params[:viewport]).reject
58
- redirect back
59
- end
60
-
61
- post '/approve' do
62
- Happo::Action.new(params[:description], params[:viewport]).approve
63
- redirect back
64
- end
65
-
66
56
  run!
67
57
  end
68
58
  end
@@ -4,9 +4,10 @@ require 'securerandom'
4
4
  module Happo
5
5
  class Uploader
6
6
  def initialize
7
- @s3_access_key_id = Happo::Utils.config['s3_access_key_id']
8
- @s3_secret_access_key = Happo::Utils.config['s3_secret_access_key']
9
- @s3_bucket_name = Happo::Utils.config['s3_bucket_name']
7
+ @s3_access_key_id = ENV['S3_ACCESS_KEY_ID']
8
+ @s3_secret_access_key = ENV['S3_SECRET_ACCESS_KEY']
9
+ @s3_bucket_name = ENV['S3_BUCKET_NAME']
10
+ @s3_bucket_path = ENV['S3_BUCKET_PATH']
10
11
  end
11
12
 
12
13
  def upload_diffs
@@ -17,7 +18,11 @@ module Happo
17
18
  result_summary[:new_examples].empty?
18
19
 
19
20
  bucket = find_or_build_bucket
20
- dir = SecureRandom.uuid
21
+ dir = if @s3_bucket_path.nil? || @s3_bucket_path.empty?
22
+ SecureRandom.uuid
23
+ else
24
+ File.join(@s3_bucket_path, SecureRandom.uuid)
25
+ end
21
26
 
22
27
  diff_images = result_summary[:diff_examples].map do |diff|
23
28
  image = bucket.objects.build(
@@ -36,7 +41,7 @@ module Happo
36
41
  "#{dir}/#{example[:description]}_#{example[:viewport]}.png")
37
42
  image.content = open(Happo::Utils.path_to(example[:description],
38
43
  example[:viewport],
39
- 'baseline.png'))
44
+ 'previous.png'))
40
45
  image.content_type = 'image/png'
41
46
  image.save
42
47
  example[:url] = image.url
data/lib/happo/utils.rb CHANGED
@@ -70,11 +70,11 @@ module Happo
70
70
 
71
71
  snapshots_folder = Happo::Utils.config['snapshots_folder']
72
72
  diff_files = Dir.glob("#{snapshots_folder}/**/diff.png")
73
- baselines = Dir.glob("#{snapshots_folder}/**/baseline.png")
73
+ previous_images = Dir.glob("#{snapshots_folder}/**/previous.png")
74
74
 
75
75
  {
76
76
  diffs: diff_files.map(&prepare_file),
77
- baselines: baselines.map(&prepare_file)
77
+ previous_images: previous_images.map(&prepare_file)
78
78
  }
79
79
  end
80
80
  end
data/lib/happo/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # Defines the gem version.
2
2
  module Happo
3
- VERSION = '1.0.0'
3
+ VERSION = '2.0.0'
4
4
  end
@@ -12,26 +12,16 @@
12
12
  <%= h diff[:description] %> @ <%= diff[:viewport] %>
13
13
  </h3>
14
14
  <p><img src="/resource?file=<%= ERB::Util.url_encode(diff[:file]) %>"></p>
15
- <form style="display: inline-block"
16
- action="/approve?description=<%= diff[:description] %>&viewport=<%= diff[:viewport] %>"
17
- method="POST">
18
- <button type="submit">Approve</button>
19
- </form>
20
- <form style="display: inline-block"
21
- action="/reject?description=<%= diff[:description] %>&viewport=<%= diff[:viewport] %>"
22
- method="POST">
23
- <button type="submit">Reject</button>
24
- </form>
25
15
  <% end %>
26
16
 
27
17
  <hr>
28
18
 
29
- <h2>BASELINES</h2>
30
- <% @snapshots[:baselines].each do |baseline| %>
19
+ <h2>PREVIOUS</h2>
20
+ <% @snapshots[:previous_images].each do |previous_image| %>
31
21
  <h3>
32
- <%= h baseline[:description] %> @ <%= baseline[:viewport] %>
22
+ <%= h previous_image[:description] %> @ <%= previous_image[:viewport] %>
33
23
  </h3>
34
- <p><img src="/resource?file=<%= ERB::Util.url_encode(baseline[:file]) %>"></p>
24
+ <p><img src="/resource?file=<%= ERB::Util.url_encode(previous_image[:file]) %>"></p>
35
25
  <% end %>
36
26
  </body>
37
27
  </html>
data/lib/happo.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  require 'happo/utils'
2
- require 'happo/action'
3
2
  require 'happo/uploader'
4
3
  require 'happo/version'
5
4
  require 'happo/logger'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: happo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henric Trotzig
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-07-13 00:00:00.000000000 Z
12
+ date: 2016-07-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: chunky_png
@@ -144,7 +144,6 @@ extra_rdoc_files: []
144
144
  files:
145
145
  - bin/happo
146
146
  - lib/happo.rb
147
- - lib/happo/action.rb
148
147
  - lib/happo/diffs.html.erb
149
148
  - lib/happo/logger.rb
150
149
  - lib/happo/public/happo-runner.js
data/lib/happo/action.rb DELETED
@@ -1,33 +0,0 @@
1
- require 'happo/utils'
2
- require 'fileutils'
3
-
4
- module Happo
5
- class Action
6
- def initialize(example_description, viewport_name)
7
- @example_description = example_description
8
- @viewport_name = viewport_name
9
- end
10
-
11
- def approve
12
- diff_path = Happo::Utils.path_to(
13
- @example_description, @viewport_name, 'diff.png')
14
- baseline_path = Happo::Utils.path_to(
15
- @example_description, @viewport_name, 'baseline.png')
16
- candidate_path = Happo::Utils.path_to(
17
- @example_description, @viewport_name, 'candidate.png')
18
-
19
- FileUtils.rm(diff_path, force: true)
20
- FileUtils.mv(candidate_path, baseline_path) if File.exist? candidate_path
21
- end
22
-
23
- def reject
24
- diff_path = Happo::Utils.path_to(
25
- @example_description, @viewport_name, 'diff.png')
26
- candidate_path = Happo::Utils.path_to(
27
- @example_description, @viewport_name, 'candidate.png')
28
-
29
- FileUtils.rm(diff_path, force: true)
30
- FileUtils.rm(candidate_path, force: true)
31
- end
32
- end
33
- end