Skip to content

Commit

Permalink
Lots of spec refactoring - rack 3 + screenshots
Browse files Browse the repository at this point in the history
* chrome screenshots work
* migrate to rack 3 🎉
* add a spec summary function to github CI
  • Loading branch information
cycomachead committed Aug 13, 2024
1 parent ff29565 commit 3ca67ce
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .rspec
Original file line number Diff line number Diff line change
@@ -1 +1 @@
--require spec_helper
-f progress -f documentation --out tmp/rspec_output.txt -f json --out tmp/rspec_output.json -f html --out tmp/rspec_output.html
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ group :development, :test do
gem 'axe-core-rspec'
gem 'capybara'
gem 'capybara-screenshot'
gem 'rack', '< 3'
gem 'rack'
gem 'rackup'
gem 'rspec'
gem 'selenium-webdriver'
end
Expand Down
49 changes: 27 additions & 22 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ GEM
coercible (1.0.0)
descendants_tracker (~> 0.0.1)
colorator (1.1.0)
concurrent-ruby (1.3.3)
concurrent-ruby (1.3.4)
descendants_tracker (0.0.4)
thread_safe (~> 0.3, >= 0.3.1)
diff-lcs (1.5.1)
Expand All @@ -57,13 +57,13 @@ GEM
ffi (1.17.0-x86_64-darwin)
ffi (1.17.0-x86_64-linux-gnu)
forwardable-extended (2.6.0)
google-protobuf (4.27.1-arm64-darwin)
google-protobuf (4.27.3-arm64-darwin)
bigdecimal
rake (>= 13)
google-protobuf (4.27.1-x86_64-darwin)
google-protobuf (4.27.3-x86_64-darwin)
bigdecimal
rake (>= 13)
google-protobuf (4.27.1-x86_64-linux)
google-protobuf (4.27.3-x86_64-linux)
bigdecimal
rake (>= 13)
http_parser.rb (0.8.0)
Expand Down Expand Up @@ -100,7 +100,7 @@ GEM
jekyll-watch (2.2.1)
listen (~> 3.0)
json (2.7.2)
just-the-docs (0.8.2)
just-the-docs (0.9.0)
jekyll (>= 3.8.5)
jekyll-include-cache
jekyll-seo-tag (>= 2.0)
Expand Down Expand Up @@ -132,24 +132,27 @@ GEM
octokit (6.1.1)
faraday (>= 1, < 3)
sawyer (~> 0.9)
parallel (1.25.1)
parser (3.3.3.0)
parallel (1.26.2)
parser (3.3.4.2)
ast (~> 2.4.1)
racc
pathutil (0.16.2)
forwardable-extended (~> 2.6)
public_suffix (6.0.1)
racc (1.8.1)
rack (2.2.9)
rack (3.1.7)
rack-test (2.1.0)
rack (>= 1.3)
rackup (2.1.0)
rack (>= 3)
webrick (~> 1.8)
rainbow (3.1.1)
rake (13.2.1)
rb-fsevent (0.11.2)
rb-inotify (0.11.1)
ffi (~> 1.0)
regexp_parser (2.9.2)
rexml (3.3.0)
rexml (3.3.5)
strscan
rouge (4.3.0)
rspec (3.13.0)
Expand All @@ -165,37 +168,38 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-support (3.13.1)
rubocop (1.64.1)
rubocop (1.65.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
regexp_parser (>= 2.4, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.31.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.31.3)
rubocop-ast (1.32.0)
parser (>= 3.3.1.0)
rubocop-capybara (2.21.0)
rubocop (~> 1.41)
rubocop-rspec (3.0.1)
rubocop-rspec (3.0.4)
rubocop (~> 1.61)
ruby-progressbar (1.13.0)
rubyzip (2.3.2)
safe_yaml (1.0.5)
sass-embedded (1.77.5-arm64-darwin)
google-protobuf (>= 3.25, < 5.0)
sass-embedded (1.77.5-x86_64-darwin)
google-protobuf (>= 3.25, < 5.0)
sass-embedded (1.77.5-x86_64-linux-gnu)
google-protobuf (>= 3.25, < 5.0)
sass-embedded (1.77.8-arm64-darwin)
google-protobuf (~> 4.26)
sass-embedded (1.77.8-x86_64-darwin)
google-protobuf (~> 4.26)
sass-embedded (1.77.8-x86_64-linux-gnu)
google-protobuf (~> 4.26)
sawyer (0.9.2)
addressable (>= 2.3.5)
faraday (>= 0.17.3, < 3)
selenium-webdriver (4.21.1)
selenium-webdriver (4.23.0)
base64 (~> 0.2)
logger (~> 1.4)
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2, < 3.0)
websocket (~> 1.0)
Expand All @@ -210,7 +214,7 @@ GEM
coercible (~> 1.0)
descendants_tracker (~> 0.0, >= 0.0.3)
webrick (1.8.1)
websocket (1.2.10)
websocket (1.2.11)
xpath (3.2.0)
nokogiri (~> 1.8)

