diff --git a/README.md b/README.md index d75c87d..4133719 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,25 @@ -# Likadan +# Diffux-CI -Likadan is a command-line tool to visually diff JavaScript components. +Diffux-CI is a command-line tool to visually diff JavaScript components. -You begin by defining a set of examples that Likadan will grab snapshots for. -If a previous snapshot (called a "baseline") exists for a component, Likadan +You begin by defining a set of examples that Diffux-CI will grab snapshots for. +If a previous snapshot (called a "baseline") exists for a component, Diffux-CI will diff the new snapshot with the old baseline. If a diff is found, a visual representation of the changes will be constructed. You can then use that diff image to decide whether a visual regression has been introduced or not, and take appropriate action based on that information. -![Demo of Likadan in action](likadan_demo.gif) +![Demo of Diffux-CI in action](diffux_ci_demo.gif) ## Defining examples You define your examples in a JavaScript file and include it in the `source_files` [configuration](#configuration) option. -Here's an example of a button component being added to a Likadan suite: +Here's an example of a button component being added to a Diffux-CI suite: ```javascript -likadan.define('button', function() { +diffux.define('button', function() { var elem = document.createElement('button'); elem.setAttribute('class', '.button'); elem.innerHTML = 'Submit'; @@ -35,21 +35,21 @@ DOM. A helper method to reduce some of the boilerplate is probably a good idea in your project. During development, you might want to zoom in/focus on a single example. In -those situations, you can use the `likadan.fdefine` function instead of -`likadan.define`. Using `fdefine` will cause `likadan` to only run for that +those situations, you can use the `diffux.fdefine` function instead of +`diffux.define`. Using `fdefine` will cause `diffux_ci` to only run for that example. ### Setting viewport sizes -By default, Likadan renders examples in a 1024 wide window. If you have +By default, Diffux-CI renders examples in a 1024 wide window. If you have components that render differently depending on available screen size you can use the `viewports` option in the object passed in as the second argument to -`likadan.define`. These need to correspond to configured `viewports` in the -`.likadan.yaml` file. Likadan comes pre-configured with three default sizes: +`diffux.define`. These need to correspond to configured `viewports` in the +`.diffux_ci.yaml` file. Diffux-CI comes pre-configured with three default sizes: `large` (1024x768), `medium` (640x888), and `small` (320x444). ```javascript -likadan.define('responsive component', function() { +diffux.define('responsive component', function() { var elem = document.createElement('div'); elem.setAttribute('class', '.responsive-component'); document.body.appendChild(elem); @@ -59,13 +59,13 @@ likadan.define('responsive component', function() { ### Controlling the snapshot -Likadan can usually figure out what part of the screen belongs to your +Diffux-CI can usually figure out what part of the screen belongs to your component, and take the snapshot of that area. In some situations however, that won't work. In those cases, you can pass in the `snapshotEntireScreen` option to force a full-size snapshot to be taken. ```javascript -likadan.define('dialog window', function() { +diffux.define('dialog window', function() { var elem = document.createElement('div'); elem.setAttribute('class', '.dialog'); document.body.appendChild(elem); @@ -79,7 +79,7 @@ If your examples need to do something asynchronous before they finish render, you can use the `done` callback passed in to the define method. ```javascript -likadan.define('async component', function(done) { +diffux.define('async component', function(done) { var elem = document.createElement('div'); document.body.appendChild(elem); setTimeout(function() { @@ -91,19 +91,19 @@ likadan.define('async component', function(done) { ## Installation -Likadan comes bundled as a gem. To install it, run `gem install likadan`. +Diffux-CI comes bundled as a gem. To install it, run `gem install diffux_ci`. ## Configuration -Likadan loads configuration in one of the following ways: +Diffux-CI loads configuration in one of the following ways: -- From a YAML file specified via a `LIKADAN_CONFIG_FILE` environment variable -- From `.likadan.yaml` in the current working directory +- From a YAML file specified via a `DIFFUX_CI_CONFIG_FILE` environment variable +- From `.diffux_ci.yaml` in the current working directory ```yaml source_files: - application.js - - likadan-examples.js + - diffux_ci-examples.js stylesheets: - application.css snapshots_folder: ./snapshots @@ -120,59 +120,59 @@ s3_secret_access_key: ## Command line tools -### `likadan` +### `diffux_ci` This command will fire up a Firefox instance and take snapshots of all your -likadan examples. +diffux examples. -### `likadan review` +### `diffux_ci review` -Once `likadan` has finished, run `likadan review` from the command line. This +Once `diffux_ci` has finished, run `diffux_ci review` from the command line. This will open a page that compares the latest run's snapshots against the previously accepted snapshots. You can then approve or reject the snapshots for the next run. -### `likadan upload_diffs` +### `diffux_ci upload_diffs` Uploads all current diff images to an Amazon S3 account and reports back URLs to access those diff images. Requires the `s3_access_key_id` and `s3_secret_access_key` configuration options. -### `likadan clean` +### `diffux_ci clean` Recursively removes everything in the snapshots folder (configured through `snapshots_folder`). ## Running in a CI environment -The main purpose for Likadan is for it to be run in a CI (Continuous +The main purpose for Diffux-CI is for it to be run in a CI (Continuous Integration) environment. The command line tools provided are designed to be used as building blocks in a script that you can run in [Travis](https://travis-ci.org/), [Jenkins](https://jenkins-ci.org/) and other Continuous Integration environments. -Below is an example of how you can use Likadan to test if a commit introduces +Below is an example of how you can use Diffux-CI to test if a commit introduces any visual change. 1. Check out the commit previous to the one to test (e.g. `git checkout HEAD^`) 2. (optionally) precompile your JavaScript and/or CSS -3. Run `likadan` to generate baseline snapshots +3. Run `diffux_ci` to generate baseline snapshots 4. Check out the commit to test 5. (optionally) precompile your JavaScript and/or CSS -6. Run `likadan` to diff against previously created snapshots -7. Run `likadan upload_diffs` to upload diffs to a publicly accessible location +6. Run `diffux_ci` to diff against previously created snapshots +7. Run `diffux_ci upload_diffs` to upload diffs to a publicly accessible location There's an example script implementing these steps located in -[likadan_ci_example.sh](likadan_ci_example.sh). Use that as a starting point +[diffux_ci_example.sh](diffux_ci_example.sh). Use that as a starting point for your own CI script. -### Headless Likadan +### Headless Diffux-CI -Since Likadan uses Firefox to generate its snapshots, you need a display. If -you are on a build server, you usually don't have a screen. To run `likadan` +Since Diffux-CI uses Firefox to generate its snapshots, you need a display. If +you are on a build server, you usually don't have a screen. To run `diffux_ci` then, you can use a virtual display server such as [xvfb](http://www.x.org/archive/X11R7.6/doc/man/man1/Xvfb.1.xhtml). The -[example CI script](likadan_ci_example.sh) as well as the internal Travis test -run for Likadan uses `xvfb-run` in order to obtain a virtual display. There are +[example CI script](diffux_ci_example.sh) as well as the internal Travis test +run for Diffux-CI uses `xvfb-run` in order to obtain a virtual display. There are other tools that can help you with this as well, for example the [headless gem](https://github.com/leonid-shevtsov/headless). diff --git a/bin/diffux_ci b/bin/diffux_ci new file mode 100755 index 0000000..8baa785 --- /dev/null +++ b/bin/diffux_ci @@ -0,0 +1,37 @@ +#!/usr/bin/env ruby + +require 'diffux_ci_utils' +require 'diffux_ci_action' +require 'diffux_ci_uploader' +require 'fileutils' + +action = ARGV[0] || 'run' +case action +when 'run' + Thread.abort_on_exception = true + Thread.new do + require 'diffux_ci_runner' + exit + end + require 'diffux_ci_server' + +when 'review' + system 'open', DiffuxCIUtils.construct_url('/review') + require 'diffux_ci_server' + +when 'clean' + if File.directory? DiffuxCIUtils.config['snapshots_folder'] + FileUtils.remove_entry_secure DiffuxCIUtils.config['snapshots_folder'] + end + +when 'approve', 'reject' + abort 'Missing example name' unless example_name = ARGV[1] + abort 'Missing viewport name' unless viewport_name = ARGV[2] + DiffuxCIAction.new(example_name, viewport_name).send(action) + +when 'upload_diffs' + # `upload_diffs` returns a URL to a static html file + puts DiffuxCIUploader.new.upload_diffs +else + abort "Unknown action \"#{action}\"" +end diff --git a/bin/likadan b/bin/likadan deleted file mode 100755 index 2816170..0000000 --- a/bin/likadan +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env ruby - -require 'likadan_utils' -require 'likadan_action' -require 'likadan_uploader' -require 'fileutils' - -action = ARGV[0] || 'run' -case action -when 'run' - Thread.abort_on_exception = true - Thread.new do - require 'likadan_runner' - exit - end - require 'likadan_server' - -when 'review' - system 'open', LikadanUtils.construct_url('/review') - require 'likadan_server' - -when 'clean' - if File.directory? LikadanUtils.config['snapshots_folder'] - FileUtils.remove_entry_secure LikadanUtils.config['snapshots_folder'] - end - -when 'approve', 'reject' - abort 'Missing example name' unless example_name = ARGV[1] - abort 'Missing viewport name' unless viewport_name = ARGV[2] - LikadanAction.new(example_name, viewport_name).send(action) - -when 'upload_diffs' - # `upload_diffs` returns a URL to a static html file - puts LikadanUploader.new.upload_diffs -else - abort "Unknown action \"#{action}\"" -end diff --git a/likadan.gemspec b/diffux_ci.gemspec similarity index 71% rename from likadan.gemspec rename to diffux_ci.gemspec index 924b156..b805dd1 100644 --- a/likadan.gemspec +++ b/diffux_ci.gemspec @@ -1,13 +1,13 @@ Gem::Specification.new do |s| - s.name = 'likadan' - s.version = '0.0.14' + s.name = 'diffux_ci' + s.version = '0.1.0' s.date = '2015-02-20' - s.summary = 'Likadan' - s.description = 'Likadan, a perceptual diff tool for JS components' + s.summary = 'Diffux-CI' + s.description = 'Diffux-CI, a perceptual diff tool for JS components' s.authors = ['Henric Trotzig'] s.email = 'henric.trotzig@gmail.com' - s.executables = ['likadan'] - s.homepage = 'http://rubygems.org/gems/likadan' + s.executables = ['diffux_ci'] + s.homepage = 'http://rubygems.org/gems/diffux_ci' s.license = 'MIT' s.require_paths = ['lib'] s.files = Dir['lib/**/*'] diff --git a/likadan_demo.gif b/diffux_ci_demo.gif similarity index 100% rename from likadan_demo.gif rename to diffux_ci_demo.gif diff --git a/likadan_ci_example.sh b/diffux_ci_example.sh similarity index 70% rename from likadan_ci_example.sh rename to diffux_ci_example.sh index 764873e..2fd2b2c 100644 --- a/likadan_ci_example.sh +++ b/diffux_ci_example.sh @@ -1,9 +1,9 @@ #!/bin/bash -ex -# This is an example script that generates and uploads Likadan diffs for the +# This is an example script that generates and uploads Diffux-CI diffs for the # differences between the previous and current commit. -run-likadan() { +run-diffux-ci() { # Checkout the commit git checkout --quiet $1 @@ -11,19 +11,19 @@ run-likadan() { npm install webpack ./entry.js bundle.js - # Run likadan for the current commit. We use `xvfb-run` so that we can run - # likadan (which uses Firefox) in a headless display environment. - xvfb-run likadan + # Run diffux_ci for the current commit. We use `xvfb-run` so that we can run + # diffux_ci (which uses Firefox) in a headless display environment. + xvfb-run diffux_ci } # Check out the previous version and generate baseline snapshots -run-likadan HEAD^ +run-diffux-ci HEAD^ # Check out the latest version and check for diffs -run-likadan - +run-diffux-ci - # Finally, upload any diffs to s3 -url_to_diffs=`likadan upload_diffs` +url_to_diffs=`diffux_ci upload_diffs` if [ -n "$url_to_diffs" ]; then # We have a URL to the diff(s) found for the commit. We can choose to do one # of a few things here. We either exit the script with a non-zero exit code. @@ -31,7 +31,7 @@ if [ -n "$url_to_diffs" ]; then # but instead post a comment to the commit with the URL to the diff(s). Below # is an example of the latter, where we post back a comment to a Gerrit patch # set. - message="Likadan diff(s) were found: $link_to_diffs" + message="Diffux-CI diff(s) were found: $link_to_diffs" ssh -p 29418 jenkins@example.com \ gerrit review \'--message="$message"\' $GERRIT_PATCHSET_REVISION diff --git a/example-project/.likadan.yaml b/example-project/.diffux_ci.yaml similarity index 100% rename from example-project/.likadan.yaml rename to example-project/.diffux_ci.yaml diff --git a/example-project/example.js b/example-project/example.js index bb6911b..9701f57 100644 --- a/example-project/example.js +++ b/example-project/example.js @@ -1,4 +1,4 @@ -likadan.define('foo', function() { +diffux.define('foo', function() { var elem = document.createElement('div'); elem.setAttribute('class', 'foo'); elem.innerHTML = 'Texts insides'; @@ -6,14 +6,14 @@ likadan.define('foo', function() { return elem; }); -likadan.define('hallooo', function() { +diffux.define('hallooo', function() { var elem = document.createElement('span'); elem.innerHTML = 'Hioyi!
Hello'; document.body.appendChild(elem); return elem; }, { viewports: ['mobile', 'desktop'] }); -likadan.define('bar', function() { +diffux.define('bar', function() { var elem = document.createElement('span'); elem.innerHTML = 'go bars!
bars'; document.body.appendChild(elem); diff --git a/lib/likadan-diffs.html.erb b/lib/diffux_ci-diffs.html.erb similarity index 81% rename from lib/likadan-diffs.html.erb rename to lib/diffux_ci-diffs.html.erb index 1f5ab44..e4f811d 100644 --- a/lib/likadan-diffs.html.erb +++ b/lib/diffux_ci-diffs.html.erb @@ -1,10 +1,10 @@ - Likadan diffs + Diffux-CI diffs -

