Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

test: add a test for fetch api respecting port forwarding (#12007)

Dmitry Gozman9a8e55493fcf
diff --git a/tests/port-forwarding-server.spec.ts b/tests/port-forwarding-server.spec.ts
index 9f16c6eace..698376b86a 100644
--- a/tests/port-forwarding-server.spec.ts
+++ b/tests/port-forwarding-server.spec.ts
@@ -121,6 +121,24 @@ it('should proxy localhost requests #smoke', async ({ pageFactory, server, brows
stopTestServer();
});
+it('should proxy localhost requests from fetch api', async ({ pageFactory, server, browserName, platform }, workerInfo) => {
+ it.skip(browserName === 'webkit' && platform === 'darwin');
+
+ const { testServerPort, stopTestServer } = await startTestServer();
+ let reachedOriginalTarget = false;
+ server.setRoute('/foo.html', async (req, res) => {
+ reachedOriginalTarget = true;
+ res.end('<html><body></body></html>');
+ });
+ const examplePort = 20_000 + workerInfo.workerIndex * 3;
+ const page = await pageFactory(testServerPort);
+ const response = await page.request.get(`http://localhost:${examplePort}/foo.html`);
+ expect(response.status()).toBe(200);
+ expect(await response.text()).toContain('from-retargeted-server');
+ expect(reachedOriginalTarget).toBe(false);
+ stopTestServer();
+});
+
it('should proxy local.playwright requests', async ({ pageFactory, server, browserName }, workerInfo) => {
const { testServerPort, stopTestServer } = await startTestServer();
let reachedOriginalTarget = false;