mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 19:34:04 +00:00
[4.x] Fix ViteBundler not affecting Vite static calls (#1389)
* Fix ViteBundler not affecting Vite static calls Replace custom Vite class override with Vite::createAssetPathsUsing() to ensure ViteBundler works for both container and static usage when asset_helper_override is enabled. Fixes #1388 * Remove redundant logic from tests * Simplify test further * Re-add file creation logic --------- Co-authored-by: Samuel Štancl <samuel@archte.ch>
This commit is contained in:
parent
3b42c9e20c
commit
99d854ed8e
3 changed files with 35 additions and 41 deletions
|
|
@ -3,27 +3,41 @@
|
|||
declare(strict_types=1);
|
||||
|
||||
use Illuminate\Foundation\Vite;
|
||||
use Stancl\Tenancy\Tests\Etc\Tenant;
|
||||
use Stancl\Tenancy\Overrides\Vite as StanclVite;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Stancl\Tenancy\Bootstrappers\FilesystemTenancyBootstrapper;
|
||||
use Stancl\Tenancy\Features\ViteBundler;
|
||||
use Stancl\Tenancy\Tests\Etc\Tenant;
|
||||
|
||||
test('vite helper uses our custom class', function() {
|
||||
$vite = app(Vite::class);
|
||||
|
||||
expect($vite)->toBeInstanceOf(Vite::class);
|
||||
expect($vite)->not()->toBeInstanceOf(StanclVite::class);
|
||||
use function Stancl\Tenancy\Tests\withBootstrapping;
|
||||
|
||||
beforeEach(function () {
|
||||
config([
|
||||
'tenancy.features' => [ViteBundler::class],
|
||||
'tenancy.filesystem.asset_helper_override' => true,
|
||||
'tenancy.bootstrappers' => [FilesystemTenancyBootstrapper::class],
|
||||
]);
|
||||
|
||||
$tenant = Tenant::create();
|
||||
|
||||
tenancy()->initialize($tenant);
|
||||
|
||||
app()->forgetInstance(Vite::class);
|
||||
|
||||
$vite = app(Vite::class);
|
||||
|
||||
expect($vite)->toBeInstanceOf(StanclVite::class);
|
||||
File::ensureDirectoryExists(dirname($manifestPath = public_path('build/manifest.json')));
|
||||
File::put($manifestPath, json_encode([
|
||||
'foo' => [
|
||||
'file' => 'assets/foo-AbC123.js',
|
||||
'src' => 'js/foo.js',
|
||||
],
|
||||
]));
|
||||
});
|
||||
|
||||
test('vite bundler ensures vite assets use global_asset when asset_helper_override is enabled', function () {
|
||||
config(['tenancy.features' => [ViteBundler::class]]);
|
||||
|
||||
withBootstrapping();
|
||||
|
||||
tenancy()->initialize(Tenant::create());
|
||||
|
||||
// Not what we want
|
||||
expect(asset('foo'))->toBe(route('stancl.tenancy.asset', ['path' => 'foo']));
|
||||
|
||||
$viteAssetUrl = app(Vite::class)->asset('foo');
|
||||
$expectedGlobalUrl = global_asset('build/assets/foo-AbC123.js');
|
||||
|
||||
expect($viteAssetUrl)->toBe($expectedGlobalUrl);
|
||||
expect($viteAssetUrl)->toBe('http://localhost/build/assets/foo-AbC123.js');
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue