The Rails application uses RSpec and RuboCop for testing and linting, as well as Brakeman for security scanning and Slim-Lint to lint Slim templates.
# Run tests and linting
bundle exec rake
# Run tests only
bundle exec rspec
# Run linters only
bundle exec rails lint
The frontend Javascript code uses Jest and ESLint for testing and linting (using Airbnb rules), as well as Stylelint for SASS linting (with the default ruleset):
# Run tests and linting
yarn test
# Run tests only
yarn run js:test
# Generate a coverage report
yarn run js:test:coverage
# Run JS linter only
yarn run js:lint
# Run SASS linter only
yarn run sass:lint
The service include parallel_tests gem, that allows to split the RSpec test suite run accross multiple CPU cores.
Each group will run against a separate database. To set it up:
RAILS_ENV=test rails parallel:create
To run the test suite in parallel:
RAILS_ENV=test rake parallel:spec
or
RAILS_ENV=test rails parallel:spec
or using Spring binstub:
parallel_rspec
The visual layout and appearance of defined scenarios (pages and common content) can be tested using BackstopJS
This works by testing snapshot images in a branch or environment against accepted baseline/reference snapshot images. Tests are run across 3 viewports - mobile, tablet and desktop. Also if abtest variants are added to config/ab_test.yml
then the corresponding page will be tested with each variant.
This is currently a tool for developers to test changes locally against the QA environment. Running the test suite will create and load a UI in the browser to report on and for you to compare visual changes.
Install the backstopjs library as a global dependency
npm install -g [email protected]
Add the following variables to your local .env
file:
VISUAL_TEST_JOBSEEKER_USERNAME=xxx
VISUAL_TEST_JOBSEEKER_PASSWORD=xxx
VISUAL_TEST_PUBLISHER_USERNAME=xxx
VISUAL_TEST_PUBLISHER_PASSWORD=xxx
If you have never run tests before, ensure you have created an backstop/lib/.tmp
folder for authentication tokens. (TODO could do with automating)
# Create reference snapshot images
yarn run visual:test:init
# Run test suite to compare your changes to reference snapshots
yarn run visual:test:run
# approve changes
yarn run visual:test:approve
This will approve changes to create new baseline snapshots and clear your file system of snapshots created by previous test suite runs.