feat: VivesPOS landing on Winter CMS 1.2 — theme + plugin + Dockerfile
Some checks are pending
Module sub-split / Sub-split (push) Waiting to run
Some checks are pending
Module sub-split / Sub-split (push) Waiting to run
- Base: wintercms/winter branch 1.2 (full framework) - Theme vivespos: Canvas 7 + Bootstrap 5 CDN, custom CSS - Layout: deferred GTM/GA4 tracking, JSON-LD SoftwareApplication - Partials: hero (offline-first), features, modes (offline/nube toggle), screenshots, pricing (3 planes), comparison, FAQ, CTA - Plugin VivesPOS.Site with ContactForm - Dockerfile: PHP 8.2 Apache, port 80, healthcheck - Added winter/wn-pages, blog, sitemap, seo plugins - Active theme set to vivespos
This commit is contained in:
19
modules/system/tests/console/asset/NpmTestTrait.php
Normal file
19
modules/system/tests/console/asset/NpmTestTrait.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace System\Tests\Console\Asset;
|
||||
|
||||
trait NpmTestTrait
|
||||
{
|
||||
protected string $jsonPath;
|
||||
protected string $backupPath;
|
||||
|
||||
/**
|
||||
* Helper to run test logic and handle restoring package.json file after
|
||||
*/
|
||||
protected function withPackageJsonRestore(callable $callback): void
|
||||
{
|
||||
copy($this->jsonPath, $this->backupPath);
|
||||
$callback();
|
||||
rename($this->backupPath, $this->jsonPath);
|
||||
}
|
||||
}
|
||||
100
modules/system/tests/console/asset/mix/MixCompileTest.php
Normal file
100
modules/system/tests/console/asset/mix/MixCompileTest.php
Normal file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
namespace System\Tests\Console\Asset\Mix;
|
||||
|
||||
use System\Tests\Bootstrap\TestCase;
|
||||
use Winter\Storm\Support\Facades\File;
|
||||
|
||||
class MixCompileTest extends TestCase
|
||||
{
|
||||
protected string $command = 'mix:compile';
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
if (!File::exists(base_path('node_modules'))) {
|
||||
$this->markTestSkipped('This test requires node_modules to be installed');
|
||||
}
|
||||
|
||||
if (!File::exists(base_path('node_modules/.bin/mix'))) {
|
||||
$this->markTestSkipped('This test requires the mix package to be installed');
|
||||
}
|
||||
}
|
||||
|
||||
public function testCompileMultiple()
|
||||
{
|
||||
$this->artisan($this->command, [
|
||||
'--manifest' => 'modules/system/tests/fixtures/npm/package-ac.json',
|
||||
'--silent' => true
|
||||
])->assertExitCode(0);
|
||||
|
||||
$this->assertFileExists(base_path('modules/system/tests/fixtures/plugins/mix/testa/assets/dist/app.js'));
|
||||
$this->assertFileExists(base_path('modules/system/tests/fixtures/plugins/mix/testc/assets/dist/app.js'));
|
||||
}
|
||||
|
||||
public function testCompileMultipleWithErrors()
|
||||
{
|
||||
$this->artisan($this->command, [
|
||||
'--manifest' => 'modules/system/tests/fixtures/npm/package-abc.json',
|
||||
'--disable-tty' => true
|
||||
])
|
||||
->expectsOutputToContain('Error: Can\'t resolve \'some-missing-package\'')
|
||||
->assertExitCode(1);
|
||||
|
||||
$this->assertFileExists(base_path('modules/system/tests/fixtures/plugins/mix/testa/assets/dist/app.js'));
|
||||
$this->assertFileExists(base_path('modules/system/tests/fixtures/plugins/mix/testb/assets/dist/app.js'));
|
||||
$this->assertFileExists(base_path('modules/system/tests/fixtures/plugins/mix/testc/assets/dist/app.js'));
|
||||
}
|
||||
|
||||
public function testCompileTarget()
|
||||
{
|
||||
$this->artisan($this->command, [
|
||||
'--manifest' => 'modules/system/tests/fixtures/npm/package-abc.json',
|
||||
'--package' => 'mix.testa',
|
||||
'--silent' => true
|
||||
])->assertExitCode(0);
|
||||
|
||||
$this->assertFileExists(base_path('modules/system/tests/fixtures/plugins/mix/testa/assets/dist/app.js'));
|
||||
$this->assertFileNotExists(base_path('modules/system/tests/fixtures/plugins/mix/testb/assets/dist/app.js'));
|
||||
$this->assertFileNotExists(base_path('modules/system/tests/fixtures/plugins/mix/testc/assets/dist/app.js'));
|
||||
}
|
||||
|
||||
public function testCompileTargetWithError()
|
||||
{
|
||||
$this->artisan($this->command, [
|
||||
'--manifest' => 'modules/system/tests/fixtures/npm/package-abc.json',
|
||||
'--package' => 'mix.testb',
|
||||
'--disable-tty' => true
|
||||
])
|
||||
->expectsOutputToContain('Error: Can\'t resolve \'some-missing-package\'')
|
||||
->assertExitCode(1);
|
||||
|
||||
$this->assertFileNotExists(base_path('modules/system/tests/fixtures/plugins/mix/testa/assets/dist/app.js'));
|
||||
$this->assertFileNotExists(base_path('modules/system/tests/fixtures/plugins/mix/testc/assets/dist/app.js'));
|
||||
$this->assertFileExists(base_path('modules/system/tests/fixtures/plugins/mix/testb/assets/dist/app.js'));
|
||||
}
|
||||
|
||||
public function testCompileTargetStopOnError()
|
||||
{
|
||||
$this->artisan($this->command, [
|
||||
'--manifest' => 'modules/system/tests/fixtures/npm/package-abc.json',
|
||||
'--stop-on-error' => true,
|
||||
'--disable-tty' => true
|
||||
])
|
||||
->expectsOutputToContain('Error: Can\'t resolve \'some-missing-package\'')
|
||||
->assertExitCode(1);
|
||||
|
||||
$this->assertFileExists(base_path('modules/system/tests/fixtures/plugins/mix/testa/assets/dist/app.js'));
|
||||
$this->assertFileExists(base_path('modules/system/tests/fixtures/plugins/mix/testb/assets/dist/app.js'));
|
||||
$this->assertFileNotExists(base_path('modules/system/tests/fixtures/plugins/mix/testc/assets/dist/app.js'));
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
{
|
||||
File::deleteDirectory('modules/system/tests/fixtures/plugins/mix/testa/assets/dist');
|
||||
File::deleteDirectory('modules/system/tests/fixtures/plugins/mix/testb/assets/dist');
|
||||
File::deleteDirectory('modules/system/tests/fixtures/plugins/mix/testc/assets/dist');
|
||||
parent::tearDown();
|
||||
}
|
||||
}
|
||||
234
modules/system/tests/console/asset/mix/MixCreateTest.php
Normal file
234
modules/system/tests/console/asset/mix/MixCreateTest.php
Normal file
@@ -0,0 +1,234 @@
|
||||
<?php
|
||||
|
||||
namespace System\Tests\Console\Asset\Mix;
|
||||
|
||||
use System\Classes\PluginManager;
|
||||
use System\Tests\Bootstrap\TestCase;
|
||||
use Winter\Storm\Support\Facades\File;
|
||||
|
||||
class MixCreateTest extends TestCase
|
||||
{
|
||||
protected string $testPlugin = 'Winter.Sample';
|
||||
|
||||
public function testConfigWritten(): void
|
||||
{
|
||||
$path = PluginManager::instance()->findByIdentifier($this->testPlugin)->getPluginPath();
|
||||
$configPath = $path . '/winter.mix.js';
|
||||
|
||||
// Check file does not exist
|
||||
$this->assertFileNotExists($configPath);
|
||||
|
||||
// Run the config command to generate the vite config
|
||||
$this->artisan('mix:create', [
|
||||
'packageName' => $this->testPlugin,
|
||||
'--no-stubs' => true,
|
||||
])
|
||||
->doesntExpectOutput('winter.mix.js already exists, overwrite?')
|
||||
->assertExitCode(0);
|
||||
|
||||
// Validate the manifest was written
|
||||
$this->assertFileExists($configPath);
|
||||
|
||||
// Get the predicted contents
|
||||
$fixture = str_replace(
|
||||
'{{packageName}}',
|
||||
'winter-sample',
|
||||
File::get(base_path('modules/system/console/asset/fixtures/config/mix/winter.mix.js.fixture')),
|
||||
);
|
||||
|
||||
// Check the file written is what was expected
|
||||
$this->assertEquals($fixture, File::get($configPath));
|
||||
|
||||
// Overwrite the file content
|
||||
File::put($configPath, 'testing');
|
||||
|
||||
// Check that refusing to overwrite does not replace file contents
|
||||
$this->artisan('mix:create', [
|
||||
'packageName' => $this->testPlugin,
|
||||
'--no-stubs' => true,
|
||||
])
|
||||
->expectsQuestion('winter.mix.js already exists, overwrite?', false)
|
||||
->assertExitCode(0);
|
||||
|
||||
// Check file contents was not overwritten
|
||||
$this->assertNotEquals($fixture, File::get($configPath));
|
||||
|
||||
// Run command confirming to overwrite file contents works
|
||||
$this->artisan('mix:create', [
|
||||
'packageName' => $this->testPlugin,
|
||||
'--no-stubs' => true,
|
||||
])
|
||||
->expectsQuestion('winter.mix.js already exists, overwrite?', true)
|
||||
->assertExitCode(0);
|
||||
|
||||
// Check file contents was overwritten
|
||||
$this->assertEquals($fixture, File::get($configPath));
|
||||
}
|
||||
|
||||
public function testConfigTailwind(): void
|
||||
{
|
||||
$path = PluginManager::instance()->findByIdentifier($this->testPlugin)->getPluginPath();
|
||||
$configPath = $path . '/winter.mix.js';
|
||||
$packageJson = $path . '/package.json';
|
||||
|
||||
// Check file does not exist
|
||||
$this->assertFileNotExists($configPath);
|
||||
|
||||
// Run the config command to generate the vite config
|
||||
$this->artisan('mix:create', [
|
||||
'packageName' => $this->testPlugin,
|
||||
'--tailwind' => true,
|
||||
'--no-stubs' => true,
|
||||
])
|
||||
->assertExitCode(0);
|
||||
|
||||
// Check files are created correctly
|
||||
$this->assertFileExists($configPath);
|
||||
$this->assertFileExists($path . '/tailwind.config.js');
|
||||
$this->assertFileExists($path . '/postcss.config.mjs');
|
||||
|
||||
// Get the contents of the package.json
|
||||
$json = json_decode(File::get($packageJson));
|
||||
|
||||
// Check tailwindcss is required
|
||||
$this->assertTrue(isset($json->devDependencies->tailwindcss));
|
||||
}
|
||||
|
||||
public function testConfigReact(): void
|
||||
{
|
||||
$path = PluginManager::instance()->findByIdentifier($this->testPlugin)->getPluginPath();
|
||||
$configPath = $path . '/winter.mix.js';
|
||||
$packageJson = $path . '/package.json';
|
||||
|
||||
// Check file does not exist
|
||||
$this->assertFileNotExists($configPath);
|
||||
|
||||
// Run the config command to generate the vite config with react
|
||||
$this->artisan('mix:create', [
|
||||
'packageName' => $this->testPlugin,
|
||||
'--react' => true,
|
||||
'--no-stubs' => true,
|
||||
])
|
||||
->assertExitCode(0);
|
||||
|
||||
// Check files are created correctly
|
||||
$this->assertFileExists($configPath);
|
||||
$this->assertFileExists($packageJson);
|
||||
|
||||
// Get the contents of the package.json
|
||||
$json = json_decode(File::get($packageJson));
|
||||
|
||||
// Check react is required
|
||||
$this->assertTrue(isset($json->devDependencies->react));
|
||||
}
|
||||
|
||||
public function testConfigTailwindReact(): void
|
||||
{
|
||||
$path = PluginManager::instance()->findByIdentifier($this->testPlugin)->getPluginPath();
|
||||
$configPath = $path . '/winter.mix.js';
|
||||
$packageJson = $path . '/package.json';
|
||||
|
||||
// Check file does not exist
|
||||
$this->assertFileNotExists($configPath);
|
||||
|
||||
// Run the config command to generate the vite config with react
|
||||
$this->artisan('mix:create', [
|
||||
'packageName' => $this->testPlugin,
|
||||
'--tailwind' => true,
|
||||
'--react' => true,
|
||||
'--no-stubs' => true,
|
||||
])
|
||||
->assertExitCode(0);
|
||||
|
||||
// Check files are created correctly
|
||||
$this->assertFileExists($configPath);
|
||||
$this->assertFileExists($packageJson);
|
||||
$this->assertFileExists($path . '/tailwind.config.js');
|
||||
$this->assertFileExists($path . '/postcss.config.mjs');
|
||||
|
||||
// Get the contents of the package.json
|
||||
$json = json_decode(File::get($packageJson));
|
||||
|
||||
// Check tailwind & react are required
|
||||
$this->assertTrue(isset($json->devDependencies->tailwindcss));
|
||||
$this->assertTrue(isset($json->devDependencies->react));
|
||||
}
|
||||
|
||||
public function testConfigVue(): void
|
||||
{
|
||||
$path = PluginManager::instance()->findByIdentifier($this->testPlugin)->getPluginPath();
|
||||
$configPath = $path . '/winter.mix.js';
|
||||
$packageJson = $path . '/package.json';
|
||||
|
||||
// Check file does not exist
|
||||
$this->assertFileNotExists($configPath);
|
||||
|
||||
// Run the config command to generate the vite config with vue
|
||||
$this->artisan('mix:create', [
|
||||
'packageName' => $this->testPlugin,
|
||||
'--vue' => true,
|
||||
'--no-stubs' => true,
|
||||
])
|
||||
->assertExitCode(0);
|
||||
|
||||
// Check files are created correctly
|
||||
$this->assertFileExists($configPath);
|
||||
$this->assertFileExists($packageJson);
|
||||
|
||||
// Get the contents of the package.json
|
||||
$json = json_decode(File::get($packageJson));
|
||||
|
||||
// Check vue is required
|
||||
$this->assertTrue(isset($json->devDependencies->vue));
|
||||
}
|
||||
|
||||
public function testConfigTailwindVue(): void
|
||||
{
|
||||
$path = PluginManager::instance()->findByIdentifier($this->testPlugin)->getPluginPath();
|
||||
$configPath = $path . '/winter.mix.js';
|
||||
$packageJson = $path . '/package.json';
|
||||
|
||||
// Check file does not exist
|
||||
$this->assertFileNotExists($configPath);
|
||||
|
||||
// Run the config command to generate the vite config with vue
|
||||
$this->artisan('mix:create', [
|
||||
'packageName' => $this->testPlugin,
|
||||
'--tailwind' => true,
|
||||
'--vue' => true,
|
||||
'--no-stubs' => true,
|
||||
])
|
||||
->assertExitCode(0);
|
||||
|
||||
// Check files are created correctly
|
||||
$this->assertFileExists($configPath);
|
||||
$this->assertFileExists($packageJson);
|
||||
$this->assertFileExists($path . '/tailwind.config.js');
|
||||
$this->assertFileExists($path . '/postcss.config.mjs');
|
||||
|
||||
// Get the contents of the package.json
|
||||
$json = json_decode(File::get($packageJson));
|
||||
|
||||
// Check tailwind & vue are required
|
||||
$this->assertTrue(isset($json->devDependencies->tailwindcss));
|
||||
$this->assertTrue(isset($json->devDependencies->vue));
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
{
|
||||
$path = PluginManager::instance()->findByIdentifier($this->testPlugin)->getPluginPath();
|
||||
|
||||
$files = [
|
||||
$path . '/winter.mix.js',
|
||||
$path . '/package.json',
|
||||
$path . '/tailwind.config.js',
|
||||
$path . '/postcss.config.mjs',
|
||||
];
|
||||
|
||||
foreach ($files as $file) {
|
||||
if (File::exists($file)) {
|
||||
File::delete($file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
213
modules/system/tests/console/asset/mix/MixInstallTest.php
Normal file
213
modules/system/tests/console/asset/mix/MixInstallTest.php
Normal file
@@ -0,0 +1,213 @@
|
||||
<?php
|
||||
|
||||
namespace System\Tests\Console\Asset\Mix;
|
||||
|
||||
use System\Classes\Asset\PackageManager;
|
||||
use System\Tests\Bootstrap\TestCase;
|
||||
use Winter\Storm\Exception\SystemException;
|
||||
use Winter\Storm\Support\Facades\File;
|
||||
|
||||
class MixInstallTest extends TestCase
|
||||
{
|
||||
protected string $fixturePath;
|
||||
protected string $jsonPath;
|
||||
protected string $lockPath;
|
||||
protected string $backupPath;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
if (!File::exists(base_path('node_modules'))) {
|
||||
$this->markTestSkipped('This test requires node_modules to be installed');
|
||||
}
|
||||
|
||||
// Define some helpful paths
|
||||
$this->fixturePath = base_path('modules/system/tests');
|
||||
$this->jsonPath = $this->fixturePath . '/package.json';
|
||||
$this->lockPath = $this->fixturePath . '/package-lock.json';
|
||||
$this->backupPath = $this->fixturePath . '/package-testing.json';
|
||||
|
||||
// Add our testing theme because it won't be auto discovered
|
||||
PackageManager::instance()->registerPackage(
|
||||
'theme-assettest',
|
||||
base_path('modules/system/tests/fixtures/themes/assettest/winter.mix.js'),
|
||||
'mix'
|
||||
);
|
||||
PackageManager::instance()->registerPackage(
|
||||
'theme-npmtest',
|
||||
base_path('modules/system/tests/fixtures/themes/npmtest/winter.mix.js'),
|
||||
'mix'
|
||||
);
|
||||
}
|
||||
|
||||
public function testMixInstallMissingPackageJson(): void
|
||||
{
|
||||
$this->artisan('mix:install', [
|
||||
'assetPackage' => ['theme-assettest'],
|
||||
'--package-json' => '/some/file',
|
||||
'--no-install' => true
|
||||
])
|
||||
->expectsOutputToContain('The supplied --package-json path does not exist.')
|
||||
->assertExitCode(1);
|
||||
}
|
||||
|
||||
public function testMixInstallSinglePackage(): void
|
||||
{
|
||||
$this->withPackageJsonRestore(function () {
|
||||
$this->artisan('mix:install', [
|
||||
'assetPackage' => ['theme-assettest'],
|
||||
'--package-json' => $this->jsonPath,
|
||||
'--no-install' => true
|
||||
])
|
||||
->expectsQuestion('laravel-mix was not found as a dependency in package.json, would you like to add it?', true)
|
||||
->expectsOutput('Adding theme-assettest (modules/system/tests/fixtures/themes/assettest) to the workspaces.packages property in package.json')
|
||||
->assertExitCode(0);
|
||||
|
||||
$this->assertFileExists($this->jsonPath);
|
||||
$packageJson = json_decode(File::get($this->jsonPath), JSON_OBJECT_AS_ARRAY);
|
||||
$this->assertArrayHasKey('devDependencies', $packageJson);
|
||||
$this->assertArrayHasKey('laravel-mix', $packageJson['devDependencies']);
|
||||
|
||||
$this->assertArrayHasKey('workspaces', $packageJson);
|
||||
$this->assertArrayHasKey('packages', $packageJson['workspaces']);
|
||||
$this->assertContains('modules/system/tests/fixtures/themes/assettest', $packageJson['workspaces']['packages']);
|
||||
});
|
||||
}
|
||||
|
||||
public function testMixInstallMultiplePackages(): void
|
||||
{
|
||||
$this->withPackageJsonRestore(function () {
|
||||
$this->artisan('mix:install', [
|
||||
'assetPackage' => ['theme-assettest', 'theme-npmtest'],
|
||||
'--package-json' => $this->jsonPath,
|
||||
'--no-install' => true
|
||||
])
|
||||
->expectsQuestion('laravel-mix was not found as a dependency in package.json, would you like to add it?', true)
|
||||
->expectsOutput('Adding theme-assettest (modules/system/tests/fixtures/themes/assettest) to the workspaces.packages property in package.json')
|
||||
->expectsOutput('Adding theme-npmtest (modules/system/tests/fixtures/themes/npmtest) to the workspaces.packages property in package.json')
|
||||
->assertExitCode(0);
|
||||
|
||||
$this->assertFileExists($this->jsonPath);
|
||||
$packageJson = json_decode(File::get($this->jsonPath), JSON_OBJECT_AS_ARRAY);
|
||||
$this->assertArrayHasKey('devDependencies', $packageJson);
|
||||
$this->assertArrayHasKey('laravel-mix', $packageJson['devDependencies']);
|
||||
|
||||
$this->assertArrayHasKey('workspaces', $packageJson);
|
||||
$this->assertArrayHasKey('packages', $packageJson['workspaces']);
|
||||
$this->assertContains('modules/system/tests/fixtures/themes/assettest', $packageJson['workspaces']['packages']);
|
||||
$this->assertContains('modules/system/tests/fixtures/themes/npmtest', $packageJson['workspaces']['packages']);
|
||||
});
|
||||
}
|
||||
|
||||
public function testMixInstallMissingPackage(): void
|
||||
{
|
||||
// We should receive an exception for a missing package
|
||||
$this->withPackageJsonRestore(function () {
|
||||
$this->expectException(SystemException::class);
|
||||
|
||||
$this->artisan('mix:install', [
|
||||
'assetPackage' => ['theme-assettest2'],
|
||||
'--package-json' => $this->jsonPath,
|
||||
'--no-install' => true
|
||||
])
|
||||
->assertExitCode(1);
|
||||
});
|
||||
}
|
||||
|
||||
public function testMixInstallRelativePath(): void
|
||||
{
|
||||
$this->withPackageJsonRestore(function () {
|
||||
$this->artisan('mix:install', [
|
||||
'assetPackage' => ['theme-assettest'],
|
||||
'--package-json' => 'modules/system/tests/package.json',
|
||||
'--no-install' => true
|
||||
])
|
||||
->expectsQuestion('laravel-mix was not found as a dependency in package.json, would you like to add it?', true)
|
||||
->expectsOutput('Adding theme-assettest (modules/system/tests/fixtures/themes/assettest) to the workspaces.packages property in package.json')
|
||||
->assertExitCode(0);
|
||||
});
|
||||
}
|
||||
|
||||
public function testMixInstallIgnoredPackage(): void
|
||||
{
|
||||
$this->withPackageJsonRestore(function () {
|
||||
$packageJson = json_decode(File::get($this->jsonPath), JSON_OBJECT_AS_ARRAY);
|
||||
$packageJson['workspaces'] = [
|
||||
'ignoredPackages' => [
|
||||
'modules/system/tests/fixtures/themes/assettest'
|
||||
]
|
||||
];
|
||||
File::put($this->jsonPath, json_encode($packageJson, JSON_PRETTY_PRINT));
|
||||
|
||||
$this->artisan('mix:install', [
|
||||
'assetPackage' => ['theme-assettest'],
|
||||
'--package-json' => $this->jsonPath,
|
||||
'--no-install' => true
|
||||
])
|
||||
->expectsQuestion('laravel-mix was not found as a dependency in package.json, would you like to add it?', false)
|
||||
->expectsOutput('The requested package theme-assettest (modules/system/tests/fixtures/themes/assettest) is ignored, remove it from package.json to continue.')
|
||||
->assertExitCode(0);
|
||||
|
||||
$packageJson = json_decode(File::get($this->jsonPath), JSON_OBJECT_AS_ARRAY);
|
||||
$this->assertArrayHasKey('workspaces', $packageJson);
|
||||
$this->assertArrayNotHasKey('packages', $packageJson['workspaces']);
|
||||
$this->assertArrayNotHasKey('dependencies', $packageJson);
|
||||
$this->assertArrayNotHasKey('devDependencies', $packageJson);
|
||||
});
|
||||
}
|
||||
|
||||
public function testMixInstallWithNpmInstall(): void
|
||||
{
|
||||
$this->withPackageJsonRestore(function () {
|
||||
$this->assertDirectoryDoesNotExist($this->fixturePath . '/node_modules');
|
||||
|
||||
$this->artisan('mix:install', [
|
||||
'assetPackage' => ['theme-assettest'],
|
||||
'--package-json' => $this->jsonPath,
|
||||
'--disable-tty' => true
|
||||
])
|
||||
->expectsQuestion('laravel-mix was not found as a dependency in package.json, would you like to add it?', true)
|
||||
->expectsOutput('Adding theme-assettest (modules/system/tests/fixtures/themes/assettest) to the workspaces.packages property in package.json')
|
||||
->expectsOutputToContain('packages, and audited') // output from npm i
|
||||
->assertExitCode(0);
|
||||
|
||||
$this->assertFileExists($this->jsonPath);
|
||||
$packageJson = json_decode(File::get($this->jsonPath), JSON_OBJECT_AS_ARRAY);
|
||||
$this->assertArrayHasKey('devDependencies', $packageJson);
|
||||
$this->assertArrayHasKey('laravel-mix', $packageJson['devDependencies']);
|
||||
|
||||
$this->assertArrayHasKey('workspaces', $packageJson);
|
||||
$this->assertArrayHasKey('packages', $packageJson['workspaces']);
|
||||
$this->assertContains('modules/system/tests/fixtures/themes/assettest', $packageJson['workspaces']['packages']);
|
||||
|
||||
$this->assertFileExists($this->lockPath);
|
||||
|
||||
$this->assertDirectoryExists($this->fixturePath . '/node_modules');
|
||||
$this->assertDirectoryExists($this->fixturePath . '/node_modules/laravel-mix');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to run test logic and handle restoring package.json file after
|
||||
*/
|
||||
protected function withPackageJsonRestore(callable $callback): void
|
||||
{
|
||||
File::copy($this->backupPath, $this->jsonPath);
|
||||
$callback();
|
||||
File::delete($this->jsonPath);
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
{
|
||||
if (File::isDirectory($this->fixturePath . '/node_modules')) {
|
||||
File::deleteDirectory($this->fixturePath . '/node_modules');
|
||||
}
|
||||
|
||||
if (File::exists($this->lockPath)) {
|
||||
File::delete($this->lockPath);
|
||||
}
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
}
|
||||
209
modules/system/tests/console/asset/npm/NpmInstallTest.php
Normal file
209
modules/system/tests/console/asset/npm/NpmInstallTest.php
Normal file
@@ -0,0 +1,209 @@
|
||||
<?php
|
||||
|
||||
namespace System\Tests\Console\Asset\Npm;
|
||||
|
||||
use System\Classes\Asset\PackageManager;
|
||||
use System\Tests\Bootstrap\TestCase;
|
||||
use System\Tests\Console\Asset\NpmTestTrait;
|
||||
use Winter\Storm\Support\Facades\File;
|
||||
|
||||
class NpmInstallTest extends TestCase
|
||||
{
|
||||
use NpmTestTrait;
|
||||
|
||||
protected string $themePath;
|
||||
protected string $jsonPath;
|
||||
protected string $lockPath;
|
||||
protected string $backupPath;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
if (!File::exists(base_path('node_modules'))) {
|
||||
$this->markTestSkipped('This test requires node_modules to be installed');
|
||||
}
|
||||
|
||||
// Define some helpful paths
|
||||
$this->themePath = base_path('modules/system/tests/fixtures/themes/npmtest');
|
||||
$this->jsonPath = $this->themePath . '/package.json';
|
||||
$this->lockPath = $this->themePath . '/package-lock.json';
|
||||
$this->backupPath = $this->themePath . '/package.backup.json';
|
||||
|
||||
// Add our testing theme because it won't be auto discovered
|
||||
PackageManager::instance()->registerPackage(
|
||||
'theme-npmtest',
|
||||
$this->themePath . '/vite.config.mjs',
|
||||
'vite'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the ability to install a single npm package via artisan
|
||||
*/
|
||||
public function testNpmInstallSingle(): void
|
||||
{
|
||||
// Validate the package Json does not have dependencies
|
||||
$packageJson = json_decode(File::get($this->jsonPath), JSON_OBJECT_AS_ARRAY);
|
||||
$this->assertArrayNotHasKey('dependencies', $packageJson);
|
||||
|
||||
// Validate node_modules not found
|
||||
$this->assertDirectoryDoesNotExist($this->themePath . '/node_modules');
|
||||
$this->assertFileNotExists($this->lockPath);
|
||||
|
||||
$this->withPackageJsonRestore(function () {
|
||||
// Run npm install for a single non-dev package
|
||||
$this->artisan('npm:install', [
|
||||
'package' => 'theme-npmtest',
|
||||
'npmArgs' => ['is-odd'],
|
||||
'--disable-tty' => true
|
||||
])
|
||||
->assertExitCode(0);
|
||||
|
||||
// Validate lock file was generated successfully
|
||||
$this->assertFileExists($this->lockPath);
|
||||
|
||||
// Validate the contents of package.json
|
||||
$packageJson = json_decode(File::get($this->jsonPath), JSON_OBJECT_AS_ARRAY);
|
||||
$this->assertArrayHasKey('dependencies', $packageJson);
|
||||
$this->assertArrayHasKey('is-odd', $packageJson['dependencies']);
|
||||
|
||||
// Validate that node_modules paths exist
|
||||
$this->assertDirectoryExists($this->themePath . '/node_modules');
|
||||
$this->assertDirectoryExists($this->themePath . '/node_modules/is-odd');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the ability to install multiple npm packages via artisan
|
||||
*/
|
||||
public function testNpmInstallMultiple(): void
|
||||
{
|
||||
// Validate the package Json does not have dependencies
|
||||
$packageJson = json_decode(File::get($this->jsonPath), JSON_OBJECT_AS_ARRAY);
|
||||
$this->assertArrayNotHasKey('dependencies', $packageJson);
|
||||
|
||||
// Validate node_modules not found
|
||||
$this->assertDirectoryDoesNotExist($this->themePath . '/node_modules');
|
||||
$this->assertFileNotExists($this->lockPath);
|
||||
|
||||
$this->withPackageJsonRestore(function () {
|
||||
// Run npm install for multiple non-dev packages
|
||||
$this->artisan('npm:install', [
|
||||
'package' => 'theme-npmtest',
|
||||
'npmArgs' => ['is-odd', 'is-even'],
|
||||
'--disable-tty' => true
|
||||
])
|
||||
->assertExitCode(0);
|
||||
|
||||
// Validate lock file was generated successfully
|
||||
$this->assertFileExists($this->lockPath);
|
||||
|
||||
// Validate the contents of package.json
|
||||
$packageJson = json_decode(File::get($this->jsonPath), JSON_OBJECT_AS_ARRAY);
|
||||
$this->assertArrayHasKey('dependencies', $packageJson);
|
||||
$this->assertArrayHasKey('is-odd', $packageJson['dependencies']);
|
||||
$this->assertArrayHasKey('is-even', $packageJson['dependencies']);
|
||||
|
||||
// Validate that node_modules paths exist
|
||||
$this->assertDirectoryExists($this->themePath . '/node_modules');
|
||||
$this->assertDirectoryExists($this->themePath . '/node_modules/is-odd');
|
||||
$this->assertDirectoryExists($this->themePath . '/node_modules/is-even');
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test the ability to install a single dev npm package via artisan
|
||||
*/
|
||||
public function testNpmInstallSingleDev(): void
|
||||
{
|
||||
// Validate the package Json does not have dependencies
|
||||
$packageJson = json_decode(File::get($this->jsonPath), JSON_OBJECT_AS_ARRAY);
|
||||
$this->assertArrayNotHasKey('devDependencies', $packageJson);
|
||||
|
||||
// Validate node_modules not found
|
||||
$this->assertDirectoryDoesNotExist($this->themePath . '/node_modules');
|
||||
$this->assertFileNotExists($this->lockPath);
|
||||
|
||||
$this->withPackageJsonRestore(function () {
|
||||
// Run npm install for a single dev package
|
||||
$this->artisan('npm:install', [
|
||||
'package' => 'theme-npmtest',
|
||||
'npmArgs' => ['is-odd'],
|
||||
'--dev' => true,
|
||||
'--disable-tty' => true
|
||||
])
|
||||
->assertExitCode(0);
|
||||
|
||||
// Validate lock file was generated successfully
|
||||
$this->assertFileExists($this->lockPath);
|
||||
|
||||
// Validate the contents of package.json
|
||||
$packageJson = json_decode(File::get($this->jsonPath), JSON_OBJECT_AS_ARRAY);
|
||||
$this->assertArrayHasKey('devDependencies', $packageJson);
|
||||
$this->assertArrayHasKey('is-odd', $packageJson['devDependencies']);
|
||||
|
||||
// Validate that node_modules paths exist
|
||||
$this->assertDirectoryExists($this->themePath . '/node_modules');
|
||||
$this->assertDirectoryExists($this->themePath . '/node_modules/is-odd');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the ability to install multiple dev npm packages via artisan
|
||||
*/
|
||||
public function testNpmInstallMultipleDev(): void
|
||||
{
|
||||
// Validate the package Json does not have dependencies
|
||||
$packageJson = json_decode(File::get($this->jsonPath), JSON_OBJECT_AS_ARRAY);
|
||||
$this->assertArrayNotHasKey('devDependencies', $packageJson);
|
||||
|
||||
// Validate node_modules not found
|
||||
$this->assertDirectoryDoesNotExist($this->themePath . '/node_modules');
|
||||
$this->assertFileNotExists($this->lockPath);
|
||||
|
||||
$this->withPackageJsonRestore(function () {
|
||||
// Run npm install for multiple dev packages
|
||||
$this->artisan('npm:install', [
|
||||
'package' => 'theme-npmtest',
|
||||
'npmArgs' => ['is-odd', 'is-even'],
|
||||
'--dev' => true,
|
||||
'--disable-tty' => true
|
||||
])
|
||||
->assertExitCode(0);
|
||||
|
||||
// Validate lock file was generated successfully
|
||||
$this->assertFileExists($this->lockPath);
|
||||
|
||||
// Validate the contents of package.json
|
||||
$packageJson = json_decode(File::get($this->jsonPath), JSON_OBJECT_AS_ARRAY);
|
||||
$this->assertArrayHasKey('devDependencies', $packageJson);
|
||||
$this->assertArrayHasKey('is-odd', $packageJson['devDependencies']);
|
||||
$this->assertArrayHasKey('is-even', $packageJson['devDependencies']);
|
||||
|
||||
// Validate that node_modules paths exist
|
||||
$this->assertDirectoryExists($this->themePath . '/node_modules');
|
||||
$this->assertDirectoryExists($this->themePath . '/node_modules/is-odd');
|
||||
$this->assertDirectoryExists($this->themePath . '/node_modules/is-even');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleanup the test theme
|
||||
*/
|
||||
public function tearDown(): void
|
||||
{
|
||||
if (File::isDirectory($this->themePath . '/node_modules')) {
|
||||
File::deleteDirectory($this->themePath . '/node_modules');
|
||||
}
|
||||
|
||||
foreach ([$this->backupPath, $this->lockPath] as $path) {
|
||||
if (File::exists($path)) {
|
||||
File::delete($path);
|
||||
}
|
||||
}
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
}
|
||||
55
modules/system/tests/console/asset/npm/NpmRunTest.php
Normal file
55
modules/system/tests/console/asset/npm/NpmRunTest.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace System\Tests\Console\Asset\Npm;
|
||||
|
||||
use System\Classes\Asset\PackageManager;
|
||||
use System\Tests\Bootstrap\TestCase;
|
||||
use Winter\Storm\Support\Facades\File;
|
||||
|
||||
class NpmRunTest extends TestCase
|
||||
{
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
if (!File::exists(base_path('node_modules'))) {
|
||||
$this->markTestSkipped('This test requires node_modules to be installed');
|
||||
}
|
||||
|
||||
// Add our testing theme because it won't be auto discovered
|
||||
PackageManager::instance()->registerPackage(
|
||||
'theme-npmtest',
|
||||
base_path('modules/system/tests/fixtures/themes/npmtest/vite.config.mjs'),
|
||||
'vite'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the ability to run a npm script via artisan
|
||||
*/
|
||||
public function testNpmRunScript(): void
|
||||
{
|
||||
$this->artisan('npm:run', [
|
||||
'package' => 'theme-npmtest',
|
||||
'script' => 'testScript',
|
||||
'--disable-tty' => true
|
||||
])
|
||||
->expectsOutputToContain('> echo "Winter says $((1+2))"')
|
||||
->expectsOutputToContain('Winter says 3')
|
||||
->assertExitCode(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the error handling of a missing script
|
||||
*/
|
||||
public function testNpmRunScriptFailed(): void
|
||||
{
|
||||
$this->artisan('npm:run', [
|
||||
'package' => 'theme-npmtest',
|
||||
'script' => 'testMissingScript',
|
||||
'--disable-tty' => true
|
||||
])
|
||||
->expectsOutputToContain('Script "testMissingScript" is not defined in package "theme-npmtest"')
|
||||
->assertExitCode(1);
|
||||
}
|
||||
}
|
||||
104
modules/system/tests/console/asset/npm/NpmUpdateTest.php
Normal file
104
modules/system/tests/console/asset/npm/NpmUpdateTest.php
Normal file
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
namespace System\tests\console\asset\npm;
|
||||
|
||||
use System\Classes\Asset\PackageManager;
|
||||
use System\Tests\Bootstrap\TestCase;
|
||||
use System\Tests\Console\Asset\NpmTestTrait;
|
||||
use Winter\Storm\Support\Facades\File;
|
||||
|
||||
class NpmUpdateTest extends TestCase
|
||||
{
|
||||
use NpmTestTrait;
|
||||
|
||||
protected string $themePath;
|
||||
protected string $jsonPath;
|
||||
protected string $lockPath;
|
||||
protected string $backupPath;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
if (!File::exists(base_path('node_modules'))) {
|
||||
$this->markTestSkipped('This test requires node_modules to be installed');
|
||||
}
|
||||
|
||||
// Define some helpful paths
|
||||
$this->themePath = base_path('modules/system/tests/fixtures/themes/npmtest');
|
||||
$this->jsonPath = $this->themePath . '/package.json';
|
||||
$this->lockPath = $this->themePath . '/package-lock.json';
|
||||
$this->backupPath = $this->themePath . '/package.backup.json';
|
||||
|
||||
// Add our testing theme because it won't be auto discovered
|
||||
PackageManager::instance()->registerPackage(
|
||||
'theme-npmtest',
|
||||
$this->themePath . '/vite.config.mjs',
|
||||
'vite'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the ability to install a single npm package via artisan
|
||||
*/
|
||||
public function testNpmUpdate(): void
|
||||
{
|
||||
// Validate the package Json does not have dependencies
|
||||
$packageJson = json_decode(File::get($this->jsonPath), JSON_OBJECT_AS_ARRAY);
|
||||
$this->assertArrayNotHasKey('dependencies', $packageJson);
|
||||
|
||||
// Validate node_modules not found
|
||||
$this->assertDirectoryDoesNotExist($this->themePath . '/node_modules');
|
||||
$this->assertFileNotExists($this->lockPath);
|
||||
|
||||
$this->withPackageJsonRestore(function () {
|
||||
// Update the contents of package.json to include a package at an old patch
|
||||
$packageJson = json_decode(File::get($this->jsonPath), JSON_OBJECT_AS_ARRAY);
|
||||
$packageJson['dependencies'] = [
|
||||
'is-odd' => '^3.0.0'
|
||||
];
|
||||
File::put($this->jsonPath, json_encode($packageJson, JSON_PRETTY_PRINT));
|
||||
|
||||
// Run npm update
|
||||
$this->artisan('npm:update', [
|
||||
'package' => 'theme-npmtest',
|
||||
'--save' => true,
|
||||
'--disable-tty' => true
|
||||
])
|
||||
->assertExitCode(0);
|
||||
|
||||
// Validate lock file was generated successfully
|
||||
$this->assertFileExists($this->lockPath);
|
||||
|
||||
// Get the new contents of package.json
|
||||
$packageJson = json_decode(File::get($this->jsonPath), JSON_OBJECT_AS_ARRAY);
|
||||
|
||||
// Validate that the package.json contents does not match the old patch value we added above
|
||||
$this->assertArrayHasKey('dependencies', $packageJson);
|
||||
$this->assertArrayHasKey('is-odd', $packageJson['dependencies']);
|
||||
$this->assertNotEquals('^3.0.0', $packageJson['dependencies']['is-odd']);
|
||||
|
||||
// Validate that node_modules paths exist
|
||||
$this->assertDirectoryExists($this->themePath . '/node_modules');
|
||||
$this->assertDirectoryExists($this->themePath . '/node_modules/is-odd');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleanup the test theme
|
||||
*/
|
||||
public function tearDown(): void
|
||||
{
|
||||
if (File::isDirectory($this->themePath . '/node_modules')) {
|
||||
File::deleteDirectory($this->themePath . '/node_modules');
|
||||
}
|
||||
|
||||
foreach ([$this->backupPath, $this->lockPath] as $path) {
|
||||
if (File::exists($path)) {
|
||||
File::delete($path);
|
||||
}
|
||||
}
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
}
|
||||
118
modules/system/tests/console/asset/vite/ViteCompileTest.php
Normal file
118
modules/system/tests/console/asset/vite/ViteCompileTest.php
Normal file
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
namespace System\Tests\Console\Asset\Vite;
|
||||
|
||||
use System\Classes\Asset\PackageManager;
|
||||
use System\Tests\Bootstrap\TestCase;
|
||||
use Winter\Storm\Support\Facades\File;
|
||||
|
||||
class ViteCompileTest extends TestCase
|
||||
{
|
||||
protected string $themePath;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
if (!File::exists(base_path('node_modules'))) {
|
||||
$this->markTestSkipped('This test requires node_modules to be installed');
|
||||
}
|
||||
|
||||
if (!File::exists(base_path('node_modules/.bin/vite'))) {
|
||||
$this->markTestSkipped('This test requires the vite package to be installed');
|
||||
}
|
||||
|
||||
$this->themePath = base_path('modules/system/tests/fixtures/themes/assettest');
|
||||
|
||||
// Add our testing theme because it won't be auto discovered
|
||||
PackageManager::instance()->registerPackage(
|
||||
'theme-assettest',
|
||||
$this->themePath . '/vite.config.mjs',
|
||||
'vite'
|
||||
);
|
||||
}
|
||||
|
||||
public function testThemeCompile(): void
|
||||
{
|
||||
// Run the vite:compile command
|
||||
$this->artisan('vite:compile', [
|
||||
'theme-assettest',
|
||||
'--manifest' => 'modules/system/tests/fixtures/npm/package-vitetheme.json',
|
||||
'--silent' => true
|
||||
])->assertExitCode(0);
|
||||
|
||||
$manifestPath = $this->themePath . '/public/build/manifest.json';
|
||||
|
||||
// Validate the manifest was written
|
||||
$this->assertFileExists($manifestPath);
|
||||
|
||||
// Get the contents of the manifest
|
||||
$manifest = json_decode(File::get($manifestPath), JSON_OBJECT_AS_ARRAY);
|
||||
|
||||
// Validate the css was compiled correctly
|
||||
$this->assertArrayHasKey('assets/css/theme.css', $manifest);
|
||||
$this->assertFileExists($this->themePath . '/public/build/' . $manifest['assets/css/theme.css']['file']);
|
||||
$this->assertEquals(
|
||||
'h1{color:red}',
|
||||
trim(File::get($this->themePath . '/public/build/' . $manifest['assets/css/theme.css']['file']))
|
||||
);
|
||||
|
||||
// Validate the js was compiled correctly
|
||||
$this->assertArrayHasKey('assets/javascript/theme.js', $manifest);
|
||||
$this->assertFileExists($this->themePath . '/public/build/' . $manifest['assets/javascript/theme.js']['file']);
|
||||
$this->assertEquals(
|
||||
'window.alert("hello world");',
|
||||
trim(File::get($this->themePath . '/public/build/' . $manifest['assets/javascript/theme.js']['file']))
|
||||
);
|
||||
}
|
||||
|
||||
public function testThemeCompileFailed(): void
|
||||
{
|
||||
// Rename the css file so vite cannot find it
|
||||
File::move($this->themePath . '/assets/css/theme.css', $this->themePath . '/assets/css/theme.back');
|
||||
|
||||
// Run the vite:compile command
|
||||
$this->artisan('vite:compile', [
|
||||
'theme-assettest',
|
||||
'--manifest' => 'modules/system/tests/fixtures/npm/package-vitetheme.json',
|
||||
'--disable-tty' => true
|
||||
])
|
||||
->expectsOutputToContain('Could not resolve entry module "assets/css/theme.css".')
|
||||
->assertExitCode(1);
|
||||
|
||||
// Validate the manifest was not written
|
||||
$this->assertFileNotExists($this->themePath . '/public/build/manifest.json');
|
||||
|
||||
// Put the css file back
|
||||
File::move($this->themePath . '/assets/css/theme.back', $this->themePath . '/assets/css/theme.css');
|
||||
}
|
||||
|
||||
public function testThemeCompileWarning(): void
|
||||
{
|
||||
// Rename the css file so vite cannot find it
|
||||
$contents = File::get($this->themePath . '/assets/css/theme.css');
|
||||
|
||||
File::put($this->themePath . '/assets/css/theme.css', 'h1 {color:');
|
||||
|
||||
// Run the vite:compile command
|
||||
$this->artisan('vite:compile', [
|
||||
'theme-assettest',
|
||||
'--manifest' => 'modules/system/tests/fixtures/npm/package-vitetheme.json',
|
||||
'--disable-tty' => true
|
||||
])
|
||||
->expectsOutputToContain('[WARNING] Expected "}" to go with "{" [css-syntax-error]')
|
||||
->assertExitCode(0);
|
||||
|
||||
// Validate the manifest was not written
|
||||
$this->assertFileExists($this->themePath . '/public/build/manifest.json');
|
||||
|
||||
// Put the css file back
|
||||
File::put($this->themePath . '/assets/css/theme.css', $contents);
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
{
|
||||
File::deleteDirectory('modules/system/tests/fixtures/themes/assettest/public');
|
||||
parent::tearDown();
|
||||
}
|
||||
}
|
||||
234
modules/system/tests/console/asset/vite/ViteCreateTest.php
Normal file
234
modules/system/tests/console/asset/vite/ViteCreateTest.php
Normal file
@@ -0,0 +1,234 @@
|
||||
<?php
|
||||
|
||||
namespace System\Tests\Console\Asset\Vite;
|
||||
|
||||
use System\Classes\PluginManager;
|
||||
use System\Tests\Bootstrap\TestCase;
|
||||
use Winter\Storm\Support\Facades\File;
|
||||
|
||||
class ViteCreateTest extends TestCase
|
||||
{
|
||||
protected string $testPlugin = 'Winter.Sample';
|
||||
|
||||
public function testConfigWritten(): void
|
||||
{
|
||||
$path = PluginManager::instance()->findByIdentifier($this->testPlugin)->getPluginPath();
|
||||
$configPath = $path . '/vite.config.mjs';
|
||||
|
||||
// Check file does not exist
|
||||
$this->assertFileNotExists($configPath);
|
||||
|
||||
// Run the config command to generate the vite config
|
||||
$this->artisan('vite:create', [
|
||||
'packageName' => $this->testPlugin,
|
||||
'--no-stubs' => true,
|
||||
])
|
||||
->doesntExpectOutput('vite.config.mjs already exists, overwrite?')
|
||||
->assertExitCode(0);
|
||||
|
||||
// Validate the manifest was written
|
||||
$this->assertFileExists($configPath);
|
||||
|
||||
// Get the predicted contents
|
||||
$fixture = str_replace(
|
||||
'{{packageName}}',
|
||||
'winter-sample',
|
||||
File::get(base_path('modules/system/console/asset/fixtures/config/vite/vite.config.mjs.fixture')),
|
||||
);
|
||||
|
||||
// Check the file written is what was expected
|
||||
$this->assertEquals($fixture, File::get($configPath));
|
||||
|
||||
// Overwrite the file content
|
||||
File::put($configPath, 'testing');
|
||||
|
||||
// Check that refusing to overwrite does not replace file contents
|
||||
$this->artisan('vite:create', [
|
||||
'packageName' => $this->testPlugin,
|
||||
'--no-stubs' => true,
|
||||
])
|
||||
->expectsQuestion('vite.config.mjs already exists, overwrite?', false)
|
||||
->assertExitCode(0);
|
||||
|
||||
// Check file contents was not overwritten
|
||||
$this->assertNotEquals($fixture, File::get($configPath));
|
||||
|
||||
// Run command confirming to overwrite file contents works
|
||||
$this->artisan('vite:create', [
|
||||
'packageName' => $this->testPlugin,
|
||||
'--no-stubs' => true,
|
||||
])
|
||||
->expectsQuestion('vite.config.mjs already exists, overwrite?', true)
|
||||
->assertExitCode(0);
|
||||
|
||||
// Check file contents was overwritten
|
||||
$this->assertEquals($fixture, File::get($configPath));
|
||||
}
|
||||
|
||||
public function testConfigTailwind(): void
|
||||
{
|
||||
$path = PluginManager::instance()->findByIdentifier($this->testPlugin)->getPluginPath();
|
||||
$configPath = $path . '/vite.config.mjs';
|
||||
$packageJson = $path . '/package.json';
|
||||
|
||||
// Check file does not exist
|
||||
$this->assertFileNotExists($configPath);
|
||||
|
||||
// Run the config command to generate the vite config
|
||||
$this->artisan('vite:create', [
|
||||
'packageName' => $this->testPlugin,
|
||||
'--tailwind' => true,
|
||||
'--no-stubs' => true,
|
||||
])
|
||||
->assertExitCode(0);
|
||||
|
||||
// Check files are created correctly
|
||||
$this->assertFileExists($configPath);
|
||||
$this->assertFileExists($path . '/tailwind.config.js');
|
||||
$this->assertFileExists($path . '/postcss.config.mjs');
|
||||
|
||||
// Get the contents of the package.json
|
||||
$json = json_decode(File::get($packageJson));
|
||||
|
||||
// Check tailwindcss is required
|
||||
$this->assertTrue(isset($json->devDependencies->tailwindcss));
|
||||
}
|
||||
|
||||
public function testConfigReact(): void
|
||||
{
|
||||
$path = PluginManager::instance()->findByIdentifier($this->testPlugin)->getPluginPath();
|
||||
$configPath = $path . '/vite.config.mjs';
|
||||
$packageJson = $path . '/package.json';
|
||||
|
||||
// Check file does not exist
|
||||
$this->assertFileNotExists($configPath);
|
||||
|
||||
// Run the config command to generate the vite config with react
|
||||
$this->artisan('vite:create', [
|
||||
'packageName' => $this->testPlugin,
|
||||
'--react' => true,
|
||||
'--no-stubs' => true,
|
||||
])
|
||||
->assertExitCode(0);
|
||||
|
||||
// Check files are created correctly
|
||||
$this->assertFileExists($configPath);
|
||||
$this->assertFileExists($packageJson);
|
||||
|
||||
// Get the contents of the package.json
|
||||
$json = json_decode(File::get($packageJson));
|
||||
|
||||
// Check react is required
|
||||
$this->assertTrue(isset($json->devDependencies->react));
|
||||
}
|
||||
|
||||
public function testConfigTailwindReact(): void
|
||||
{
|
||||
$path = PluginManager::instance()->findByIdentifier($this->testPlugin)->getPluginPath();
|
||||
$configPath = $path . '/vite.config.mjs';
|
||||
$packageJson = $path . '/package.json';
|
||||
|
||||
// Check file does not exist
|
||||
$this->assertFileNotExists($configPath);
|
||||
|
||||
// Run the config command to generate the vite config with react
|
||||
$this->artisan('vite:create', [
|
||||
'packageName' => $this->testPlugin,
|
||||
'--tailwind' => true,
|
||||
'--react' => true,
|
||||
'--no-stubs' => true,
|
||||
])
|
||||
->assertExitCode(0);
|
||||
|
||||
// Check files are created correctly
|
||||
$this->assertFileExists($configPath);
|
||||
$this->assertFileExists($packageJson);
|
||||
$this->assertFileExists($path . '/tailwind.config.js');
|
||||
$this->assertFileExists($path . '/postcss.config.mjs');
|
||||
|
||||
// Get the contents of the package.json
|
||||
$json = json_decode(File::get($packageJson));
|
||||
|
||||
// Check tailwind & react are required
|
||||
$this->assertTrue(isset($json->devDependencies->tailwindcss));
|
||||
$this->assertTrue(isset($json->devDependencies->react));
|
||||
}
|
||||
|
||||
public function testConfigVue(): void
|
||||
{
|
||||
$path = PluginManager::instance()->findByIdentifier($this->testPlugin)->getPluginPath();
|
||||
$configPath = $path . '/vite.config.mjs';
|
||||
$packageJson = $path . '/package.json';
|
||||
|
||||
// Check file does not exist
|
||||
$this->assertFileNotExists($configPath);
|
||||
|
||||
// Run the config command to generate the vite config with vue
|
||||
$this->artisan('vite:create', [
|
||||
'packageName' => $this->testPlugin,
|
||||
'--vue' => true,
|
||||
'--no-stubs' => true,
|
||||
])
|
||||
->assertExitCode(0);
|
||||
|
||||
// Check files are created correctly
|
||||
$this->assertFileExists($configPath);
|
||||
$this->assertFileExists($packageJson);
|
||||
|
||||
// Get the contents of the package.json
|
||||
$json = json_decode(File::get($packageJson));
|
||||
|
||||
// Check vue is required
|
||||
$this->assertTrue(isset($json->devDependencies->vue));
|
||||
}
|
||||
|
||||
public function testConfigTailwindVue(): void
|
||||
{
|
||||
$path = PluginManager::instance()->findByIdentifier($this->testPlugin)->getPluginPath();
|
||||
$configPath = $path . '/vite.config.mjs';
|
||||
$packageJson = $path . '/package.json';
|
||||
|
||||
// Check file does not exist
|
||||
$this->assertFileNotExists($configPath);
|
||||
|
||||
// Run the config command to generate the vite config with vue
|
||||
$this->artisan('vite:create', [
|
||||
'packageName' => $this->testPlugin,
|
||||
'--tailwind' => true,
|
||||
'--vue' => true,
|
||||
'--no-stubs' => true,
|
||||
])
|
||||
->assertExitCode(0);
|
||||
|
||||
// Check files are created correctly
|
||||
$this->assertFileExists($configPath);
|
||||
$this->assertFileExists($packageJson);
|
||||
$this->assertFileExists($path . '/tailwind.config.js');
|
||||
$this->assertFileExists($path . '/postcss.config.mjs');
|
||||
|
||||
// Get the contents of the package.json
|
||||
$json = json_decode(File::get($packageJson));
|
||||
|
||||
// Check tailwind & vue are required
|
||||
$this->assertTrue(isset($json->devDependencies->tailwindcss));
|
||||
$this->assertTrue(isset($json->devDependencies->vue));
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
{
|
||||
$path = PluginManager::instance()->findByIdentifier($this->testPlugin)->getPluginPath();
|
||||
|
||||
$files = [
|
||||
$path . '/vite.config.mjs',
|
||||
$path . '/package.json',
|
||||
$path . '/tailwind.config.js',
|
||||
$path . '/postcss.config.mjs',
|
||||
];
|
||||
|
||||
foreach ($files as $file) {
|
||||
if (File::exists($file)) {
|
||||
File::delete($file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
223
modules/system/tests/console/asset/vite/ViteInstallTest.php
Normal file
223
modules/system/tests/console/asset/vite/ViteInstallTest.php
Normal file
@@ -0,0 +1,223 @@
|
||||
<?php
|
||||
|
||||
namespace System\Tests\Console\Asset\Vite;
|
||||
|
||||
use System\Classes\Asset\PackageManager;
|
||||
use System\Tests\Bootstrap\TestCase;
|
||||
use Winter\Storm\Exception\SystemException;
|
||||
use Winter\Storm\Support\Facades\File;
|
||||
|
||||
class ViteInstallTest extends TestCase
|
||||
{
|
||||
protected string $jsonPath;
|
||||
protected string $lockPath;
|
||||
protected string $backupPath;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
if (!File::exists(base_path('node_modules'))) {
|
||||
$this->markTestSkipped('This test requires node_modules to be installed');
|
||||
}
|
||||
|
||||
// Define some helpful paths
|
||||
$this->fixturePath = base_path('modules/system/tests');
|
||||
$this->jsonPath = $this->fixturePath . '/package.json';
|
||||
$this->lockPath = $this->fixturePath . '/package-lock.json';
|
||||
$this->backupPath = $this->fixturePath . '/package-testing.json';
|
||||
|
||||
// Add our testing theme because it won't be auto discovered
|
||||
PackageManager::instance()->registerPackage(
|
||||
'theme-assettest',
|
||||
base_path('modules/system/tests/fixtures/themes/assettest/vite.config.mjs'),
|
||||
'vite'
|
||||
);
|
||||
PackageManager::instance()->registerPackage(
|
||||
'theme-npmtest',
|
||||
base_path('modules/system/tests/fixtures/themes/npmtest/vite.config.mjs'),
|
||||
'vite'
|
||||
);
|
||||
}
|
||||
|
||||
public function testViteInstallMissingPackageJson(): void
|
||||
{
|
||||
$this->artisan('vite:install', [
|
||||
'assetPackage' => ['theme-assettest'],
|
||||
'--package-json' => '/some/file',
|
||||
'--no-install' => true
|
||||
])
|
||||
->expectsOutputToContain('The supplied --package-json path does not exist.')
|
||||
->assertExitCode(1);
|
||||
}
|
||||
|
||||
public function testViteInstallSinglePackage(): void
|
||||
{
|
||||
$this->withPackageJsonRestore(function () {
|
||||
$this->artisan('vite:install', [
|
||||
'assetPackage' => ['theme-assettest'],
|
||||
'--package-json' => $this->jsonPath,
|
||||
'--no-install' => true
|
||||
])
|
||||
->expectsQuestion('vite was not found as a dependency in package.json, would you like to add it?', true)
|
||||
->expectsQuestion('laravel-vite-plugin was not found as a dependency in package.json, would you like to add it?', true)
|
||||
->expectsOutput('Adding theme-assettest (modules/system/tests/fixtures/themes/assettest) to the workspaces.packages property in package.json')
|
||||
->assertExitCode(0);
|
||||
|
||||
$this->assertFileExists($this->jsonPath);
|
||||
$packageJson = json_decode(File::get($this->jsonPath), JSON_OBJECT_AS_ARRAY);
|
||||
$this->assertArrayHasKey('devDependencies', $packageJson);
|
||||
$this->assertArrayHasKey('vite', $packageJson['devDependencies']);
|
||||
$this->assertArrayHasKey('laravel-vite-plugin', $packageJson['devDependencies']);
|
||||
|
||||
$this->assertArrayHasKey('workspaces', $packageJson);
|
||||
$this->assertArrayHasKey('packages', $packageJson['workspaces']);
|
||||
$this->assertContains('modules/system/tests/fixtures/themes/assettest', $packageJson['workspaces']['packages']);
|
||||
});
|
||||
}
|
||||
|
||||
public function testViteInstallMultiplePackages(): void
|
||||
{
|
||||
$this->withPackageJsonRestore(function () {
|
||||
$this->artisan('vite:install', [
|
||||
'assetPackage' => ['theme-assettest', 'theme-npmtest'],
|
||||
'--package-json' => $this->jsonPath,
|
||||
'--no-install' => true
|
||||
])
|
||||
->expectsQuestion('vite was not found as a dependency in package.json, would you like to add it?', true)
|
||||
->expectsQuestion('laravel-vite-plugin was not found as a dependency in package.json, would you like to add it?', true)
|
||||
->expectsOutput('Adding theme-assettest (modules/system/tests/fixtures/themes/assettest) to the workspaces.packages property in package.json')
|
||||
->expectsOutput('Adding theme-npmtest (modules/system/tests/fixtures/themes/npmtest) to the workspaces.packages property in package.json')
|
||||
->assertExitCode(0);
|
||||
|
||||
$this->assertFileExists($this->jsonPath);
|
||||
$packageJson = json_decode(File::get($this->jsonPath), JSON_OBJECT_AS_ARRAY);
|
||||
$this->assertArrayHasKey('devDependencies', $packageJson);
|
||||
$this->assertArrayHasKey('vite', $packageJson['devDependencies']);
|
||||
$this->assertArrayHasKey('laravel-vite-plugin', $packageJson['devDependencies']);
|
||||
|
||||
$this->assertArrayHasKey('workspaces', $packageJson);
|
||||
$this->assertArrayHasKey('packages', $packageJson['workspaces']);
|
||||
$this->assertContains('modules/system/tests/fixtures/themes/assettest', $packageJson['workspaces']['packages']);
|
||||
$this->assertContains('modules/system/tests/fixtures/themes/npmtest', $packageJson['workspaces']['packages']);
|
||||
});
|
||||
}
|
||||
|
||||
public function testViteInstallMissingPackage(): void
|
||||
{
|
||||
// We should receive an exception for a missing package
|
||||
$this->withPackageJsonRestore(function () {
|
||||
$this->expectException(SystemException::class);
|
||||
$this->expectExceptionMessage('PackageNotFoundException: The package `theme-assettest2` does not exist.');
|
||||
|
||||
$this->artisan('vite:install', [
|
||||
'assetPackage' => ['theme-assettest2'],
|
||||
'--package-json' => $this->jsonPath,
|
||||
'--no-install' => true
|
||||
])
|
||||
->assertExitCode(1);
|
||||
});
|
||||
}
|
||||
|
||||
public function testViteInstallRelativePath(): void
|
||||
{
|
||||
$this->withPackageJsonRestore(function () {
|
||||
$this->artisan('vite:install', [
|
||||
'assetPackage' => ['theme-assettest'],
|
||||
'--package-json' => 'modules/system/tests/package.json',
|
||||
'--no-install' => true
|
||||
])
|
||||
->expectsQuestion('vite was not found as a dependency in package.json, would you like to add it?', true)
|
||||
->expectsQuestion('laravel-vite-plugin was not found as a dependency in package.json, would you like to add it?', true)
|
||||
->expectsOutput('Adding theme-assettest (modules/system/tests/fixtures/themes/assettest) to the workspaces.packages property in package.json')
|
||||
->assertExitCode(0);
|
||||
});
|
||||
}
|
||||
|
||||
public function testViteInstallIgnoredPackage(): void
|
||||
{
|
||||
$this->withPackageJsonRestore(function () {
|
||||
$packageJson = json_decode(File::get($this->jsonPath), JSON_OBJECT_AS_ARRAY);
|
||||
$packageJson['workspaces'] = [
|
||||
'ignoredPackages' => [
|
||||
'modules/system/tests/fixtures/themes/assettest'
|
||||
]
|
||||
];
|
||||
|
||||
File::put($this->jsonPath, json_encode($packageJson, JSON_PRETTY_PRINT));
|
||||
|
||||
$this->artisan('vite:install', [
|
||||
'assetPackage' => ['theme-assettest'],
|
||||
'--package-json' => $this->jsonPath,
|
||||
'--no-install' => true
|
||||
])
|
||||
->expectsQuestion('vite was not found as a dependency in package.json, would you like to add it?', false)
|
||||
->expectsQuestion('laravel-vite-plugin was not found as a dependency in package.json, would you like to add it?', false)
|
||||
->expectsOutput('The requested package theme-assettest (modules/system/tests/fixtures/themes/assettest) is ignored, remove it from package.json to continue.')
|
||||
->assertExitCode(0);
|
||||
|
||||
$packageJson = json_decode(File::get($this->jsonPath), JSON_OBJECT_AS_ARRAY);
|
||||
$this->assertArrayHasKey('workspaces', $packageJson);
|
||||
$this->assertArrayNotHasKey('packages', $packageJson['workspaces']);
|
||||
$this->assertArrayNotHasKey('dependencies', $packageJson);
|
||||
$this->assertArrayNotHasKey('devDependencies', $packageJson);
|
||||
});
|
||||
}
|
||||
|
||||
public function testViteInstallWithNpmInstall(): void
|
||||
{
|
||||
$this->withPackageJsonRestore(function () {
|
||||
$this->assertDirectoryDoesNotExist($this->fixturePath . '/node_modules');
|
||||
|
||||
$this->artisan('vite:install', [
|
||||
'assetPackage' => ['theme-assettest'],
|
||||
'--package-json' => $this->jsonPath,
|
||||
'--disable-tty' => true
|
||||
])
|
||||
->expectsQuestion('vite was not found as a dependency in package.json, would you like to add it?', true)
|
||||
->expectsQuestion('laravel-vite-plugin was not found as a dependency in package.json, would you like to add it?', true)
|
||||
->expectsOutput('Adding theme-assettest (modules/system/tests/fixtures/themes/assettest) to the workspaces.packages property in package.json')
|
||||
->expectsOutputToContain('packages, and audited') // output from npm i
|
||||
->assertExitCode(0);
|
||||
|
||||
$this->assertFileExists($this->jsonPath);
|
||||
$packageJson = json_decode(File::get($this->jsonPath), JSON_OBJECT_AS_ARRAY);
|
||||
$this->assertArrayHasKey('devDependencies', $packageJson);
|
||||
$this->assertArrayHasKey('vite', $packageJson['devDependencies']);
|
||||
$this->assertArrayHasKey('laravel-vite-plugin', $packageJson['devDependencies']);
|
||||
|
||||
$this->assertArrayHasKey('workspaces', $packageJson);
|
||||
$this->assertArrayHasKey('packages', $packageJson['workspaces']);
|
||||
$this->assertContains('modules/system/tests/fixtures/themes/assettest', $packageJson['workspaces']['packages']);
|
||||
|
||||
$this->assertFileExists($this->lockPath);
|
||||
|
||||
$this->assertDirectoryExists($this->fixturePath . '/node_modules');
|
||||
$this->assertDirectoryExists($this->fixturePath . '/node_modules/vite');
|
||||
$this->assertDirectoryExists($this->fixturePath . '/node_modules/laravel-vite-plugin');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to run test logic and handle restoring package.json file after
|
||||
*/
|
||||
protected function withPackageJsonRestore(callable $callback): void
|
||||
{
|
||||
File::copy($this->backupPath, $this->jsonPath);
|
||||
$callback();
|
||||
File::delete($this->jsonPath);
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
{
|
||||
if (File::isDirectory($this->fixturePath . '/node_modules')) {
|
||||
File::deleteDirectory($this->fixturePath . '/node_modules');
|
||||
}
|
||||
|
||||
if (File::exists($this->lockPath)) {
|
||||
File::delete($this->lockPath);
|
||||
}
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user