Skip to content

Commit 7fa064e

Browse files
committed
Test
1 parent a46296e commit 7fa064e

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

packages/framework/tests/Feature/Views/MetadataViewTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ protected function setUp(): void
2626

2727
$this->withSiteUrl();
2828
config(['hyde.cache_busting' => false]);
29+
30+
// Ensure Vite is not detected as running during tests
31+
// This prevents Windows-specific issues with stale vite.hot files
32+
$this->ensureViteNotRunning();
2933
}
3034

3135
protected function build(?string $page = null): void
@@ -54,6 +58,18 @@ protected function assertSee(string $page, string|array $text): string|array
5458
return $text;
5559
}
5660

61+
protected function ensureViteNotRunning(): void
62+
{
63+
$hotFile = 'app/storage/framework/runtime/vite.hot';
64+
65+
if (\Hyde\Facades\Filesystem::exists($hotFile)) {
66+
\Hyde\Facades\Filesystem::delete($hotFile);
67+
}
68+
69+
// Mark for cleanup in case any test creates it
70+
$this->cleanUpWhenDone($hotFile);
71+
}
72+
5773
protected function assertAllTagsWereCovered(string $page, array $tags): void
5874
{
5975
$expected = file_get_contents(Hyde::path("_site/$page.html"));

packages/framework/tests/Unit/Facades/ViteFacadeTest.php

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,34 @@ protected function tearDown(): void
2222
$this->cleanUpFilesystem();
2323
}
2424

25-
public function testRunningReturnsTrueWhenViteHotFileExists()
25+
public function testRunningReturnsFalseWhenViteHotFileExistsButPortIsNotActive()
2626
{
2727
$this->file('app/storage/framework/runtime/vite.hot');
2828

29-
$this->assertTrue(Vite::running());
29+
// Since port 5173 is not actually in use, Vite::running() should return false
30+
// and clean up the stale hot file
31+
$this->assertFalse(Vite::running());
32+
33+
// The stale hot file should be cleaned up
34+
$this->assertFileDoesNotExist('app/storage/framework/runtime/vite.hot');
35+
}
36+
37+
public function testRunningReturnsTrueWhenViteHotFileExistsAndPortIsActive()
38+
{
39+
$this->file('app/storage/framework/runtime/vite.hot');
40+
41+
// Mock a server running on port 5173
42+
$socket = stream_socket_server('tcp://127.0.0.1:5173', $errno, $errstr);
43+
44+
if ($socket !== false) {
45+
try {
46+
$this->assertTrue(Vite::running());
47+
} finally {
48+
stream_socket_shutdown($socket, STREAM_SHUT_RDWR);
49+
}
50+
} else {
51+
$this->markTestSkipped('Unable to bind to port 5173 for testing');
52+
}
3053
}
3154

3255
public function testRunningReturnsFalseWhenViteHotFileDoesNotExist()

0 commit comments

Comments
 (0)