A Pest plugin to watch files and restart Pest when they change.
This is a Pest Watch plugin that works with Pest v4 & v5 and differs from the official Pest Watch plugin which became unsupported. It's now built on the spatie/file-system-watcher package which uses the node package chokidar under the hood for efficient file watching.
You can install the package via composer:
composer require petecoop/pest-plugin-watch --devIn your project, you should have the JavaScript package chokidar installed. You can install it via npm
npm install chokidar --save-devIf you are using Bun, you can install it via:
bun a -d chokidarThe watcher will automatically use Bun if there is a bun.lock file in your project.
To start Pest in watch mode, run the following command:
pest --watchThis will restart Pest whenever a file in src, app, tests or resources/views changes.
You can override the default paths by providing your own paths, for example inside your Pest.php file:
Petecoop\PestWatch\Plugin::directories(['src', 'tests', 'custom-dir']);The watcher preserves the PHP binary and configuration that started it. This allows coverage to be collected on every rerun when using Laravel Herd:
herd coverage vendor/bin/pest --coverage --watchand allows --tia to work with the watcher:
herd coverage vendor/bin/pest --tia --watch