Skip to content

Commit e9d8c31

Browse files
committed
wip
1 parent 784c8b9 commit e9d8c31

File tree

1 file changed

+36
-13
lines changed

1 file changed

+36
-13
lines changed

pest-v4-is-here-now-with-browser-testing.md

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Pest v4 Is Here — Now with Browser Testing
3-
description: Today, were thrilled to announce Pest v4 — our biggest release yet, featuring powerful new browser testing with parallel support and full Laravel integration.
3+
description: Today, we're thrilled to announce Pest v4 — our biggest release yet, featuring powerful new browser testing with parallel support and full Laravel integration.
44
---
55

66
> To get started with Pest v4's new features including browser testing, please refer to the upgrade guide: [Upgrade Guide →](/docs/upgrade-guide).
@@ -15,9 +15,13 @@ description: Today, we’re thrilled to announce Pest v4 — our biggest release
1515

1616
# Pest v4 Is Here — Now with Browser Testing
1717

18-
Today, were thrilled to announce the release of **Pest v4**, bringing the biggest testing upgrade yet: powerful **[Browser Testing](/docs/browser-testing)**. Pests new browser testing features let you run elegant, maintainable browser tests — with first-class support for Laravel's testing API and the ability to run tests in parallel. For the first time, this is browser testing that feels as good as writing unit tests.
18+
Today, we're thrilled to announce the release of **Pest v4**, bringing the biggest testing upgrade yet: powerful **[Browser Testing](/docs/browser-testing)**. Pest's new browser testing features let you run elegant, maintainable browser tests — with first-class support for Laravel's testing API and the ability to run tests in parallel. For the first time, this is browser testing that feels as good as writing unit tests.
1919

20-
Here is an example using [Laravel](https://laravel.com):
20+
Here is the creator of Pest, [Nuno Maduro](https://twitter.com/enunomaduro), demoing the new browser testing features in Pest v4 at Laracon US:
21+
22+
[![Pest v4](/assets/pest4_play.png)](https://youtu.be/f5gAgwwwwOI?si=LtPpySZe3tf8qMjz&t=52)
23+
24+
Here is an example of Browser Testing using [Laravel](https://laravel.com):
2125

2226
```php
2327
it('may reset the password', function () {
@@ -32,17 +36,17 @@ it('may reset the password', function () {
3236
->inDarkMode(); // or ->inLightMode()
3337

3438
$page->assertSee('Sign In')
35-
->assertNoJavascriptErrors() // or ->assertNoConsoleLogs()
3639
->click('Forgot Password?')
37-
->fill('email', 'nuno@laravel.com')
38-
->click('Send Reset Link')
40+
->type('email', 'nuno@laravel.com')
41+
->press('Send Reset Link')
3942
->assertSee('We have emailed your password reset link!')
43+
->assertNoJavascriptErrors(); // or ->assertNoConsoleLogs()
4044

4145
Notification::assertSent(ResetPassword::class);
4246
});
4347
```
4448

45-
With Pest v4s browser testing, you can:
49+
With Pest v4's browser testing, you can:
4650
- Seamlessly use **Laravel features** like `Event::fake()`, `assertAuthenticated()`, and model factories
4751
- Use `RefreshDatabase`, even with SQLite in-memory databases, to ensure a clean state for each test
4852
- Test on **multiple browsers** (Chrome, Firefox, Safari)
@@ -59,6 +63,7 @@ To get started with browser testing in Pest, you need to install the Pest Browse
5963
```bash
6064
composer require pestphp/pest-plugin-browser --dev
6165

66+
npm install playwright@latest
6267
npx playwright install
6368
```
6469

@@ -69,24 +74,26 @@ After, you may use the `visit()` function anywhere. Finally, running this test i
6974
Smoke testing your application in real browsers has never been easier. With Pest v4, you can literally visit all your application pages, and ensure they don't throw any JavaScript errors, and they don't log any console errors.
7075

7176
```php
72-
$pages = visit(['/', '/about', '/contact']);
77+
$routes = ['/', '/about', '/contact'];
7378

74-
$pages->assertNoJavascriptErrors()
75-
->assertNoConsoleLogs();
79+
visit($routes)->assertNoSmoke();
80+
81+
// assertNoSmoke() is a shorthand for:
82+
// - assertNoJavascriptErrors()
83+
// - assertNoConsoleLogs()
7684
```
7785

7886
## Visual Regression Testing
7987

80-
Want to ensure your pages look exactly as expected? Pest v4 introduces visual regression testing with the `assertScreenshotsMatches()` assertion. This allows you to take screenshots of your pages and compare them against baseline images, ensuring that your UI remains consistent across changes.
88+
Want to ensure your pages look exactly as expected over time? Pest v4 introduces visual regression testing with the `assertScreenshotsMatches()` assertion. This allows you to take screenshots of your pages and compare them against baseline images, ensuring that your UI remains consistent across changes.
8189

8290
```php
8391
$pages = visit(['/', '/about', '/contact']);
8492

8593
$pages->assertScreenshotsMatches();
8694
```
8795

88-
[image here missing]
89-
96+
![Visual Regression Testing in Pest v4](/assets/pest4_play.png)
9097

9198
This is just a glimpse of what Browser Testing in Pest v4 can do. Find out more about the new features below, and check out the [Browser Testing documentation](/docs/browser-testing) for a complete guide on how to get started.
9299

@@ -171,9 +178,25 @@ As an example, `pr31(f*ck)` means that the word "fuck" was found on line 31.
171178

172179
To learn more about the Profanity plugin and how to configure it, check out the [Profanity documentation](/docs/profanity).
173180

181+
### Skip Locally or On CI
182+
183+
Pest v4 introduces the ability to conditionally skip tests based on the environment. You can use `skipLocally()` to skip tests when running locally, or `skipOnCi` to skip tests when running on a CI server.
184+
185+
```php
186+
it('does not run locally', function () {
187+
// This test will be skipped when running locally
188+
})->skipLocally();
189+
190+
it('does not run on CI', function () {
191+
// This test will be skipped when running on a CI server
192+
})->skipOnCi();
193+
```
194+
174195
### Miscellaneous Improvements
175196

176197
- You may now use `skipLocally()` or `skipOnCi` to conditionally skip tests based on the environment.
198+
- The `not->toHaveSuspiciousCharacters()` arch expectation has been added to help you identify potential suspicious characters in your code. This arch expectation is now enabled by default on the `php` arch preset.
199+
- The expectation `toBeSlug` has been added to help you validate that a string is a valid slug.
177200

178201
### On Top of PHPUnit 12
179202

0 commit comments

Comments
 (0)