Testing - prestomade/presto-player-developer-documentation GitHub Wiki
Overview
Testing makes use of a few different types of tests:
- PHPUnit
- WP Admin JavaScript Unit Testing
- WP Admin E2E Testing
- Front-End JavaScript Unit Testing
- Front-End JavaScript E2E Testing
PHPUnit Tests
PHPUnit tests are the basis for the backend of the plugin. Testing replies on the @wordpress/env package to run tests in a controlled Docker environment. This simplifies setting up PHPUnit on various machines since it's run in an isolated environment. Additionally, it also allows us to test with different php versions and more easily in a CI environment like GitHub Actions.
Tests should be placed in the tests/feature
or tests/unit
directories for respective tests.
Prerequisites
- Unit tests require Docker to be installed and running. There are instructions available for installing Docker Desktop
- You must have BOTH the Presto Player and Presto Player Pro plugin folders as siblings in your file browser (i.e. both in the plugins directory)
plugins
└───presto-player
└───presto-player-pro
Installation
Once you have Docker running, you'll want to make sure you're in the presto-player
plugin directory to install node_modules and composer dependencies.
yarn
composer install
Usage
To run php unit tests, run the following commands:
yarn wp-env start
yarn test:php
WordPress Admin JavaScript Unit Tests
For Presto Player, we only write javascript tests for the WordPress admin interactions. Unit tests for the front-end should be handled with the Component Tests (see below).
Tests should be placed in the tests
folder within the individual component directories and should be named *.spec.js
.
Installation
yarn
composer install
Usage
To run javascript unit tests, run the following commands:
yarn test:js
or
yarn test:js --watch
WordPress Admin End-To-End Tests
For this package, we only write e2e tests for the WordPress admin interactions. e2e tests for the front-end should be handled with the Component Tests (see below).
Admin e2e Testing replies on the @wordpress/env package to run tests in a controlled Docker environment.
Tests should be placed in the tests-e2e
directory.
Installation
yarn
composer install
Usage
To run javascript unit tests, first, be sure the wp-env environment is running:
yarn wp-env start
Then run
yarn test:admin-e2e
or
yarn test:admin-e2e --watch
Component Tests
Presto Player uses StencilJS for it's various components, which provides it's own isolated testing environment for both "unit" and "e2e" tests. Component tests are run directly in the packages/components
directory.
The benefit of component tests is we can easily seed component data without needing to spin up WordPress or seed post content directly.
Tests should be placed in the tests
folder within the individual component directories.
Documentation
Installation
cd packages/components
yarn
Usage
yarn test
Watch Mode
yarn test.watch