latest test updates

This commit is contained in:
Mark Gregory
2026-06-15 11:59:41 +01:00
parent 1fd9be097e
commit 330d6922a4
4 changed files with 88 additions and 20 deletions
+28 -12
View File
@@ -5,7 +5,6 @@ namespace Tests;
use Facebook\WebDriver\Chrome\ChromeOptions;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Illuminate\Support\Facades\Artisan;
use Laravel\Dusk\TestCase as BaseTestCase;
use PHPUnit\Framework\Attributes\BeforeClass;
@@ -22,6 +21,7 @@ abstract class DuskTestCase extends BaseTestCase
if (! static::runningInSail()) {
static::ensureChromeDriverBinaryAlias();
static::startChromeDriver(['--port=9515']);
static::waitForChromeDriver();
}
}
@@ -50,11 +50,13 @@ abstract class DuskTestCase extends BaseTestCase
/**
* Dusk may install a differently named macOS Apple Silicon binary.
* Laravel Dusk still asks for chromedriver-mac-arm, so create that alias safely.
*
* This method intentionally does not use base_path(), app(), or Artisan because
* PHPUnit calls BeforeClass before Laravel has booted the application container.
*/
private static function ensureChromeDriverBinaryAlias(): void
{
$binDirectory = base_path('vendor/laravel/dusk/bin');
$binDirectory = dirname(__DIR__).'/vendor/laravel/dusk/bin';
$expected = $binDirectory.'/chromedriver-mac-arm';
if (is_file($expected)) {
@@ -67,12 +69,6 @@ abstract class DuskTestCase extends BaseTestCase
@mkdir($binDirectory, 0755, true);
}
try {
Artisan::call('dusk:chrome-driver');
} catch (\Throwable) {
//
}
$candidates = array_values(array_filter(
glob($binDirectory.'/chromedriver*') ?: [],
static function (string $path) use ($expected): bool {
@@ -85,9 +81,9 @@ abstract class DuskTestCase extends BaseTestCase
usort($candidates, static function (string $left, string $right): int {
$score = static fn (string $path): int =>
str_contains($path, 'mac-arm64') ? 0
: (str_contains($path, 'mac-arm') ? 1
: (str_contains($path, 'mac') ? 2 : 3));
str_contains($path, 'mac-arm64') ? 0
: (str_contains($path, 'mac-arm') ? 1
: (str_contains($path, 'mac') ? 2 : 3));
return $score($left) <=> $score($right);
});
@@ -97,4 +93,24 @@ abstract class DuskTestCase extends BaseTestCase
@chmod($expected, 0755);
}
}
/**
* Wait until ChromeDriver is listening before the first browser session starts.
*/
private static function waitForChromeDriver(): void
{
$deadline = microtime(true) + 5.0;
do {
$connection = @fsockopen('127.0.0.1', 9515);
if (is_resource($connection)) {
fclose($connection);
return;
}
usleep(100_000);
} while (microtime(true) < $deadline);
}
}