* fix: stabilize and diagnose browser CI gate - Replace networkidle screenshot wait (5s client timeout, flaky with long-lived connections) with readyState + fonts-loaded wait and fixed settle in a StableScreenshot helper. - Export standalone diff/expected/actual PNGs on visual mismatch so CI artifacts are directly viewable (vendor only writes an HTML diff view). - Create .env in CI test jobs; without it Laravel's env bootstrap emits a file_get_contents warning on every test. - Bump checkout/cache actions to v5 (Node 20 deprecation). - Gitignore tests/Browser/Screenshots. * docs: track browser CI gate task status in tasks.md
41 lines
1.2 KiB
PHP
41 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Support;
|
|
|
|
final class MismatchScreenshotExporter
|
|
{
|
|
/**
|
|
* Extracts the diff, expected, and actual images embedded in an ImageDiffView
|
|
* HTML file and writes them as standalone PNG files so they can be inspected
|
|
* directly in CI artifacts.
|
|
*
|
|
* @return list<string> paths of the written PNG files
|
|
*/
|
|
public static function export(string $htmlPath, string $targetDir): array
|
|
{
|
|
$html = (string) file_get_contents($htmlPath);
|
|
|
|
if (preg_match_all('/src="data:image\/png;base64,([^"]+)"/', $html, $matches) === false || ! isset($matches[1][2])) {
|
|
return [];
|
|
}
|
|
|
|
$base = pathinfo($htmlPath, PATHINFO_FILENAME);
|
|
$labels = ['diff', 'expected', 'actual'];
|
|
$written = [];
|
|
|
|
foreach (array_slice($matches[1], 0, 3) as $index => $base64) {
|
|
$path = $targetDir.'/'.$base.'-'.($labels[$index] ?? 'image-'.$index).'.png';
|
|
|
|
if (file_put_contents($path, (string) base64_decode($base64, true)) === false) {
|
|
continue;
|
|
}
|
|
|
|
$written[] = $path;
|
|
}
|
|
|
|
return $written;
|
|
}
|
|
}
|