Disable Vite During Laravel Tests

October 15th, 2024 • 1 minute read time

Unless you're running end-to-end tests, you probably don't need Vite to build assets before your test suite runs.

I was recently working on an application that uses Inertia and Inertia's built-in test functionality to verify the correct data was being made available as props. However, running the test suite gave me this:

Vite manifest not found at [location]

Because we didn't build assets as part of the test, an HTTP request to the pages of the application can't find the Vite manifest file that would usually be available when you're running npm run dev locally or npm run build in production.

So, here's how I disabled Vite during these feature tests.

To do this with Pest 3, it's as simple as adding a beforeEach hook to all your Feature tests:

pest()->extend(Tests\TestCase::class)
    ->in('Feature')
    ->beforeEach(fn () => $this->withoutVite());

We call the withoutVite method on the base TestCase to prevent Vite from running.

If you're using PHPUnit, the process to disable Vite during your tests is pretty much the same — just call the withoutVite method in setUp:

abstract class TestCase extends BaseTestCase
{
    use CreatesApplication;

    protected function setUp(): void
    {
        parent::setUp();
        $this->withoutVite();
    }
}

Hopefully this has helped you disable Vite during your Laravel feature tests, where it's unlikely you'll ever need it.

If you found this article helpful, you'll love our practical screencasts.
Author
Alex Garrett-Smith
Share :

Comments

No comments, yet. Be the first!

Table of contents

Tagged under