Skip to content

Commit e8b0cae

Browse files
authored
Merge pull request #16 from o2ps/fix-manifest-dev-server-url
Fix BuildDirectoryProvider pointing to public URL of dev server
2 parents 7f4fa1d + a7f60ad commit e8b0cae

File tree

5 files changed

+69
-7
lines changed

5 files changed

+69
-7
lines changed

src/BuildDirectoryProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function __construct(string $directory, DevServer $devServer)
3232
public function getBuildDirectory(): string
3333
{
3434
return $this->devServer->isAvailable()
35-
? $this->devServer->getUrl()
35+
? $this->devServer->getInternalUrl()
3636
: $this->directory;
3737
}
3838

src/DevServer.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ class DevServer
3131
*/
3232
private $publicUrl;
3333

34-
/**
35-
* @var float
36-
*/
34+
/**
35+
* @var float
36+
*/
3737
private $timeout;
3838

3939
/**
@@ -58,6 +58,12 @@ public function getUrl(): string
5858
}
5959

6060

61+
public function getInternalUrl(): string
62+
{
63+
return $this->url;
64+
}
65+
66+
6167
public function isEnabled(): bool
6268
{
6369
return $this->enabled;
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
namespace OopsTests\WebpackNetteAdapter;
6+
7+
use Oops\WebpackNetteAdapter\BuildDirectoryProvider;
8+
use Oops\WebpackNetteAdapter\DevServer;
9+
use Tester\Assert;
10+
use Tester\TestCase;
11+
12+
13+
require_once __DIR__ . '/../bootstrap.php';
14+
15+
16+
/**
17+
* @testCase
18+
*/
19+
class BuildDirectoryProviderTest extends TestCase
20+
{
21+
22+
public function testWithDevServer(): void
23+
{
24+
$devServer = \Mockery::mock(DevServer::class);
25+
$devServer->shouldReceive('isAvailable')->andReturn(TRUE);
26+
$devServer->shouldReceive('getInternalUrl')->andReturn('http://localhost:3000');
27+
28+
$provider = new BuildDirectoryProvider('dist/', $devServer);
29+
Assert::same('http://localhost:3000', $provider->getBuildDirectory());
30+
}
31+
32+
33+
public function testWithoutDevServer(): void
34+
{
35+
$devServer = \Mockery::mock(DevServer::class);
36+
$devServer->shouldReceive('isAvailable')->andReturn(FALSE);
37+
$devServer->shouldReceive('getInternalUrl')->never();
38+
39+
$provider = new BuildDirectoryProvider('dist/', $devServer);
40+
Assert::same('dist/', $provider->getBuildDirectory());
41+
}
42+
43+
44+
protected function tearDown(): void
45+
{
46+
parent::tearDown();
47+
\Mockery::close();
48+
}
49+
50+
}
51+
52+
53+
(new BuildDirectoryProviderTest())->run();

tests/WebpackNetteAdapter/DI/WebpackExtensionTest.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,15 @@ class WebpackExtensionTest extends TestCase
112112
// mock devServer so that it is available
113113
$devServerMock = \Mockery::mock(DevServer::class);
114114
$devServerMock->shouldReceive('getUrl')->andReturn('/devServer/');
115+
$devServerMock->shouldReceive('getInternalUrl')->andReturn('/devServer-internal/');
115116
$devServerMock->shouldReceive('isAvailable')->andReturn(TRUE);
116117
$container->removeService('webpack.devServer');
117118
$container->addService('webpack.devServer', $devServerMock);
118119

119120
/** @var AssetLocator $assetLocator */
120121
$assetLocator = $container->getByType(AssetLocator::class);
121122
Assert::same('/devServer/foo.js', $assetLocator->locateInPublicPath('foo.js'));
122-
Assert::same('/devServer/foo.js', $assetLocator->locateInBuildDirectory('foo.js'));
123+
Assert::same('/devServer-internal/foo.js', $assetLocator->locateInBuildDirectory('foo.js'));
123124
Assert::same('data:,', $assetLocator->locateInPublicPath('foo.css'));
124125
Assert::same('data:,', $assetLocator->locateInBuildDirectory('foo.css'));
125126

tests/WebpackNetteAdapter/DevServerTest.phpt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class DevServerTest extends TestCase
4141
$devServer = new DevServer(TRUE, 'http://localhost:3000', NULL, 0.1, $this->httpClient);
4242
Assert::true($devServer->isEnabled());
4343
Assert::same($devServer->getUrl(), 'http://localhost:3000');
44+
Assert::same($devServer->getInternalUrl(), 'http://localhost:3000');
4445

4546
$this->httpClient->shouldReceive('request')
4647
->with('GET', 'http://localhost:3000', ['http_errors' => FALSE, 'verify' => FALSE, 'timeout' => 0.1])
@@ -53,9 +54,10 @@ class DevServerTest extends TestCase
5354
{
5455
$devServer = new DevServer(TRUE, 'http://localhost:3000', 'http://localhost:3030', 0.1, $this->httpClient);
5556
Assert::true($devServer->isEnabled());
56-
Assert::same($devServer->getUrl(), 'http://localhost:3030');
57+
Assert::same($devServer->getUrl(), 'http://localhost:3030');
58+
Assert::same($devServer->getInternalUrl(), 'http://localhost:3000');
5759

58-
$this->httpClient->shouldReceive('request')
60+
$this->httpClient->shouldReceive('request')
5961
->with('GET', 'http://localhost:3000', ['http_errors' => FALSE, 'verify' => FALSE, 'timeout' => 0.1])
6062
->andReturn(new Response(404));
6163

0 commit comments

Comments
 (0)