Likadan diffs

+

Diffux-CI diffs

File generated: <%= Time.now %>

<% diff_images.each do |diff| %> diff --git a/lib/diffux_ci_action.rb b/lib/diffux_ci_action.rb new file mode 100644 index 0000000..42791f2 --- /dev/null +++ b/lib/diffux_ci_action.rb @@ -0,0 +1,29 @@ +require 'diffux_ci_utils' +require 'fileutils' + +class DiffuxCIAction + def initialize(example_name, viewport_name) + @example_name = example_name + @viewport_name = viewport_name + end + + def approve + diff_path = DiffuxCIUtils.path_to(@example_name, @viewport_name, 'diff.png') + baseline_path = DiffuxCIUtils.path_to(@example_name, @viewport_name, 'baseline.png') + candidate_path = DiffuxCIUtils.path_to(@example_name, @viewport_name, 'candidate.png') + + FileUtils.rm(diff_path, force: true) + + if File.exist? candidate_path + FileUtils.mv(candidate_path, baseline_path) + end + end + + def reject + diff_path = DiffuxCIUtils.path_to(@example_name, @viewport_name, 'diff.png') + candidate_path = DiffuxCIUtils.path_to(@example_name, @viewport_name, 'candidate.png') + + FileUtils.rm(diff_path, force: true) + FileUtils.rm(candidate_path, force: true) + end +end diff --git a/lib/likadan_runner.rb b/lib/diffux_ci_runner.rb similarity index 82% rename from lib/likadan_runner.rb rename to lib/diffux_ci_runner.rb index 64dcc04..a19d225 100644 --- a/lib/likadan_runner.rb +++ b/lib/diffux_ci_runner.rb @@ -6,11 +6,11 @@ require 'diffux_core/snapshot_comparison_image/overlayed' require 'diffux_core/snapshot_comparison_image/after' require 'chunky_png' -require 'likadan_utils' +require 'diffux_ci_utils' require 'fileutils' def resolve_viewports(example) - configured_viewports = LikadanUtils.config['viewports'] + configured_viewports = DiffuxCIUtils.config['viewports'] (example['options']['viewports'] || [configured_viewports.first.first]).map do |viewport| configured_viewports[viewport].merge('name' => viewport) @@ -18,26 +18,26 @@ def resolve_viewports(example) end begin - driver = Selenium::WebDriver.for LikadanUtils.config['driver'].to_sym + driver = Selenium::WebDriver.for DiffuxCIUtils.config['driver'].to_sym rescue Selenium::WebDriver::Error::WebDriverError # "unable to obtain stable firefox connection in 60 seconds" # # This seems to happen sporadically for some versions of Firefox, so we want # to retry it in case it will work the second time around. - driver = Selenium::WebDriver.for LikadanUtils.config['driver'].to_sym + driver = Selenium::WebDriver.for DiffuxCIUtils.config['driver'].to_sym end begin driver.manage.timeouts.script_timeout = 3 # move to config? - driver.navigate.to LikadanUtils.construct_url('/') + driver.navigate.to DiffuxCIUtils.construct_url('/') # Check for errors during startup - errors = driver.execute_script('return window.likadan.errors;') + errors = driver.execute_script('return window.diffux.errors;') unless errors.empty? fail "JavaScript errors found during initialization: \n#{errors.inspect}" end - while current = driver.execute_script('return window.likadan.next()') do + while current = driver.execute_script('return window.diffux.next()') do resolve_viewports(current).each do |viewport| # Resize window to the right size before rendering driver.manage.window.resize_to(viewport['width'], viewport['height']) @@ -57,7 +57,7 @@ def resolve_viewports(example) # does. script = <<-EOS var doneFunc = arguments[arguments.length - 1]; - window.likadan.renderCurrent(doneFunc); + window.diffux.renderCurrent(doneFunc); EOS rendered = driver.execute_async_script(script) @@ -66,10 +66,10 @@ def resolve_viewports(example) Error while rendering "#{current['name']}" @#{viewport['name']}: #{rendered['error']} Debug by pointing your browser to - #{LikadanUtils.construct_url('/', name: current['name'])} + #{DiffuxCIUtils.construct_url('/', name: current['name'])} EOS end - output_file = LikadanUtils.path_to( + output_file = DiffuxCIUtils.path_to( current['name'], viewport['name'], 'candidate.png') # Create the folder structure if it doesn't already exist @@ -89,7 +89,7 @@ def resolve_viewports(example) print "Checking \"#{current['name']}\" at [#{viewport['name']}]... " # Run the diff if needed - baseline_file = LikadanUtils.path_to(current['name'], viewport['name'], 'baseline.png') + baseline_file = DiffuxCIUtils.path_to(current['name'], viewport['name'], 'baseline.png') if File.exist? baseline_file comparison = Diffux::SnapshotComparer.new( @@ -98,7 +98,7 @@ def resolve_viewports(example) ).compare! if img = comparison[:diff_image] - diff_output = LikadanUtils.path_to(current['name'], viewport['name'], 'diff.png') + diff_output = DiffuxCIUtils.path_to(current['name'], viewport['name'], 'diff.png') img.save(diff_output) puts "#{comparison[:diff_in_percent].round(1)}% (#{diff_output})" else diff --git a/lib/likadan_server.rb b/lib/diffux_ci_server.rb similarity index 53% rename from lib/likadan_server.rb rename to lib/diffux_ci_server.rb index f6042d8..76fd133 100644 --- a/lib/likadan_server.rb +++ b/lib/diffux_ci_server.rb @@ -1,21 +1,21 @@ require 'sinatra/base' require 'yaml' -require 'likadan_utils' -require 'likadan_action' +require 'diffux_ci_utils' +require 'diffux_ci_action' -class LikadanServer < Sinatra::Base +class DiffuxCIServer < Sinatra::Base configure do enable :static - set :port, LikadanUtils.config['port'] + set :port, DiffuxCIUtils.config['port'] end get '/' do - @config = LikadanUtils.config + @config = DiffuxCIUtils.config erb :index end get '/review' do - @snapshots = LikadanUtils.current_snapshots + @snapshots = DiffuxCIUtils.current_snapshots erb :review end @@ -29,12 +29,12 @@ class LikadanServer < Sinatra::Base end post '/reject' do - LikadanAction.new(params[:name], params[:viewport]).reject + DiffuxCIAction.new(params[:name], params[:viewport]).reject redirect back end post '/approve' do - LikadanAction.new(params[:name], params[:viewport]).approve + DiffuxCIAction.new(params[:name], params[:viewport]).approve redirect back end diff --git a/lib/likadan_uploader.rb b/lib/diffux_ci_uploader.rb similarity index 75% rename from lib/likadan_uploader.rb rename to lib/diffux_ci_uploader.rb index 8ef0ed6..9e81d90 100644 --- a/lib/likadan_uploader.rb +++ b/lib/diffux_ci_uploader.rb @@ -1,17 +1,17 @@ -require 'likadan_utils' +require 'diffux_ci_utils' require 's3' require 'securerandom' -class LikadanUploader - BUCKET_NAME = 'likadan-diffs' +class DiffuxCIUploader + BUCKET_NAME = 'diffux_ci-diffs' def initialize - @s3_access_key_id = LikadanUtils.config['s3_access_key_id'] - @s3_secret_access_key = LikadanUtils.config['s3_secret_access_key'] + @s3_access_key_id = DiffuxCIUtils.config['s3_access_key_id'] + @s3_secret_access_key = DiffuxCIUtils.config['s3_secret_access_key'] end def upload_diffs - current_snapshots = LikadanUtils.current_snapshots + current_snapshots = DiffuxCIUtils.current_snapshots return [] if current_snapshots[:diffs].empty? bucket = find_or_build_bucket @@ -31,7 +31,7 @@ def upload_diffs html.content = ERB.new( File.read(File.expand_path( - File.join(File.dirname(__FILE__), 'likadan-diffs.html.erb'))) + File.join(File.dirname(__FILE__), 'diffux_ci-diffs.html.erb'))) ).result(binding) html.content_type = 'text/html' html.save diff --git a/lib/likadan_utils.rb b/lib/diffux_ci_utils.rb similarity index 85% rename from lib/likadan_utils.rb rename to lib/diffux_ci_utils.rb index 3f6a3e1..4a57ae3 100644 --- a/lib/likadan_utils.rb +++ b/lib/diffux_ci_utils.rb @@ -1,7 +1,7 @@ require 'yaml' require 'erb' -class LikadanUtils +class DiffuxCIUtils def self.config @@config ||= { 'snapshots_folder' => './snapshots', @@ -24,7 +24,7 @@ def self.config } } }.merge(YAML.load(ERB.new(File.read( - ENV['LIKADAN_CONFIG_FILE'] || '.likadan.yaml')).result)) + ENV['DIFFUX_CI_CONFIG_FILE'] || '.diffux_ci.yaml')).result)) end def self.normalize_name(name) @@ -61,8 +61,8 @@ def self.current_snapshots file: file, } end - diff_files = Dir.glob("#{LikadanUtils.config['snapshots_folder']}/**/diff.png") - baselines = Dir.glob("#{LikadanUtils.config['snapshots_folder']}/**/baseline.png") + diff_files = Dir.glob("#{DiffuxCIUtils.config['snapshots_folder']}/**/diff.png") + baselines = Dir.glob("#{DiffuxCIUtils.config['snapshots_folder']}/**/baseline.png") { diffs: diff_files.map(&prepare_file), baselines: baselines.map(&prepare_file) diff --git a/lib/likadan_action.rb b/lib/likadan_action.rb deleted file mode 100644 index 0a9fa08..0000000 --- a/lib/likadan_action.rb +++ /dev/null @@ -1,29 +0,0 @@ -require 'likadan_utils' -require 'fileutils' - -class LikadanAction - def initialize(example_name, viewport_name) - @example_name = example_name - @viewport_name = viewport_name - end - - def approve - diff_path = LikadanUtils.path_to(@example_name, @viewport_name, 'diff.png') - baseline_path = LikadanUtils.path_to(@example_name, @viewport_name, 'baseline.png') - candidate_path = LikadanUtils.path_to(@example_name, @viewport_name, 'candidate.png') - - FileUtils.rm(diff_path, force: true) - - if File.exist? candidate_path - FileUtils.mv(candidate_path, baseline_path) - end - end - - def reject - diff_path = LikadanUtils.path_to(@example_name, @viewport_name, 'diff.png') - candidate_path = LikadanUtils.path_to(@example_name, @viewport_name, 'candidate.png') - - FileUtils.rm(diff_path, force: true) - FileUtils.rm(candidate_path, force: true) - end -end diff --git a/lib/public/likadan-runner.js b/lib/public/diffux_ci-runner.js similarity index 95% rename from lib/public/likadan-runner.js rename to lib/public/diffux_ci-runner.js index 555cae2..aef962a 100644 --- a/lib/public/likadan-runner.js +++ b/lib/public/diffux_ci-runner.js @@ -1,4 +1,4 @@ -window.likadan = { +window.diffux = { defined: [], currentIndex: 0, currentExample: undefined, @@ -65,7 +65,7 @@ window.likadan = { }, /** - * @param {Function} func The likadan.describe function from the current + * @param {Function} func The diffux.describe function from the current * example being rendered. This function takes a callback as an argument * that is called when it is done. * @return {Promise} @@ -98,7 +98,7 @@ window.likadan = { /** * @param {Function} doneFunc injected by driver.execute_async_script in - * likadan_runner.rb + * diffux_ci_runner.rb */ renderCurrent: function(doneFunc) { try { @@ -168,8 +168,8 @@ window.addEventListener('load', function() { return; } var example = decodeURIComponent(matches[1]); - window.likadan.setCurrent(example); - window.likadan.renderCurrent(); + window.diffux.setCurrent(example); + window.diffux.renderCurrent(); }); // We need to redefine a few global functions that halt execution. Without this, @@ -187,5 +187,5 @@ window.prompt = function(message, value) { }; window.onerror = function(message, url, lineNumber) { - window.likadan.errors.push({ message: message, url: url, lineNumber: lineNumber }); + window.diffux.errors.push({ message: message, url: url, lineNumber: lineNumber }); } diff --git a/lib/views/index.erb b/lib/views/index.erb index f229865..53d2401 100644 --- a/lib/views/index.erb +++ b/lib/views/index.erb @@ -18,7 +18,7 @@ <% end %> - + <% @config['source_files'].each do |source_file| %> <% end %> diff --git a/lib/views/review.erb b/lib/views/review.erb index 0b6cd56..2724a65 100644 --- a/lib/views/review.erb +++ b/lib/views/review.erb @@ -12,7 +12,7 @@ -

