From bc66ca74b71e0f7387ce7617bf4d22b9c2d615e0 Mon Sep 17 00:00:00 2001 From: Kelvin Gan Date: Thu, 10 Sep 2026 16:54:14 +0100 Subject: [PATCH 1/2] Update axe (accessibility) checks to be skippable These are among our slowest tests, and barely change. Switching this to run by default on our infrastructure and not as part of local development where the tests are slowest to run. --- config/settings.yml | 5 +++++ lib/tasks/test.rake | 9 ++++++++- spec/support/axe_feature_helpers.rb | 12 ++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/config/settings.yml b/config/settings.yml index 4ba85a1bff..d0823d7033 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -53,6 +53,11 @@ govuk_notify: # When set to true, any capybara tests will run chrome normally rather than in headless mode. show_browser_during_tests: false +# Axe checks make feature specs significantly slower, so they can be skipped, e.g. for a +# faster local test run. Set to true in config/settings/test.local.yml or via the +# SETTINGS__SKIP_AXE_TESTS environment variable. Runs by default everywhere else, e.g. in CI. +skip_axe_tests: false + maintenance_mode: # When set to true, All pages will render 'Maintenance mode' message enabled: false diff --git a/lib/tasks/test.rake b/lib/tasks/test.rake index 20c136d4b8..91f645cb88 100644 --- a/lib/tasks/test.rake +++ b/lib/tasks/test.rake @@ -1,7 +1,14 @@ # frozen_string_literal: true -desc "Run tests" +desc "Run tests, including accessibility (axe) checks unless Settings.skip_axe_tests is set" task test: :environment do sh "bundle exec rspec" sh "npm run test" end + +namespace :test do + desc "Run only the accessibility (axe) checks within the feature specs" + task axe: :environment do + sh({ "SETTINGS__SKIP_AXE_TESTS" => "false" }, "bundle exec rspec spec/features") + end +end diff --git a/spec/support/axe_feature_helpers.rb b/spec/support/axe_feature_helpers.rb index 62e8c78b74..7bd32a9190 100644 --- a/spec/support/axe_feature_helpers.rb +++ b/spec/support/axe_feature_helpers.rb @@ -1,11 +1,23 @@ module AxeFeatureHelpers def expect_page_to_have_no_axe_errors(page) + return if skip_axe_tests? + expect(page).to be_axe_clean.according_to(:wcag2a, :wcag2aa, :wcag21a, :wcag21aa) end def expect_component_to_have_no_axe_errors(page) + return if skip_axe_tests? + expect(page).to be_axe_clean.within("#main-content").according_to(:wcag2a, :wcag2aa, :wcag21a, :wcag21aa) end + +private + + # Axe checks make feature specs significantly slower, so they can be skipped, e.g. for a + # faster local test run. See Settings.skip_axe_tests in config/settings.yml. + def skip_axe_tests? + Settings.skip_axe_tests + end end RSpec.configure do |config| From 924e9b75fe1b7a485c92cff5d8206e060da70c66 Mon Sep 17 00:00:00 2001 From: Kelvin Gan Date: Thu, 10 Sep 2026 16:56:54 +0100 Subject: [PATCH 2/2] Update documentation to cover way of running axe tests --- README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/README.md b/README.md index c60acdf100..c2f3dde8af 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,24 @@ The app tests are written with [rspec-rails] and you can run them with: bundle exec rspec ``` +This includes the [axe-core] accessibility checks within the feature specs by default (as does CI), though they are slow to run. To skip them locally, add a gitignored `config/settings/test.local.yml` with: + +```yaml +skip_axe_tests: true +``` + +or override it per-run: + +```bash +SETTINGS__SKIP_AXE_TESTS=true bundle exec rspec +``` + +`bundle exec rake test` (which also runs the frontend test suite) honours the same setting. To run just the feature specs with accessibility checks, without the rest of the suite, use: + +```bash +bundle exec rake test:axe +``` + There are also unit tests for JavaScript code (look for files named `*.test.js`), written with [Vitest]. You can run those with: ```bash @@ -65,6 +83,7 @@ npm run test ``` [rspec-rails]: https://github.com/rspec/rspec-rails +[axe-core]: https://github.com/dequelabs/axe-core-gems [Vitest]: https://vitest.dev/ ### Running the RSpec tests in parallel