generated from kevinlin1/just-the-class
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lots of spec refactoring - rack 3 + screenshots
* chrome screenshots work * migrate to rack 3 🎉 * add a spec summary function to github CI
- Loading branch information
1 parent
ff29565
commit 3ca67ce
Showing
5 changed files
with
103 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 GitHub Actions / runner / rubocop
|
||
|
||
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 |