Skip to content

Commit

Permalink
Add hyperlinks
Browse files Browse the repository at this point in the history
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
  • Loading branch information
LDA committed Feb 13, 2025
1 parent 28b7e1a commit 15b0075
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ There are several environment variables available to configure:
| `PANTHER_BROWSER_CLASS` | `PantherBrowser` class to use. | `Zenstruck\Browser\PantherBrowser` |
| `PANTHER_NO_HEADLESS` | Disable headless-mode and allow usage of `PantherBrowser::pause()`. | `0` _(false)_ |
| `BROWSER_ALWAYS_START_WEBSERVER` | Always start a webserver configured for your current test env before running tests (only applies to `PantherBrowser`). | `0` _(false)_ |
| `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` |

## Extending

Expand Down
9 changes: 8 additions & 1 deletion src/Browser/Test/LegacyExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Zenstruck\Browser\Test;

use Symfony\Component\ErrorHandler\ErrorRenderer\FileLinkFormatter;
use Zenstruck\Browser;

/**
Expand All @@ -24,6 +25,12 @@ class LegacyExtension

/** @var array<string,array<string,string[]>> */
private array $savedArtifacts = [];
private FileLinkFormatter $fileLinkFormatter;

public function __construct(FileLinkFormatter|null $fileLinkFormatter = null)
{
$this->fileLinkFormatter = $fileLinkFormatter ?? new FileLinkFormatter($_ENV['BROWSER_FILE_LINK_FORMAT'] ?? $_SERVER['BROWSER_FILE_LINK_FORMAT'] ?? '');
}

/**
* @internal
Expand Down Expand Up @@ -77,7 +84,7 @@ public function executeAfterLastTest(): void
echo "\n {$category}:";

foreach ($artifacts as $artifact) {
echo "\n * {$artifact}:";
echo "\n * \033]8;;{$this->fileLinkFormatter->format(realpath($artifact), 1)}\033\\$artifact\033]8;;\033\\";

Check failure on line 87 in src/Browser/Test/LegacyExtension.php

View workflow job for this annotation

GitHub Actions / sca / Static Code Analysis

Parameter #1 $file of method Symfony\Component\ErrorHandler\ErrorRenderer\FileLinkFormatter::format() expects string, string|false given.
}
}
}
Expand Down

0 comments on commit 15b0075

Please sign in to comment.