Likadan Review Tool

+

Diffux-CI Review Tool

DIFFS

<% @snapshots[:diffs].each do |diff| %>

diff --git a/spec/likadan_spec.rb b/spec/diffux_ci_spec.rb similarity index 85% rename from spec/likadan_spec.rb rename to spec/diffux_ci_spec.rb index f535d89..e7f77e9 100644 --- a/spec/likadan_spec.rb +++ b/spec/diffux_ci_spec.rb @@ -2,7 +2,7 @@ require 'tmpdir' require 'open3' -describe 'likadan' do +describe 'diffux_ci' do let(:config) do { 'source_files' => ['examples.js'] @@ -12,7 +12,7 @@ let(:example_config) { '{}' } let(:examples_js) { <<-EOS } - likadan.define('foo', function() { + diffux.define('foo', function() { var elem = document.createElement('div'); elem.innerHTML = 'Foo'; document.body.appendChild(elem); @@ -23,7 +23,7 @@ before do @tmp_dir = Dir.mktmpdir - File.open(File.join(@tmp_dir, '.likadan.yaml'), 'w') do |f| + File.open(File.join(@tmp_dir, '.diffux_ci.yaml'), 'w') do |f| f.write(config.to_yaml) end @@ -36,11 +36,11 @@ FileUtils.remove_entry_secure @tmp_dir end - def run_likadan + def run_diffux_ci pwd = Dir.pwd Dir.chdir @tmp_dir do std_out, std_err, status = - Open3.capture3("ruby -I#{pwd}/lib #{pwd}/bin/likadan") + Open3.capture3("ruby -I#{pwd}/lib #{pwd}/bin/diffux_ci") { std_out: std_out, std_err: std_err, @@ -57,11 +57,11 @@ def snapshot_file_exists?(size, file_name) describe 'with no previous run' do it 'exits with a zero exit code' do - expect(run_likadan[:exit_status]).to be(0) + expect(run_diffux_ci[:exit_status]).to be(0) end it 'generates a baseline, but no diff' do - run_likadan + run_diffux_ci expect(snapshot_file_exists?('@large', 'baseline.png')).to be(true) expect(snapshot_file_exists?('@large', 'diff.png')).to be(false) expect(snapshot_file_exists?('@large', 'candidate.png')).to be(false) @@ -71,15 +71,15 @@ def snapshot_file_exists?(size, file_name) describe 'with a previous run' do context 'and no diff' do before do - run_likadan + run_diffux_ci end it 'exits with a zero exit code' do - expect(run_likadan[:exit_status]).to be(0) + expect(run_diffux_ci[:exit_status]).to be(0) end it 'keeps the baseline, and creates no diff' do - run_likadan + run_diffux_ci expect(snapshot_file_exists?('@large', 'baseline.png')).to be(true) expect(snapshot_file_exists?('@large', 'diff.png')).to be(false) expect(snapshot_file_exists?('@large', 'candidate.png')).to be(false) @@ -88,16 +88,16 @@ def snapshot_file_exists?(size, file_name) context 'and there is a diff' do it 'exits with a zero exit code' do - expect(run_likadan[:exit_status]).to be(0) + expect(run_diffux_ci[:exit_status]).to be(0) end context 'and the baseline has height' do before do - run_likadan + run_diffux_ci File.open(File.join(@tmp_dir, 'examples.js'), 'w') do |f| f.write(<<-EOS) - likadan.define('foo', function() { + diffux.define('foo', function() { var elem = document.createElement('div'); elem.innerHTML = 'Football'; document.body.appendChild(elem); @@ -108,7 +108,7 @@ def snapshot_file_exists?(size, file_name) end it 'keeps the baseline, and generates a diff' do - run_likadan + run_diffux_ci expect(snapshot_file_exists?('@large', 'baseline.png')).to be(true) expect(snapshot_file_exists?('@large', 'diff.png')).to be(true) expect(snapshot_file_exists?('@large', 'candidate.png')).to be(true) @@ -118,7 +118,7 @@ def snapshot_file_exists?(size, file_name) context 'and the baseline does not have height' do let(:examples_js) { <<-EOS } - likadan.define('foo', function() { + diffux.define('foo', function() { var elem = document.createElement('div'); document.body.appendChild(elem); return elem; @@ -126,11 +126,11 @@ def snapshot_file_exists?(size, file_name) EOS before do - run_likadan + run_diffux_ci File.open(File.join(@tmp_dir, 'examples.js'), 'w') do |f| f.write(<<-EOS) - likadan.define('foo', function() { + diffux.define('foo', function() { var elem = document.createElement('div'); elem.innerHTML = 'Foo'; document.body.appendChild(elem); @@ -141,7 +141,7 @@ def snapshot_file_exists?(size, file_name) end it 'keeps the baseline, and generates a diff' do - run_likadan + run_diffux_ci expect(snapshot_file_exists?('@large', 'baseline.png')).to be(true) expect(snapshot_file_exists?('@large', 'diff.png')).to be(true) expect(snapshot_file_exists?('@large', 'candidate.png')).to be(true) @@ -153,14 +153,14 @@ def snapshot_file_exists?(size, file_name) let(:example_config) { "{ viewports: ['large', 'small'] }" } it 'generates the right baselines' do - run_likadan + run_diffux_ci expect(snapshot_file_exists?('@large', 'baseline.png')).to be(true) expect(snapshot_file_exists?('@small', 'baseline.png')).to be(true) expect(snapshot_file_exists?('@medium', 'baseline.png')).to be(false) end end - describe 'with custom viewports in .likadan.yaml' do + describe 'with custom viewports in .diffux_ci.yaml' do let(:config) do { 'source_files' => ['examples.js'], @@ -179,7 +179,7 @@ def snapshot_file_exists?(size, file_name) context 'and the example has no `viewport` config' do it 'uses the first viewport in the config' do - run_likadan + run_diffux_ci expect(snapshot_file_exists?('@foo', 'baseline.png')).to be(true) expect(snapshot_file_exists?('@bar', 'baseline.png')).to be(false) end @@ -189,7 +189,7 @@ def snapshot_file_exists?(size, file_name) let(:example_config) { "{ viewports: ['bar'] }" } it 'uses the viewport to generate a baseline' do - run_likadan + run_diffux_ci expect(snapshot_file_exists?('@foo', 'baseline.png')).to be(false) expect(snapshot_file_exists?('@bar', 'baseline.png')).to be(true) end @@ -198,7 +198,7 @@ def snapshot_file_exists?(size, file_name) describe 'with doneCallback async argument' do let(:examples_js) { <<-EOS } - likadan.define('foo', function(done) { + diffux.define('foo', function(done) { setTimeout(function() { var elem = document.createElement('div'); elem.innerHTML = 'Foo'; @@ -209,7 +209,7 @@ def snapshot_file_exists?(size, file_name) EOS it 'generates a baseline, but no diff' do - run_likadan + run_diffux_ci expect(snapshot_file_exists?('@large', 'baseline.png')).to be(true) expect(snapshot_file_exists?('@large', 'diff.png')).to be(false) expect(snapshot_file_exists?('@large', 'candidate.png')).to be(false) @@ -218,11 +218,11 @@ def snapshot_file_exists?(size, file_name) describe 'with a previous run' do context 'and no diff' do before do - run_likadan + run_diffux_ci end it 'keeps the baseline, and creates no diff' do - run_likadan + run_diffux_ci expect(snapshot_file_exists?('@large', 'baseline.png')).to be(true) expect(snapshot_file_exists?('@large', 'diff.png')).to be(false) expect(snapshot_file_exists?('@large', 'candidate.png')).to be(false) @@ -232,11 +232,11 @@ def snapshot_file_exists?(size, file_name) context 'and there is a diff' do context 'and the baseline has height' do before do - run_likadan + run_diffux_ci File.open(File.join(@tmp_dir, 'examples.js'), 'w') do |f| f.write(<<-EOS) - likadan.define('foo', function(done) { + diffux.define('foo', function(done) { setTimeout(function() { var elem = document.createElement('div'); elem.innerHTML = 'Football'; @@ -249,7 +249,7 @@ def snapshot_file_exists?(size, file_name) end it 'keeps the baseline, and generates a diff' do - run_likadan + run_diffux_ci expect(snapshot_file_exists?('@large', 'baseline.png')).to be(true) expect(snapshot_file_exists?('@large', 'diff.png')).to be(true) expect(snapshot_file_exists?('@large', 'candidate.png')).to be(true) @@ -261,17 +261,17 @@ def snapshot_file_exists?(size, file_name) describe 'when an example fails' do let(:examples_js) { <<-EOS } - likadan.define('foo', function() { + diffux.define('foo', function() { return undefined; }); EOS it 'exits with a non-zero exit code' do - expect(run_likadan[:exit_status]).to be(1) + expect(run_diffux_ci[:exit_status]).to be(1) end it 'logs the error' do - expect(run_likadan[:std_err]).to include('Error while rendering "foo"') + expect(run_diffux_ci[:std_err]).to include('Error while rendering "foo"') end end end