Repository navigation
Running Tests
Mukurtu includes multiple types of test coverage: Unit testing, functional, (other types to be added, i.e. security, linting, performance, etc.)
Mukurtu includes PHPUnit tests that leverage Drupal's built-in Kernel and Browser testing. The full list of tests executed in this way can be found within the <testsuites> section of the phpunit.xml file.
Tests can be run with the following (from the project root):
# Copy the Mukurtu test suite PHPUnit configuration file to the root:
cp ./web/profiles/mukurtu/phpunit.ddev.xml ./phpunit.xml
# Run all tests:
ddev exec phpunit --display-all-issues --testsuite kernel
Playwright is used for browser-based testing. Playwright is JavaScript-based and executed via npx or yarn. For consistency with Playwright's documentation and simplifying the overall configuration, this document recommends installing npm and Playwright on the host machine (not within a DDEV docker container). Running directly on the host allows easier access to Playwright reports, the codegen tool, and running tests in browser (headed) mode.
If you don't yet have Node.js and npm, install via your preferred method. NVM (Node Version Manager) is recommended if you have not yet installed Node.js.
If you're not sure if you have Node.js run:
which npm
Which should return something like /home/[user]/.config/nvm/20.4.0/bin/npm.
cd ./web/profiles/mukurtu/tests/playwright
npm install
npx playwright install
# Linux and Windows WSL2 only:
npx playwright install-deps
To run the entire test suite:
cd ./web/profiles/mukurtu/tests/playwright
npx playwright test
Or to run an individual test:
npx playwright test tests/community.spec.ts
You can also run a test just to populate default content with:
npx playwright test tests/default-content.spec.ts
Note that tests run the default content test as a dependency before any other tests are run, so you can assume the default content exists rather than recreating it in every test case.
Playwright also includes some useful tools to write new tests and debug existing ones.
- Playwright Codegen: This can help create a set of steps, such as filling out a form. The generated TypeScript code can be copy/pasted into your test. Codegen is a learning tool, not a comprehensive test creation tool. It can help write tests but they still require manual modification. Still, it can be quite helpful when navigating complex Drupal modal dialogs and multi-page workflows. Start the codegen tool with:
npx playwright codegen
- Playwright UI Mode: This mode gives you a browser from which you can run individual tests, and watch them execute in real time. This can be useful to run an individual test instead of typing in the tests name, finding a list of all tests, and running the same test repeatedly.
npx playwright test --ui
- Playwright Debugging Mode: Debug mode is similar to UI mode, in that it will show the browser as it executes the test, but debug mode provides the ability to run the test one line at a time, watching the test as it makes each step. This can be useful to identify exactly where a test is failing. Debug mode can be run on an individual test like this:
npx playwright test tests/community.spec.ts --debug
- DDEV Snapshots: There is not a mechanism to delete the default content, other than re-installing Mukurtu. However, when writing tests it can be faster to use DDEV snapshots to save and then restore the database.
# Before running tests:
ddev snapshot
# Run an individual test in debug mode:
cd ./web/profiles/mukurtu/tests/playwright
npx playwright test tests/community.spec.ts --debug
# If there are errors in the test and you want to try again, restore the snapshot:
ddev snapshot restore