Skip to content

Commit d3cdc39

Browse files
committed
refactor: test result
1 parent 92d8fcb commit d3cdc39

File tree

7 files changed

+8
-111
lines changed

7 files changed

+8
-111
lines changed

src/Compiler.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
/**
1010
* @internal
1111
*/
12-
final class Compiler
12+
final readonly class Compiler
1313
{
1414
/**
1515
* The path to the tests.
@@ -20,7 +20,7 @@ final class Compiler
2020
* @param array<int, Operation> $operations
2121
*/
2222
public function __construct(
23-
private readonly array $operations
23+
private array $operations
2424
) {
2525
//
2626
}
@@ -43,16 +43,6 @@ public function compile(): void
4343
4444
test('runtime', async ({ page }) => {
4545
$content
46-
47-
const response = await page.reload();
48-
test.info().annotations.push({
49-
type: '_response',
50-
description: JSON.stringify({
51-
headers: response.headers(),
52-
status: response.status(),
53-
url: response.url(),
54-
})
55-
});
5646
});
5747
JS,
5848
);

src/PendingTest.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44

55
namespace Pest\Browser;
66

7-
use Pest\Browser\ValueObjects\TestResult;
8-
use Pest\Browser\ValueObjects\TestResultResponse;
97
use Pest\Browser\Contracts\Operation;
8+
use Pest\Browser\ValueObjects\TestResult;
109

1110
/**
1211
* @internal
@@ -68,18 +67,10 @@ public function assertUrlIs(string $url): self
6867
return $this;
6968
}
7069

71-
/**
72-
* Build and return the final response the test received.
73-
*/
74-
public function response(): TestResultResponse
75-
{
76-
return $this->build()->response();
77-
}
78-
7970
/**
8071
* Compile the JavaScript test file.
8172
*/
82-
public function build(): void
73+
public function compile(): TestResult
8374
{
8475
$compiler = new Compiler($this->operations);
8576

src/Support/Str.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,10 @@ public static function isRegex(string $target): bool
1818
return false;
1919
}
2020

21-
// If the first and last characters are not the same, it's not a regex
2221
if (($delimiter = mb_substr($target, 0, 1)) !== mb_substr($target, -1, 1)) {
2322
return false;
2423
}
2524

26-
// If the delimiter is alphanumeric, it's not a regex
27-
if (! preg_match('/[^a-zA-Z0-9]/', $delimiter)) {
28-
return false;
29-
}
30-
31-
return true;
25+
return preg_match('/[^a-zA-Z0-9]/', $delimiter) !== false;
3226
}
3327
}

src/ValueObjects/TestResult.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
*/
1515
public function __construct(
1616
private bool $ok,
17-
private TestResultResponse $response,
1817
) {
1918
//
2019
}
@@ -26,12 +25,4 @@ public function ok(): bool
2625
{
2726
return $this->ok;
2827
}
29-
30-
/**
31-
* Get the final response from the test result.
32-
*/
33-
public function response(): TestResultResponse
34-
{
35-
return $this->response;
36-
}
3728
}

src/ValueObjects/TestResultResponse.php

Lines changed: 0 additions & 60 deletions
This file was deleted.

src/Worker.php

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

77
use Pest\Browser\ValueObjects\TestResult;
8-
use Pest\Browser\ValueObjects\TestResultResponse;
98
use Pest\Support\Arr;
109
use Symfony\Component\Process\Process;
1110

@@ -25,12 +24,11 @@ public function run(): TestResult
2524

2625
$output = $process->getOutput();
2726

28-
// @phpstan-ignore-next-line
27+
/** @var array<int, mixed> $outputAsArray */
2928
$outputAsArray = json_decode($output, true);
3029

31-
$ok = Arr::get($outputAsArray, 'suites.0.specs.0.ok');
32-
$annotations = Arr::get($outputAsArray, 'suites.0.specs.0.tests.0.annotations');
30+
$ok = (bool) Arr::get($outputAsArray, 'suites.0.specs.0.ok');
3331

34-
return new TestResult($ok, new TestResultResponse($annotations));
32+
return new TestResult($ok);
3533
}
3634
}

tests/Example.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,4 @@
2222
visit('https://laravel.com')
2323
->clickLink('Get Started')
2424
->assertUrlIs('https://laravel.com/docs/11.x');
25-
26-
// -- or --
27-
28-
$browser = visit('https://laravel.com')
29-
->clickLink('Get Started');
30-
31-
expect($browser->response()->url())->toBe('https://laravel.com/docs/11.x');
3225
});

0 commit comments

Comments
 (0)