Skip to content

Commit

Permalink
Add smoke test
Browse files Browse the repository at this point in the history
  • Loading branch information
angelikatyborska committed Jun 2, 2024
1 parent 10b8a0c commit 503ee3f
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 7 deletions.
13 changes: 11 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,17 @@ jobs:
- name: Run tests
run: mix test

# - name: Run smoke tests
# run: elixir ./bin/smoke_test.exs
- name: Set up Chromedriver
uses: nanasess/setup-chromedriver@v2
- run: |
export DISPLAY=:99
chromedriver &
- name: Set up demo project
run: cd demo && mix deps.get

- name: Run smoke tests
run: elixir ./bin/smoke_test.exs

- name: Check for compilation warnings
run: mix compile --force --no-warnings
Expand Down
43 changes: 43 additions & 0 deletions bin/smoke_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# assumes Chromedriver is running

IO.puts("Running smoke tests")
IO.puts("\n\n")

check_output = fn (output, pattern) ->
if not (output =~ pattern) do
IO.puts("Expected test output to match pattern:")
IO.inspect(pattern)
IO.puts("Full output")
IO.inspect(output)
exit 1
end
end

demo_project_path = "./demo"
demo_test_files =
[
"test/demo_web/integration/pages_wallaby_test.exs",
"test/demo_web/integration/pages_hound_test.exs"
]

Enum.each(demo_test_files, fn demo_test_file ->
IO.puts("checking #{demo_test_file}")

{output, 2} = System.cmd("mix", ["test", demo_test_file], cd: demo_project_path)

check_output.(output, ~r/3 (features|tests), 2 failures/)
check_output.(output, "invalid page with accessibility errors")
check_output.(output, "critical")
check_output.(output, "Images must have alternate text")
check_output.(output, "There is 1 node with this violation:")
check_output.(output, "dynamic invalid page with accessibility errors that only happen after interaction")
check_output.(output, "serious")
check_output.(output, "Elements must meet minimum color contrast ratio thresholds")
check_output.(output, "There are 13 nodes with this violation:")
check_output.(output, "1. <h1>Angelika's Star Trek series ranking</h1>")
check_output.(output, "... and 10 more nodes")

IO.puts("ok #{demo_test_file}")
end)

IO.puts("all ok")
2 changes: 1 addition & 1 deletion demo/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule Demo.MixProject do
[
app: :demo,
version: "0.1.0",
elixir: "~> 1.14",
elixir: "~> 1.13",
elixirc_paths: elixirc_paths(Mix.env()),
start_permanent: Mix.env() == :prod,
aliases: aliases(),
Expand Down
2 changes: 1 addition & 1 deletion demo/test/demo_web/integration/pages_hound_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ defmodule DemoWeb.PagesHoundTest do
article = find_element(:css, "article")
assert attribute_value(article, "style") == "background-color: rgb(34, 34, 34);"

A11yAudit.Hound.assert_no_violations()
A11yAudit.Hound.assert_no_violations(nodes_per_violation_print_limit: 3)
end
end
2 changes: 1 addition & 1 deletion demo/test/demo_web/integration/pages_wallaby_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ defmodule DemoWeb.PagesWallabyTest do
|> find(Query.css("article"), fn article ->
assert Element.attr(article, "style") == "background-color: rgb(34, 34, 34);"
end)
|> A11yAudit.Wallaby.assert_no_violations()
|> A11yAudit.Wallaby.assert_no_violations(nodes_per_violation_print_limit: 3)
end
end
4 changes: 2 additions & 2 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ defmodule A11yAudit.MixProject do
end

defp description() do
"Elixir formatter plugin for doctests."
"Automated accessibility checks for Elixir web apps, based on axe-core."
end

defp package() do
[
name: "doctest_formatter",
name: "a11y_audit",
files: ~w(lib priv .formatter.exs mix.exs README* LICENSE* CHANGELOG*),
licenses: ["MIT"],
links: %{
Expand Down

0 comments on commit 503ee3f

Please sign in to comment.