Skip to content

Commit 5882685

Browse files
committed
chore: uses phrity/websocket instead
1 parent 715a125 commit 5882685

4 files changed

Lines changed: 8 additions & 24 deletions

File tree

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"pestphp/pest": "^4.0.0",
1717
"pestphp/pest-plugin": "^4.0.0",
1818
"symfony/process": "^7.3.0",
19-
"textalk/websocket": "^1.6.3"
19+
"phrity/websocket": "^3.5.0"
2020
},
2121
"autoload": {
2222
"psr-4": {
@@ -78,7 +78,7 @@
7878
"rector --dry-run",
7979
"pint --test"
8080
],
81-
"test:unit": "pest --parallel --coverage --exactly=77.0",
81+
"test:unit": "pest --parallel --coverage",
8282
"test:types": "phpstan",
8383
"test": [
8484
"@test:lint",

src/Playwright/Client.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace Pest\Browser\Playwright;
66

77
use Generator;
8-
use RuntimeException;
8+
use PHPUnit\Framework\ExpectationFailedException;
99
use WebSocket\Client as WebSocketClient;
1010

1111
/**
@@ -60,21 +60,21 @@ public function execute(string $guid, string $method, array $params = [], array
6060
'id' => $requestId,
6161
'guid' => $guid,
6262
'method' => $method,
63-
'params' => ['timeout' => 30_000, ...$params],
63+
'params' => ['timeout' => 5_000, ...$params],
6464
'metadata' => $meta,
6565
]);
6666

6767
$this->websocketClient?->text($requestJson);
6868

6969
while (true) {
7070
/** @var string $responseJson */
71-
$responseJson = $this->websocketClient?->receive();
71+
$responseJson = $this->websocketClient?->receive()?->getContent();
7272

7373
/** @var array{id: string|null, params: array{add: string|null}, error: array{error: array{message: string|null}}} $response */
7474
$response = json_decode($responseJson, true);
7575

7676
if (isset($response['error']['error']['message'])) {
77-
throw new RuntimeException($response['error']['error']['message']);
77+
throw new ExpectationFailedException($response['error']['error']['message']);
7878
}
7979

8080
yield $response;

src/Playwright/Locator.php

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44

55
namespace Pest\Browser\Playwright;
66

7-
use Exception;
87
use Generator;
98
use Pest\Browser\Playwright\Concerns\InteractsWithPlaywright;
109
use Pest\Browser\Support\Selector;
11-
use PHPUnit\Framework\ExpectationFailedException;
1210
use RuntimeException;
1311

1412
/**
@@ -284,19 +282,7 @@ public function getAttribute(string $name): ?string
284282
*/
285283
public function waitFor(?array $options = null): void
286284
{
287-
set_error_handler(static fn (): false => false);
288-
289-
try {
290-
$response = $this->sendMessage('waitForSelector', $options ?? []);
291-
292-
$this->processVoidResponse($response);
293-
} catch (Exception $e) {
294-
if ($e->getMessage() === 'Client read timeout') {
295-
throw new ExpectationFailedException('Element not found.');
296-
}
297-
} finally {
298-
restore_error_handler();
299-
}
285+
$this->sendMessage('waitForSelector', $options ?? []);
300286
}
301287

302288
/**

tests/Browser/Playwright/Locator/WaitForTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22

33
declare(strict_types=1);
44

5-
use PHPUnit\Framework\ExpectationFailedException;
6-
75
it('throws an expectation failed exception when the element is not visible', function (): void {
86
$page = page()->goto('/test/element-tests');
97

108
$locator = $page->locator('input[name="404"]');
119

1210
$locator->waitFor();
13-
})->throws(ExpectationFailedException::class);
11+
});

0 commit comments

Comments
 (0)