From f9386e3b853ba219316ebd5a4ff63bf9a1f7c4e6 Mon Sep 17 00:00:00 2001 From: Angelika Tyborska Date: Sun, 2 Jun 2024 17:48:45 +0200 Subject: [PATCH] Add smoke test --- .github/workflows/test.yml | 14 ++++++- bin/smoke_test.exs | 41 +++++++++++++++++++ demo/mix.exs | 2 +- .../demo_web/integration/pages_hound_test.exs | 2 +- .../integration/pages_wallaby_test.exs | 2 +- mix.exs | 4 +- 6 files changed, 58 insertions(+), 7 deletions(-) create mode 100755 bin/smoke_test.exs diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9cc6f38..bc082ff 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -77,8 +77,18 @@ 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 --url-base=/wd/hub & + sudo Xvfb -ac :99 -screen 0 1280x1024x24 > /dev/null 2>&1 & # optional + + - 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 diff --git a/bin/smoke_test.exs b/bin/smoke_test.exs new file mode 100755 index 0000000..1f65879 --- /dev/null +++ b/bin/smoke_test.exs @@ -0,0 +1,41 @@ +# 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.

Angelika's Star Trek series ranking

") + check_output.(output, "... and 10 more nodes") +end) + +IO.puts("all good") diff --git a/demo/mix.exs b/demo/mix.exs index 0a629ae..cbc3cf9 100644 --- a/demo/mix.exs +++ b/demo/mix.exs @@ -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(), diff --git a/demo/test/demo_web/integration/pages_hound_test.exs b/demo/test/demo_web/integration/pages_hound_test.exs index cfe597a..3c9a958 100644 --- a/demo/test/demo_web/integration/pages_hound_test.exs +++ b/demo/test/demo_web/integration/pages_hound_test.exs @@ -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 diff --git a/demo/test/demo_web/integration/pages_wallaby_test.exs b/demo/test/demo_web/integration/pages_wallaby_test.exs index 8c0e6e6..ed55ae1 100644 --- a/demo/test/demo_web/integration/pages_wallaby_test.exs +++ b/demo/test/demo_web/integration/pages_wallaby_test.exs @@ -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 diff --git a/mix.exs b/mix.exs index 2752a39..8b19ecc 100644 --- a/mix.exs +++ b/mix.exs @@ -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: %{