Skip to content

Commit 15b0075

Browse files
author
LDA
committed
Add hyperlinks
Turns file paths seen in `Saved Source Files` into links that open those files right inside your browser Enable the `Zenstruck\Browser\Test\BrowserExtension` extension Configure the file link format with the environment variable `BROWSER_FILE_LINK_FORMAT`, the default value is `file://%f#L%l` Can be overloaded in the `phpunit.xml.dist` for example ``` <server name="BROWSER_FILE_LINK_FORMAT" value="'file://%f#L%l"/> ``` iUseful when running your app in a container or in a virtual machine, see Symfony doc https://symfony.com/doc/current/reference/configuration/framework.html#ide
1 parent 28b7e1a commit 15b0075

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,7 @@ There are several environment variables available to configure:
563563
| `PANTHER_BROWSER_CLASS` | `PantherBrowser` class to use. | `Zenstruck\Browser\PantherBrowser` |
564564
| `PANTHER_NO_HEADLESS` | Disable headless-mode and allow usage of `PantherBrowser::pause()`. | `0` _(false)_ |
565565
| `BROWSER_ALWAYS_START_WEBSERVER` | Always start a webserver configured for your current test env before running tests (only applies to `PantherBrowser`). | `0` _(false)_ |
566+
| `BROWSER_FILE_LINK_FORMAT` | Turns file paths seen in `Saved Source Files` into links that open those files right inside your browser | `file://%f#L%l` |
566567

567568
## Extending
568569

src/Browser/Test/LegacyExtension.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Zenstruck\Browser\Test;
1313

14+
use Symfony\Component\ErrorHandler\ErrorRenderer\FileLinkFormatter;
1415
use Zenstruck\Browser;
1516

1617
/**
@@ -24,6 +25,12 @@ class LegacyExtension
2425

2526
/** @var array<string,array<string,string[]>> */
2627
private array $savedArtifacts = [];
28+
private FileLinkFormatter $fileLinkFormatter;
29+
30+
public function __construct(FileLinkFormatter|null $fileLinkFormatter = null)
31+
{
32+
$this->fileLinkFormatter = $fileLinkFormatter ?? new FileLinkFormatter($_ENV['BROWSER_FILE_LINK_FORMAT'] ?? $_SERVER['BROWSER_FILE_LINK_FORMAT'] ?? '');
33+
}
2734

2835
/**
2936
* @internal
@@ -77,7 +84,7 @@ public function executeAfterLastTest(): void
7784
echo "\n {$category}:";
7885

7986
foreach ($artifacts as $artifact) {
80-
echo "\n * {$artifact}:";
87+
echo "\n * \033]8;;{$this->fileLinkFormatter->format(realpath($artifact), 1)}\033\\$artifact\033]8;;\033\\";
8188
}
8289
}
8390
}

0 commit comments

Comments
 (0)