@next/playwright 16.5.0-canary.53 → 16.5.0-canary.54
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
# @next/playwright
|
|
2
2
|
|
|
3
3
|
> - **Status:** Experimental. This API is not yet stable.
|
|
4
|
-
> - **Requires:** [Cache Components](https://nextjs.org/docs) to be enabled.
|
|
4
|
+
> - **Requires:** [Cache Components](https://nextjs.org/docs/app/api-reference/config/next-config-js/cacheComponents) to be enabled.
|
|
5
5
|
|
|
6
6
|
Playwright helpers for testing Next.js applications.
|
|
7
7
|
|
|
8
|
+
See the [Playwright guide](https://nextjs.org/docs/app/guides/testing/playwright#testing-instant-navigations)
|
|
9
|
+
for installation, parameters, initial page loads, and navigation caveats.
|
|
10
|
+
|
|
8
11
|
## Instant Navigation Testing
|
|
9
12
|
|
|
10
13
|
An **instant navigation** commits immediately without waiting for data fetching.
|
|
@@ -22,12 +25,15 @@ data is available. This way you're testing whether the route is _structured
|
|
|
22
25
|
correctly_ for instant navigation, independent of network timing. If content you
|
|
23
26
|
expected to be cached is missing inside the callback, it points to a problem — a
|
|
24
27
|
missing `use cache` directive, a misplaced Suspense boundary, or a similar gap.
|
|
28
|
+
For [same-page search-parameter updates](https://nextjs.org/docs/app/guides/testing/playwright#search-parameter-updates),
|
|
29
|
+
waiting for fresh data can be intentional.
|
|
25
30
|
|
|
26
31
|
### Examples
|
|
27
32
|
|
|
28
33
|
**Loading shell appears instantly** (dynamic content behind a Suspense boundary):
|
|
29
34
|
|
|
30
35
|
```ts
|
|
36
|
+
import { expect, test } from '@playwright/test'
|
|
31
37
|
import { instant } from '@next/playwright'
|
|
32
38
|
|
|
33
39
|
test('shows loading shell during navigation', async ({ page }) => {
|
|
@@ -35,6 +41,7 @@ test('shows loading shell during navigation', async ({ page }) => {
|
|
|
35
41
|
|
|
36
42
|
await instant(page, async () => {
|
|
37
43
|
await page.click('a[href="/dashboard"]')
|
|
44
|
+
await page.waitForURL((url) => url.pathname === '/dashboard')
|
|
38
45
|
|
|
39
46
|
// The loading shell is visible — dynamic data is deferred
|
|
40
47
|
await expect(page.locator('[data-testid="loading"]')).toBeVisible()
|
|
@@ -48,11 +55,15 @@ test('shows loading shell during navigation', async ({ page }) => {
|
|
|
48
55
|
**Fully instant navigation** (all content is cached):
|
|
49
56
|
|
|
50
57
|
```ts
|
|
58
|
+
import { expect, test } from '@playwright/test'
|
|
59
|
+
import { instant } from '@next/playwright'
|
|
60
|
+
|
|
51
61
|
test('navigates to profile instantly', async ({ page }) => {
|
|
52
62
|
await page.goto('/')
|
|
53
63
|
|
|
54
64
|
await instant(page, async () => {
|
|
55
65
|
await page.click('a[href="/profile"]')
|
|
66
|
+
await page.waitForURL((url) => url.pathname === '/profile')
|
|
56
67
|
|
|
57
68
|
// All content renders immediately
|
|
58
69
|
await expect(page.locator('[data-testid="profile-name"]')).toBeVisible()
|
|
@@ -64,11 +75,13 @@ test('navigates to profile instantly', async ({ page }) => {
|
|
|
64
75
|
### Enabling in production builds
|
|
65
76
|
|
|
66
77
|
In development (`next dev`), the testing API is available by default. In
|
|
67
|
-
production builds, it is disabled unless you explicitly opt in
|
|
78
|
+
production builds, it is disabled unless you explicitly opt in during both
|
|
79
|
+
`next build` and `next start`:
|
|
68
80
|
|
|
69
81
|
```js
|
|
70
82
|
// next.config.js
|
|
71
83
|
module.exports = {
|
|
84
|
+
cacheComponents: true,
|
|
72
85
|
experimental: {
|
|
73
86
|
exposeTestingApiInProductionBuild: true,
|
|
74
87
|
},
|
|
@@ -105,3 +118,6 @@ document.cookie = 'next-instant-navigation-testing=1; path=/'
|
|
|
105
118
|
// Clear the cookie to resume normal behavior
|
|
106
119
|
document.cookie = 'next-instant-navigation-testing=; path=/; max-age=0'
|
|
107
120
|
```
|
|
121
|
+
|
|
122
|
+
See the [helper implementation](https://github.com/vercel/next.js/blob/canary/packages/next-playwright/src/index.ts)
|
|
123
|
+
for browser-context cookie handling and cleanup when assertions fail.
|