Unverified Commit a69be6ca authored by Shu Uesugi's avatar Shu Uesugi Committed by GitHub

docs: Update README for experimental testmode (#75722)

- Fix the `npm` command
- Make it clear where to place test files
  - Was reported here: https://github.com/vercel/next.js/issues/71773
  - Relevant Next.js code:


https://github.com/vercel/next.js/blob/ae5026a0fa8cd67f434cf63cc1db7d7ee696c047/packages/next/src/experimental/testmode/playwright/default-config.ts#L13

- Make it clear that `next.onFetch` only works for external requests.
  - Relevant Next.js code:


https://github.com/vercel/next.js/blob/d2711d22fb719131d63cbce05a6306917f3626ea/packages/next/src/experimental/testmode/playwright/page-route.ts#L34-L40
parent 1dad3a67
...@@ -35,7 +35,7 @@ import { defineConfig } from 'next/experimental/testmode/playwright' ...@@ -35,7 +35,7 @@ import { defineConfig } from 'next/experimental/testmode/playwright'
export default defineConfig({ export default defineConfig({
webServer: { webServer: {
command: 'npm dev', command: 'npm run dev',
url: 'http://localhost:3000', url: 'http://localhost:3000',
}, },
}) })
...@@ -44,9 +44,16 @@ export default defineConfig({ ...@@ -44,9 +44,16 @@ export default defineConfig({
### Use the `next/experimental/testmode/playwright` to create tests ### Use the `next/experimental/testmode/playwright` to create tests
```javascript ```javascript
// Place this file in the `app` directory and name it with `.spec.ts`.
// To customize where to put tests, add `testMatch` to `playwright.config.ts`.
import { test, expect } from 'next/experimental/testmode/playwright' import { test, expect } from 'next/experimental/testmode/playwright'
test('/product/shoe', async ({ page, next }) => { test('/product/shoe', async ({ page, next }) => {
// NOTE: `next.onFetch` only intercepts external `fetch` requests (for both client and server).
// For example, if you `fetch` a relative URL (e.g. `/api/hello`) from the client
// that's handled by a Next.js route handler (e.g. `app/api/hello/route.ts`),
// it won't be intercepted.
next.onFetch((request) => { next.onFetch((request) => {
if (request.url === 'http://my-db/product/shoe') { if (request.url === 'http://my-db/product/shoe') {
return new Response( return new Response(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment