File tree Expand file tree Collapse file tree 4 files changed +18
-7
lines changed Expand file tree Collapse file tree 4 files changed +18
-7
lines changed Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ import { defineConfig } from 'next/experimental/testmode/playwright'
2525
2626export default defineConfig ({
2727 webServer: {
28- command: ' pnpm dev -- --experimental-test-proxy' ,
28+ command: ' npm dev -- --experimental-test-proxy' ,
2929 url: ' http://localhost:3000' ,
3030 },
3131})
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ export async function handleRoute(
88) {
99 const request = route . request ( )
1010
11- // COntinue the navigation and non-fetch requests.
11+ // Continue the navigation and non-fetch requests.
1212 if ( request . isNavigationRequest ( ) || request . resourceType ( ) !== 'fetch' ) {
1313 return route . continue ( )
1414 }
Original file line number Diff line number Diff line change @@ -64,8 +64,9 @@ function buildResponse(proxyResponse: ProxyFetchResponse): Response {
6464 } )
6565}
6666
67- export function createTestFetch ( originalFetch : Fetch ) : Fetch {
68- return async function testFetch (
67+ function interceptFetch ( ) {
68+ const originalFetch = global . fetch
69+ global . fetch = async function testFetch (
6970 input : FetchInputArg ,
7071 init ?: FetchInitArg
7172 ) : Promise < Response > {
@@ -107,6 +108,16 @@ export function createTestFetch(originalFetch: Fetch): Fetch {
107108 }
108109}
109110
111+ export function interceptTestApis ( ) : ( ) => void {
112+ const originalFetch = global . fetch
113+ interceptFetch ( )
114+
115+ // Cleanup.
116+ return ( ) => {
117+ global . fetch = originalFetch
118+ }
119+ }
120+
110121export function wrapRequestHandler (
111122 handler : NodeRequestHandler
112123) : NodeRequestHandler {
Original file line number Diff line number Diff line change @@ -222,10 +222,10 @@ export default class NextNodeServer extends BaseServer {
222222 // ensure options are set when loadConfig isn't called
223223 setHttpClientAndAgentOptions ( this . nextConfig )
224224
225- // Intercept fetch
225+ // Intercept fetch and other testmode apis.
226226 if ( this . serverOptions . experimentalTestProxy ) {
227- const { createTestFetch } = require ( '../experimental/testmode/server' )
228- global . fetch = createTestFetch ( global . fetch )
227+ const { interceptTestApis } = require ( '../experimental/testmode/server' )
228+ interceptTestApis ( )
229229 }
230230 }
231231
You can’t perform that action at this time.
0 commit comments