Skip to content

Commit

Permalink
Quick demo
Browse files Browse the repository at this point in the history
  • Loading branch information
kevindew committed Dec 14, 2020
1 parent 88c258e commit 87bc88c
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/visual-regression-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ jobs:
- run: yarn install --frozen-lockfile
- uses: percy/[email protected]
with:
command: bundle exec rspec ./spec/visual_regression_tests/all_components.rb
command: bundle exec rake visual_regression_tests
env:
PERCY_TOKEN: ${{ secrets.PERCY_TOKEN }}
4 changes: 4 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@ task lint: %i[rubocop environment] do
sh "yarn run lint"
end

task :visual_regression_tests do
sh "bin/visual_regression_tests"
end

task default: [:lint, :spec, "app:jasmine:ci"]
66 changes: 66 additions & 0 deletions bin/visual_regression_tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env ruby

require "rubygems"
require "bundler/setup"

ENV["RAILS_ENV"] ||= "test"

require File.expand_path("../spec/dummy/config/environment", __dir__)

require "capybara/rails"
require "govuk_test"
require "active_support/testing/time_helpers"
require "uri"
require "percy"

GovukTest.configure
Capybara.configure do |config|
config.default_driver = :headless_chrome
config.default_max_wait_time = 10
end

class VisualRegressionTestRunner
include Capybara::DSL
include ActiveSupport::Testing::TimeHelpers

COMPONENTS_TO_SKIP = [
# not visible
"/component-guide/meta_tags",
"/component-guide/machine_readable_metadata",
"/component-guide/admin_analytics",
"/component-guide/google_tag_manager_script",
"/component-guide/layout_for_admin",
# times out
"/component-guide/govspeak",
].freeze

def self.call
new.call
end

def call
travel_to(Time.zone.local(2020, 12, 1, 6, 0, 0)) do
visit("/component-guide")

find("#list-all-components-in-the-gem")
.all("a")
.map { |link| URI(link[:href]).path }
.reject { |path| COMPONENTS_TO_SKIP.include?(path) }
.each { |path| test(path) }
end
end

def test(path)
visit("#{path}/preview")
name = title.gsub(/(: Default|) preview - Component Guide/, "")

if page.find(:css, "#wrapper")
puts "Screenshotting #{name}"
page.save_screenshot("#{name}.png")
else
puts "Failed to screenshot #{name}"
end
end
end

VisualRegressionTestRunner.call

0 comments on commit 87bc88c

Please sign in to comment.