Expand All @@ -230,7 +234,8 @@ DEPENDENCIES
jekyll-sitemap
just-the-docs
kramdown-parser-gfm
rack (< 3)
rack
rackup
rspec
rubocop
rubocop-capybara
Expand Down
8 changes: 4 additions & 4 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
require 'rspec'
require 'rack'
require 'yaml'
require 'webrick'

require 'capybara/rspec'
require 'capybara/dsl'
Expand Down Expand Up @@ -68,7 +69,7 @@ class StaticSite
# TODO: Rack::File will be deprecated soon. Find a better solution.
def initialize(root)
@root = root
@server = Rack::File.new(root)
@server = Rack::Files.new(root)
end

def call(env)

Check warning on line 75 in spec/spec_helper.rb

View workflow job for this annotation

GitHub Actions / runner / rubocop

[rubocop] reported by reviewdog 🐶 Assignment Branch Condition size for call is too high. [<6, 20, 7> 22.02/17] Raw Output: spec/spec_helper.rb:75:3: C: Metrics/AbcSize: Assignment Branch Condition size for call is too high. [<6, 20, 7> 22.02/17]

Check warning on line 75 in spec/spec_helper.rb

View workflow job for this annotation

GitHub Actions / runner / rubocop

[rubocop] reported by reviewdog 🐶 Method has too many lines. [12/10] Raw Output: spec/spec_helper.rb:75:3: C: Metrics/MethodLength: Method has too many lines. [12/10]
Expand Down Expand Up @@ -101,8 +102,8 @@ def exists?(path)
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
# macbook air ~13" screen size
options.add_argument('--window-size=1280,800')
# macbook air ~13" screen size, with an absurd height for full size screenshots.
options.add_argument('--window-size=1280,4000')

Capybara::Selenium::Driver.new(app, browser: :chrome, options:)
end
Expand All @@ -113,7 +114,6 @@ def exists?(path)
Capybara.javascript_driver = :chrome_headless

Capybara::Screenshot.register_driver(:chrome_headless) do |driver, path|
# driver.browser.save_screenshot(path, full: true)
driver.save_screenshot(path)
end

Expand Down
69 changes: 69 additions & 0 deletions spec/support/spec_summary.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# frozen_string_literal: true

# Summarize the axe rspec failures into aggregate counts
# TODO: This should be an RSpec formatter

require 'json'
require 'pp'

Check warning on line 7 in spec/support/spec_summary.rb

View workflow job for this annotation

GitHub Actions / runner / rubocop

[rubocop] reported by reviewdog 🐶 Remove unnecessary `require` statement. Raw Output: spec/support/spec_summary.rb:7:1: W: Lint/RedundantRequireStatement: Remove unnecessary `require` statement.

RESULTS_PATH = File.join(File.dirname(__FILE__), '..', '..', 'tmp/rspec_output.json')
AXE_CASE_TITLE = /\n\s*\n\s*\d+\)\s+([-\w]+):/


def failing_specs(results_data)
results_data['examples'].filter do |ex|
ex['status'] == 'failed'
end
end

def summarize_results(results)
failing_specs(results).map do |ex|
ex['exception']['message'].scan(AXE_CASE_TITLE)
end.flatten.tally
end

def group_results(results)
all_cases_list = failing_specs(results).map do |ex|
msg = ex['exception']['message']
msg.gsub!(/\nInvocation:.*;/, '')
cases = msg.split(AXE_CASE_TITLE)
cases.delete_at(0)
Hash[*cases].transform_values { |v| { page: ex['full_description'], message: v }}
end
results = Hash.new
results.default = []
all_cases_list.each do |test_hash|
test_hash.each do |axe_name, failure|
if results.has_key?(axe_name)
results[axe_name] << failure
else
results[axe_name] = [ failure ]
end
end
end
results
end

def test_failures_with_pages(summary_group)
summary_group.transform_values { |list| list.map { |h| h[:page] } }
end

def nicely_print(hash)
hash.each do |key, values|
puts "#{key}:"
values.each { |item| puts("\t#{item}") }
end
end

def print_summary
results_data = JSON.parse(File.read(RESULTS_PATH))
failing_tests_by_type = summarize_results(results_data)
pp(failing_tests_by_type)
puts "Total: #{failing_tests_by_type.values.sum} failures."

puts "\n#{'-'*16}"
summary_group = group_results(results_data)
nicely_print(test_failures_with_pages(summary_group))
end

print_summary

0 comments on commit 3ca67ce

Please sign in to comment.