Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
idleberg committed Aug 31, 2022
1 parent b1bda3d commit 5390710
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/_data/manifest-empty-css.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"demo.ts": {
"file": "assets/index.deadbeef.js",
"src": "demo.ts",
"isEntry": true,
"imports": [
"vendor.deadbeef.js"
],
"css": []
},
"vendor.deadbeef.js": {
"file": "assets/vendor.deadbeef.js"
}
}
11 changes: 11 additions & 0 deletions tests/_data/manifest-empty-imports.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"demo.ts": {
"file": "assets/index.deadbeef.js",
"src": "demo.ts",
"isEntry": true,
"imports": [],
"css": [
"assets/index.deadbeef.css"
]
}
}
38 changes: 38 additions & 0 deletions tests/unit/ViteManifestEmptyCssTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

use Idleberg\ViteManifest\ViteManifest;

class ViteManifestEmptyCssTest extends \Codeception\Test\Unit
{
/**
* @var \UnitTester
*/
protected $tester;
protected $vm;
protected $baseUrl = __DIR__ . "/../_data/";
protected $manifest = __DIR__ . "/../_data/manifest-empty-css.json";

protected function _before()
{
$this->vm = new ViteManifest($this->manifest, $this->baseUrl);
}

protected function _after()
{
// The void
}

// tests
public function testGetManifest()
{
$actual = $this->vm->getManifest();
$expected = json_decode('{"demo.ts":{"file":"assets/index.deadbeef.js","src":"demo.ts","isEntry":true,"imports":["vendor.deadbeef.js"],"css":[]},"vendor.deadbeef.js":{"file":"assets/vendor.deadbeef.js"}}', true);

$this->assertEquals($actual, $expected);
}

public function testGetStyles()
{
$this->assertEquals(count($this->vm->getStyles("demo.ts")), 0);
}
}
38 changes: 38 additions & 0 deletions tests/unit/ViteManifestEmptyImportsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

use Idleberg\ViteManifest\ViteManifest;

class ViteManifestEmptyImportsTest extends \Codeception\Test\Unit
{
/**
* @var \UnitTester
*/
protected $tester;
protected $vm;
protected $baseUrl = __DIR__ . "/../_data/";
protected $manifest = __DIR__ . "/../_data/manifest-empty-imports.json";

protected function _before()
{
$this->vm = new ViteManifest($this->manifest, $this->baseUrl);
}

protected function _after()
{
// The void
}

// tests
public function testGetManifest()
{
$actual = $this->vm->getManifest();
$expected = json_decode('{"demo.ts":{"file":"assets/index.deadbeef.js","src":"demo.ts","isEntry":true,"imports":[],"css":["assets/index.deadbeef.css"]}}', true);

$this->assertEquals($actual, $expected);
}

public function testGetImports()
{
$this->assertEquals(count($this->vm->getImports("demo.ts")), 0);
}
}

0 comments on commit 5390710

Please sign in to comment.