Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hyperlinks #165

Open
wants to merge 1 commit into
base: 1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
15 changes: 14 additions & 1 deletion src/Browser/Test/LegacyExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,15 @@

namespace Zenstruck\Browser\Test;

use Symfony\Component\ErrorHandler\ErrorRenderer\FileLinkFormatter;
use Symfony\Component\HttpKernel\Debug\FileLinkFormatter as LegacyFileLinkFormatter;
use Zenstruck\Browser;

if (!class_exists(FileLinkFormatter::class) && class_exists(LegacyFileLinkFormatter::class)) {
class_alias(LegacyFileLinkFormatter::class, FileLinkFormatter::class);
}


/**
* @author Kevin Bond <[email protected]>
*/
Expand All @@ -24,6 +31,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 +90,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\\";
}
}
}
Expand Down
Loading