Test add-ons in Volto 17
Contents
Test add-ons in Volto 17#
Volto uses Jest for unit tests.
You must configure package.json
to let Jest know about your aliases and make them available to it to resolve them.
"jest": {
"moduleNameMapper": {
"@plone/volto/(.*)$": "<rootDir>/node_modules/@plone/volto/src/$1",
"@package/(.*)$": "<rootDir>/src/$1",
"@plone/some-volto-addon/(.*)$": "<rootDir>/src/addons/@plone/some-volto-addon/src/$1",
"my-volto-addon/(.*)$": "<rootDir>/src/addons/my-volto-addon/src/$1",
"~/(.*)$": "<rootDir>/src/$1"
}
}
You can use yarn test src/addons/addon-name
to run tests.
Override Jest configuration#
In CI or for testing add-ons, it's useful to modify Jest's package.json
configuration file.
You can use a jest.config.js
file, or point the test runner to a file of your choice, using the RAZZLE_JEST_CONFIG
environment variable.
RAZZLE_JEST_CONFIG=my-custom-jest-config.js yarn test
Both configurations are merged in a way that the keys of the configuration provided override the initial package.json
configuration, either in Volto or in your projects.
Test add-ons in isolation#
Testing an add-on in isolation, as you would when you develop a Plone Python backend add-on, can be a bit challenging, since an add-on needs a working project in order to bootstrap itself. The latest generator has the boilerplate needed to bootstrap a dockerized environment where you can run any test to your add-on.
Acceptance tests#
Use Cypress to run acceptance tests. Run the following command once.
make install-acceptance
To start the servers, run the following command.
make start-test-acceptance-server
You run the frontend in development mode, so you can develop while writing tests. Run the following command to run Cypress tests afterward.
make test-acceptance
When finished, shut down the backend server.
make stop-test-acceptance-server