diff --git a/packages/playwright-test/src/plugins/webServerPlugin.ts b/packages/playwright-test/src/plugins/webServerPlugin.ts index a7372d2573..9e708074c5 100644 --- a/packages/playwright-test/src/plugins/webServerPlugin.ts +++ b/packages/playwright-test/src/plugins/webServerPlugin.ts @@ -153,7 +153,7 @@ async function isURLAvailable(url: URL, ignoreHTTPSErrors: boolean, onStdErr: Re indexUrl.pathname = '/index.html'; statusCode = await httpStatusCode(indexUrl, ignoreHTTPSErrors, onStdErr); } - return statusCode >= 200 && statusCode < 300; + return statusCode >= 200 && statusCode < 404; } async function httpStatusCode(url: URL, ignoreHTTPSErrors: boolean, onStdErr: Reporter['onStdErr']): Promise { diff --git a/tests/playwright-test/assets/simple-server.js b/tests/playwright-test/assets/simple-server.js index bea8268a74..b1d7b217af 100644 --- a/tests/playwright-test/assets/simple-server.js +++ b/tests/playwright-test/assets/simple-server.js @@ -13,5 +13,9 @@ setTimeout(() => { server.setRoute('/port', (_, response) => { response.end('' + server.PORT); }); + server.setRoute('/redirect', (_, response) => { + response.writeHead(301, 'Moved'); + response.end(); + }); }); }, process.argv[3] ? +process.argv[3] : 0); diff --git a/tests/playwright-test/web-server.spec.ts b/tests/playwright-test/web-server.spec.ts index 96f2f97beb..4a3c46d43b 100644 --- a/tests/playwright-test/web-server.spec.ts +++ b/tests/playwright-test/web-server.spec.ts @@ -546,3 +546,26 @@ test.describe('baseURL with plugins', () => { expect(result.passed).toBe(1); }); }); + +test('should treat 3XX as available server', async ({ runInlineTest }, { workerIndex }) => { + const port = workerIndex + 10500; + const result = await runInlineTest({ + 'test.spec.ts': ` + const { test } = pwt; + test('pass', async ({}) => {}); + `, + 'playwright.config.ts': ` + module.exports = { + webServer: { + command: 'node ${JSON.stringify(SIMPLE_SERVER_PATH)} ${port}', + url: 'http://localhost:${port}/redirect', + } + }; + `, + }, {}, { DEBUG: 'pw:webserver' }); + expect(result.exitCode).toBe(0); + expect(result.passed).toBe(1); + expect(result.output).toContain('[WebServer] listening'); + expect(result.output).toContain('[WebServer] error from server'); +}); +