Test an application
Ontario.ca Frontend includes a set of unit, integration, and end-to-end tests that allow you to make sure important project files exist and that your project behaves as expected.
You can run the tests by using the following command:
Unit and integration tests
npm run test
End-to-end tests
npm run test:e2e
npm run test:e2e –url={your-target-url}
You must have Google Chrome installed on your machine for the end-to-end tests to run.
Testing a customized project
From time to time, you may make changes to your project’s structure that deviate from what the testing suite expects. In those cases, you may need to adjust certain testing parameters to ensure that the tests still run.
Customized file names
If you change the English and French page names of the base English and French pages you created during the project setup process, you will need to update those names in app.spec.js
.
// Page file namesconst enFile = 'en.njk'; // UPDATE if changedconst frFile = 'fr.njk'; // UPDATE if changed
Adding or removing ESLint or Prettier
If you added ESLint and Prettier to the application after you created your project, make sure to enable them in packages.spec.js
.
const optionalPackages = { eslint: { enabled: true,// UPDATE if changed packages: [ 'eslint', 'eslint-plugin-import', '@ongov/eslint-config-ontario-frontend', ], }, prettier: { enabled: true, // UPDATE if changed packages: ['prettier', '@ongov/prettier-config-ontario-frontend'], }, };
Debugging errors
You should have an .env
file in your project’s root directory with the variable E2E_URL=your-target-url
. The command npm run test:e2e
will run the tests on this saved URL. Make sure to update this link to your preferred URL, where your application is running – locally, on stage, or production.
You can also use the --url
flag to provide the test URL through CLI:
npm run test:e2e –url={your-target-url}
Required packages
The tests use the stable versions of:
- Mocha v10.7
- Chai v4.4
- Nightwatch v3.7
- Chromedriver v126.0
These packages will automatically be installed on your machine when you run any of the test commands.