Running tests
You can run the following types of tests when building on VA.gov.
Prerequisite
- Run or build the application.
Test commands
Test type | Test all | Test one | Requires local build to run | Test target | Modules used |
---|---|---|---|---|---|
Unit | yarn test:unit | yarn test:unit ./PATH-TO-TEST-FILE | no | *.unit.spec.js(x) | Mocha, Chai, Sinon, JSDom, Enzyme |
Lint | yarn lint | yarn lint:js or yarn lint:sass | no | *.js , *.scss | ESLint, Prettier, sass-lint |
End to end | yarn test:e2e | yarn test:e2e ./PATH-TO-TEST-FILE | yes | *.e2e.spec.js | Nightwatch.js |
Accessibility | yarn test:accessibility | yes | all pages in sitemap.xml | Nightwatch.js |
Requires local build or run
Some tests require running or building VA.gov:
- Testing while running
watch
task: Tests will automatically be run against the site running on that server. - Testing with a local build: If nothing is running at
http://localhost:3001
(vets-website
testing) or,http://localhost:3002
(content-build
testing), tests start an Express server and serve the build output inbuild/localhost
.
Unit tests
- Run all Mocha/Chai/Sinon-based unit tests with the file extension
.unit.spec.js(x)
- Use JSDom and Enzyme to test browser and React behavior
- Are located in
test/
directories near the code they're testing insrc/
Linting
- Verify consistency of JavaScript
- Enforce code formatting rules
- Automatically run on
git commit
as a precommit hook
Set up your editor to show ESLint errors automatically as you're writing code. This makes the linter far less annoying in day to day use. ESLint has integrations for nearly all popular editors.
End to end tests
- Run all Nightwatch.js tests in headless Chrome with the file extension
.e2e.spec.js
- Simulate an actual user completing tasks in the tools and services
- Are located in
test/
directories near the application they're testing insrc/
End to end tests will only pass if they are run against their mock API server. This server is started by the end to end test automatically when vets-api is not running.
Accessibility tests
- A variation of e2e tests that run aXe against the content pages running in Chrome.