Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ jobs:
timeout_minutes: 5
max_attempts: 5
command: |
composer require phpunit/phpunit:^9.5.8 --dev --${{ matrix.stability }} --no-update --no-interaction
composer require vlucas/phpdotenv:^5.3.1 --${{ matrix.stability }} --no-update --no-interaction
if: matrix.php >= 8.1 && matrix.stability == 'prefer-lowest'

Expand All @@ -63,7 +62,6 @@ jobs:
max_attempts: 5
command: |
composer require "orchestra/testbench:^9.2|^10.0" --dev --${{ matrix.stability }} --no-update --no-interaction
composer require "phpunit/phpunit:^10.4|^11.5" --dev --${{ matrix.stability }} --no-update --no-interaction
if: matrix.php >= 8.2 && matrix.stability == 'prefer-lowest' && matrix.laravel >= 11

- name: Set Laravel version
Expand Down
4 changes: 2 additions & 2 deletions src/Middleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ public function version(Request $request)
return hash('xxh128', config('app.asset_url'));
}

if (file_exists($manifest = public_path('mix-manifest.json'))) {
if (file_exists($manifest = public_path('build/manifest.json'))) {
return hash_file('xxh128', $manifest);
}

if (file_exists($manifest = public_path('build/manifest.json'))) {
if (file_exists($manifest = public_path('mix-manifest.json'))) {
return hash_file('xxh128', $manifest);
}

Expand Down
51 changes: 51 additions & 0 deletions tests/MiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Inertia\Tests;

use Illuminate\Filesystem\Filesystem;
use Illuminate\Http\Request;
use Illuminate\Session\Middleware\StartSession;
use Illuminate\Support\Facades\Route;
Expand All @@ -13,9 +14,16 @@
use Inertia\Middleware;
use Inertia\Tests\Stubs\ExampleMiddleware;
use LogicException;
use PHPUnit\Framework\Attributes\After;

class MiddlewareTest extends TestCase
{
#[After]
public function cleanupPublicFolder(): void
{
(new Filesystem)->cleanDirectory(public_path());
}

public function test_no_response_value_by_default_means_automatically_redirecting_back_for_inertia_requests(): void
{
$fooCalled = false;
Expand Down Expand Up @@ -241,6 +249,49 @@ public function rootView(Request $request): string
$response->assertViewIs('welcome');
}

public function test_determine_the_version_by_a_hash_of_the_asset_url(): void
{
config(['app.asset_url' => $url = 'https://example.com/assets']);

$this->prepareMockEndpoint(middleware: new Middleware);

$response = $this->get('/');
$response->assertOk();
$response->assertViewHas('page.version', hash('xxh128', $url));
}

public function test_determine_the_version_by_a_hash_of_the_vite_manifest(): void
{
$filesystem = new Filesystem;
$filesystem->ensureDirectoryExists(public_path('build'));
$filesystem->put(
public_path('build/manifest.json'),
$contents = json_encode(['vite' => true])
);

$this->prepareMockEndpoint(middleware: new Middleware);

$response = $this->get('/');
$response->assertOk();
$response->assertViewHas('page.version', hash('xxh128', $contents));
}

public function test_determine_the_version_by_a_hash_of_the_mix_manifest(): void
{
$filesystem = new Filesystem;
$filesystem->ensureDirectoryExists(public_path());
$filesystem->put(
public_path('mix-manifest.json'),
$contents = json_encode(['mix' => true])
);

$this->prepareMockEndpoint(middleware: new Middleware);

$response = $this->get('/');
$response->assertOk();
$response->assertViewHas('page.version', hash('xxh128', $contents));
}

private function prepareMockEndpoint($version = null, $shared = [], $middleware = null): \Illuminate\Routing\Route
{
if (is_null($middleware)) {
Expand Down