Skip to content

Testing the application

Matt Smith edited this page Jan 24, 2020 · 2 revisions

The entire test suite for the application can be triggered by running the command:

npm test

Linting

The application uses Javascript Standard Style. Visit the project website https://standardjs.com for more information and documentation. Plugins are available for various text editors.

Linting can be run with the command:

npm run test:lint

Unit tests

The application uses Tape, Sinon and Proxyquire for unit testing.

Unit tests are located adjacent to the code that they are testing. All unit tests can be run by running the command:

npm run test:unit

The application will look for tests in these locations:

  • ./src/config/**/*.test.js
  • ./src/web/**/*.test.js

Files containing unit tests must use the naming convention *.test.js.

Acceptance and compatibility tests

Acceptance & compatibility tests are provided by a separate repository htbhf-acceptance-tests. The tests consume features.json to enable feature toggling.

Setting the acceptance tests version number

The application can be configured to run a certain version of htbhf-acceptance-tests by setting a version number in test_versions.properties.

Running acceptance tests locally

To run a local version of local htbhf-acceptance-tests, create a local_acceptance_tests.properties file at the root level of the application and specify the version of chromedriver and the location of htbhf-acceptance-tests:

// local_acceptance_tests.properties

CHROMEDRIVER_VERSION=76.0.3809.68
# if you're not using chromedriver_linux64, also specify CHROMEDRIVER_URL:
CHROMEDRIVER_URL=https://chromedriver.storage.googleapis.com/76.0.3809.68/chromedriver_linux64.zip
# if you want to use a local copy of the acceptance tests:
USE_LOCAL_ACCEPTANCE_TESTS=true
ACCEPTANCE_TESTS_DIR=../htbhf-acceptance-tests

Performance tests

Performance tests are provided by a separate repository htbhf-performance-tests. The tests consume features.json to enable feature toggling.

Setting the performance tests version number

The application can be configured to run a certain version of htbhf-performance-tests by setting a version number in test_versions.properties.

A11y tests

The application uses Pa11y and Wiremock to run a11y tests.

A11y tests are defined in test/a11y/tests directory. A test is defined as an array of javascript objects that represent the pages to be tested. This allows the tests to progress through a journey, iteratively testing each page.

A page object is defined using the following schema:

Property Type Description
url string URL of page to run a11y test against
formData (requestCookie) => {} A function that returns data to POST to the server for the page under test. The function has access to the request cookie
issueChecks (url, result) => ?string [] An array of custom test functions

issueChecks

The issueChecks property should be an array of issue checking functions that take the following format:

function myIssueCheck (url, result) {
  return result.documentTitle !== EXPECTED_TITLE
    ? `Expected title to be ${EXPECTED_TITLE}, instead got ${result.documentTitle}`
    : null
}

A checker function has access to the URL under test and the result object created by Pa11y. Returning a string will cause the test to record an a11y issue. If null is returned then no issue is recorded.

Clone this wiki locally