Inertia Testing Fails in GitHub Actions Due to Laravel 12 and Starter Kit Structure
Description
With the new Laravel 12 version, Inertia's testing configuration variable inertia.testing.view-finder defaults to resource_path('js/Pages'). However, the latest starter kits use the js/pages directory structure.
This discrepancy causes tests to fail in GitHub Actions, even though they pass locally.
Steps to Reproduce
Create a new Laravel 12 project using a starter kit with Inertia and React.
Run tests locally (./vendor/bin/pest or php artisan test). (Tests pass)
Commit and push the changes to a GitHub repository with GitHub Actions configured to run tests.
Observe the test failure in GitHub Actions:
FAILED Tests\Feature\Auth\LoginTest > it can render the login screen
AssertionFailedError
Inertia page component file [auth/login] does not exist.
at vendor/inertiajs/inertia-laravel/src/Testing/AssertableInertia.php:63
FAILED Tests\Feature\WelcomeTest > it can render t… AssertionFailedError
Inertia page component file [welcome] does not exist.
at vendor/inertiajs/inertia-laravel/src/Testing/AssertableInertia.php:63
59▕ if ($shouldExist || (is_null($shouldExist) && config('inertia.testing.ensure_pages_exist', true))) {
60▕ try {
61▕ app('inertia.testing.view-finder')->find($value);
62▕ } catch (InvalidArgumentException $exception) {
➜ 63▕ PHPUnit::fail(sprintf('Inertia page component file [%s] does not exist.', $value));
64▕ }
65▕ }
66▕
67▕ return $this;
+1 vendor frames
2 tests/Feature/WelcomeTest.php:6
+2 vendor frames
5 tests/Feature/WelcomeTest.php:6
To resolve the issue with Inertia's testing configuration in Laravel 12, you need to ensure that the inertia.testing.view-finder configuration matches the directory structure used by your starter kit. Since the default is set to resource_path('js/Pages') but your project uses js/pages, you can override this configuration in your test setup.
Here's how you can fix it:
Create a Test Case Base Class: If you don't already have a base test case class, create one to centralize your test setup.
Override the Inertia Configuration: In your base test case class, override the inertia.testing.view-finder configuration to match your directory structure.
Here's an example of how you can implement this:
<?php
namespace Tests;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
abstract class TestCase extends BaseTestCase
{
use CreatesApplication;
protected function setUp(): void
{
parent::setUp();
// Override the Inertia view-finder configuration
config()->set('inertia.testing.view-finder', resource_path('js/pages'));
}
}
Ensure All Tests Extend This Base Class: Make sure all your test classes extend this base TestCase class so that the configuration is applied to all tests.
Commit and Push Changes: After making these changes, commit and push them to your GitHub repository.
Verify in GitHub Actions: Once the changes are pushed, GitHub Actions should now run the tests with the correct configuration, and the tests should pass.
By overriding the configuration in your test setup, you ensure that the tests are looking in the correct directory for your Inertia page components, both locally and in your CI environment.
It kind of didn't work. I imagine it might be related to having an HTTP service running for Inertia to render the component, but since I'm new to Inertia, I can't say for sure!