Skip to content

Commit

Permalink
[TASK] Add test coverage for css-only entrypoints
Browse files Browse the repository at this point in the history
  • Loading branch information
s2b committed Aug 2, 2024
1 parent df941c3 commit 590e720
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Tests/Fixtures/OnlyCssManifest/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"Main.scss": {
"file": "assets/Main-4483b920.css",
"isEntry": true,
"src": "Main.scss"
}
}
41 changes: 41 additions & 0 deletions Tests/Unit/Domain/Model/ViteManifestItemTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

namespace Praetorius\ViteAssetCollector\Tests\Unit\Service;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use Praetorius\ViteAssetCollector\Domain\Model\ViteManifestItem;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;

final class ViteManifestItemTest extends UnitTestCase
{
public static function isCssDataProvider(): array
{
return [
'Main.js' => [
new ViteManifestItem('Main.js', 'Main.js', 'assets/Main-4483b920.js', true, false, [], [], [], []),
false,
],
'Main.css' => [
new ViteManifestItem('Main.css', 'Main.css', 'assets/Main-4483b920.css', true, false, [], [], [], []),
true,
],
'Main.scss' => [
new ViteManifestItem('Main.scss', 'Main.scss', 'assets/Main-4483b920.css', true, false, [], [], [], []),
true,
],
];
}

#[Test]
#[DataProvider('isCssDataProvider')]
public function isCss(ViteManifestItem $item, bool $expected): void
{
self::assertEquals(
$expected,
$item->isCss()
);
}
}
26 changes: 26 additions & 0 deletions Tests/Unit/Service/ViteServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,32 @@ public static function addAssetsFromManifestDataProvider(): array
],
[],
],
'onlyCss' => [
$fixtureDir . 'OnlyCssManifest/manifest.json',
'Main.scss',
[],
true,
[],
[],
[
'vite:Main.scss' => [
'source' => $fixtureDir . 'OnlyCssManifest/assets/Main-4483b920.css',
'attributes' => ['media' => 'print', 'disabled' => 'disabled'],
'options' => [],
],
],
[],
],
'onlyCssFlagDisabled' => [
$fixtureDir . 'OnlyCssManifest/manifest.json',
'Main.scss',
[],
false,
[],
[],
[],
[],
],
'withCssAndPriority' => [
$fixtureDir . 'ValidManifest/manifest.json',
'Main.js',
Expand Down

0 comments on commit 590e720

Please sign in to comment.