From 821be98ee51305aec9eca388ce350c68689ecc4f Mon Sep 17 00:00:00 2001 From: Clem Blanco Date: Sat, 15 Feb 2025 00:50:57 +0100 Subject: [PATCH 1/2] WIP --- src/{Operations => Assertions}/AssertUrlIs.php | 2 +- src/Compiler.php | 2 +- src/PendingTest.php | 3 ++- tests/Browser/Assertions/AssertUrlIsTest.php | 15 +++++++++++++++ 4 files changed, 19 insertions(+), 3 deletions(-) rename src/{Operations => Assertions}/AssertUrlIs.php (92%) create mode 100644 tests/Browser/Assertions/AssertUrlIsTest.php diff --git a/src/Operations/AssertUrlIs.php b/src/Assertions/AssertUrlIs.php similarity index 92% rename from src/Operations/AssertUrlIs.php rename to src/Assertions/AssertUrlIs.php index cbc49d0..efd7102 100644 --- a/src/Operations/AssertUrlIs.php +++ b/src/Assertions/AssertUrlIs.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Pest\Browser\Operations; +namespace Pest\Browser\Assertions; use Pest\Browser\Contracts\Operation; diff --git a/src/Compiler.php b/src/Compiler.php index a453807..87b627e 100644 --- a/src/Compiler.php +++ b/src/Compiler.php @@ -14,7 +14,7 @@ /** * The path to the tests. */ - private const TEST_PATH = __DIR__.'/../.temp/e2e/runtime.spec.js'; + public const TEST_PATH = __DIR__.'/../.temp/e2e/runtime.spec.js'; /** * @param array $operations diff --git a/src/PendingTest.php b/src/PendingTest.php index 091d16c..ae54c0c 100644 --- a/src/PendingTest.php +++ b/src/PendingTest.php @@ -4,6 +4,7 @@ namespace Pest\Browser; +use Pest\Browser\Contracts\Assertions; use Pest\Browser\Contracts\Operation; use Pest\Browser\ValueObjects\TestResult; @@ -84,7 +85,7 @@ public function clickLink(string $text): self */ public function assertUrlIs(string $url): self { - $this->operations[] = new Operations\AssertUrlIs($url); + $this->operations[] = new Assertions\AssertUrlIs($url); return $this; } diff --git a/tests/Browser/Assertions/AssertUrlIsTest.php b/tests/Browser/Assertions/AssertUrlIsTest.php new file mode 100644 index 0000000..0c86d65 --- /dev/null +++ b/tests/Browser/Assertions/AssertUrlIsTest.php @@ -0,0 +1,15 @@ +assertUrlIs('https://laravel.com'); + + expect(file_get_contents(Compiler::TEST_PATH)) + ->toContain("await expect(page.url()).toBe('https://laravel.com');"); +}); From 114490dbdccd5a6181c1800ce4eb797226553d2f Mon Sep 17 00:00:00 2001 From: Clem Blanco Date: Sat, 15 Feb 2025 01:16:36 +0100 Subject: [PATCH 2/2] WIP --- src/Assertions/AssertUrlIs.php | 4 +++- src/PendingTest.php | 1 - tests/Browser/Assertions/AssertUrlIsTest.php | 10 +++++++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Assertions/AssertUrlIs.php b/src/Assertions/AssertUrlIs.php index efd7102..98fae8f 100644 --- a/src/Assertions/AssertUrlIs.php +++ b/src/Assertions/AssertUrlIs.php @@ -22,6 +22,8 @@ public function __construct( public function compile(): string { - return sprintf("await expect(page.url()).toBe('%s');", $this->url); + $pattern = str_replace('\*', '.*', preg_quote($this->url, '/')); + + return sprintf('await expect(page.url()).toMatch(/%s/i);', $pattern); } } diff --git a/src/PendingTest.php b/src/PendingTest.php index ae54c0c..e46ab7d 100644 --- a/src/PendingTest.php +++ b/src/PendingTest.php @@ -4,7 +4,6 @@ namespace Pest\Browser; -use Pest\Browser\Contracts\Assertions; use Pest\Browser\Contracts\Operation; use Pest\Browser\ValueObjects\TestResult; diff --git a/tests/Browser/Assertions/AssertUrlIsTest.php b/tests/Browser/Assertions/AssertUrlIsTest.php index 0c86d65..19caa00 100644 --- a/tests/Browser/Assertions/AssertUrlIsTest.php +++ b/tests/Browser/Assertions/AssertUrlIsTest.php @@ -11,5 +11,13 @@ ->assertUrlIs('https://laravel.com'); expect(file_get_contents(Compiler::TEST_PATH)) - ->toContain("await expect(page.url()).toBe('https://laravel.com');"); + ->toContain('await expect(page.url()).toMatch(/https\:\/\/laravel\.com/i);'); +}); + +it('can use the asterisk wildcard', function (): void { + visit('https://laravel.com/docs/11.x') + ->assertUrlIs('https://laravel.com/*/11.x'); + + expect(file_get_contents(Compiler::TEST_PATH)) + ->toContain('await expect(page.url()).toMatch(/https\:\/\/laravel\.com\/.*\/11\.x/i);'); });