Skip to content

Commit 95b0449

Browse files
committed
Review fixes
1 parent a99b682 commit 95b0449

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

packages/next/src/experimental/testmode/playwright/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { defineConfig } from 'next/experimental/testmode/playwright'
2525

2626
export 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
})

packages/next/src/experimental/testmode/playwright/page-route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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
}

packages/next/src/experimental/testmode/server.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff 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+
110121
export function wrapRequestHandler(
111122
handler: NodeRequestHandler
112123
): NodeRequestHandler {

packages/next/src/server/next-server.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)