Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
Revert "feat(test runner): use happy eyeballs in webServer port check" (#40594)
Simon Knott22a112f0f805
diff --git a/packages/playwright/src/plugins/webServerPlugin.ts b/packages/playwright/src/plugins/webServerPlugin.tsindex 2b8b9ca628..7c83dadad8 100644--- a/packages/playwright/src/plugins/webServerPlugin.ts+++ b/packages/playwright/src/plugins/webServerPlugin.ts@@ -13,6 +13,7 @@* See the License for the specific language governing permissions and* limitations under the License.*/+import net from 'net';import path from 'path';import colors from 'colors/safe';@@ -20,7 +21,6 @@ import debug from 'debug';import { ManualPromise } from '@isomorphic/manualPromise';import { monotonicTime } from '@isomorphic/time';import { raceAgainstDeadline } from '@isomorphic/timeoutRunner';-import { createSocket } from '@utils/happyEyeballs';import { isURLAvailable } from '@utils/network';import { launchProcess } from '@utils/processLauncher';@@ -210,13 +210,18 @@ export class WebServerPlugin implements TestRunnerPlugin {}async function isPortUsed(port: number): Promise<boolean> {- try {- const socket = await createSocket('localhost', port);- socket.end();- return true;- } catch {- return false;- }+ const innerIsPortUsed = (host: string) => new Promise<boolean>(resolve => {+ const conn = net+ .connect(port, host)+ .on('error', () => {+ resolve(false);+ })+ .on('connect', () => {+ conn.end();+ resolve(true);+ });+ });+ return await innerIsPortUsed('127.0.0.1') || await innerIsPortUsed('::1');}async function waitFor(waitFn: () => Promise<boolean>, cancellationToken: { canceled: boolean }) {diff --git a/packages/utils/index.ts b/packages/utils/index.tsindex 1e319ecd9a..00fd5ca902 100644--- a/packages/utils/index.ts+++ b/packages/utils/index.ts@@ -23,7 +23,6 @@ export * from './debugLogger';export * from './env';export * from './eventsHelper';export * from './fileUtils';-export * from './happyEyeballs';export * from './hostPlatform';export * from './httpServer';export * from './network';diff --git a/tests/playwright-test/web-server.spec.ts b/tests/playwright-test/web-server.spec.tsindex 992bfca875..c171637bad 100644--- a/tests/playwright-test/web-server.spec.ts+++ b/tests/playwright-test/web-server.spec.ts@@ -15,7 +15,6 @@*/import type http from 'http';-import type { AddressInfo } from 'net';import path from 'path';import { test, expect, parseTestRunnerOutput } from './playwright-test-fixtures';import type { RunResult } from './playwright-test-fixtures';@@ -313,12 +312,12 @@ test('should time out waiting for a server with url', async ({ runInlineTest },expect(result.output).toContain(`Timed out waiting 300ms from config.webServer.`);});-test('should be able to specify the baseURL without the server', async ({ runInlineTest }) => {+test('should be able to specify the baseURL without the server', async ({ runInlineTest }, { workerIndex }) => {+ const port = workerIndex * 2 + 10500;const server = createHttpServer((req: http.IncomingMessage, res: http.ServerResponse) => {res.end('<html><body>hello</body></html>');});- await new Promise<void>(resolve => server.listen(0, resolve));- const port = (server.address() as AddressInfo).port;+ await new Promise<void>(resolve => server.listen(port, resolve));const result = await runInlineTest({'test.spec.ts': `import { test, expect } from '@playwright/test';@@ -376,12 +375,12 @@ test('should be able to specify a custom baseURL with the server', async ({ runIawait new Promise(resolve => server.close(resolve));});-test('should be able to use an existing server when reuseExistingServer:true', async ({ runInlineTest }) => {+test('should be able to use an existing server when reuseExistingServer:true', async ({ runInlineTest }, { workerIndex }) => {+ const port = workerIndex * 2 + 10500;const server = createHttpServer((req: http.IncomingMessage, res: http.ServerResponse) => {res.end('<html><body>hello</body></html>');});- await new Promise<void>(resolve => server.listen(0, resolve));- const port = (server.address() as AddressInfo).port;+ await new Promise<void>(resolve => server.listen(port, resolve));const result = await runInlineTest({'test.spec.ts': `import { test, expect } from '@playwright/test';@@ -409,12 +408,12 @@ test('should be able to use an existing server when reuseExistingServer:true', aawait new Promise(resolve => server.close(resolve));});-test('should throw when a server is already running on the given port and strict is true', async ({ runInlineTest }) => {+test('should throw when a server is already running on the given port and strict is true', async ({ runInlineTest }, { workerIndex }) => {+ const port = workerIndex * 2 + 10500;const server = createHttpServer((req: http.IncomingMessage, res: http.ServerResponse) => {res.end('<html><body>hello</body></html>');});- await new Promise<void>(resolve => server.listen(0, resolve));- const port = (server.address() as AddressInfo).port;+ await new Promise<void>(resolve => server.listen(port, resolve));const result = await runInlineTest({'test.spec.ts': `import { test, expect } from '@playwright/test';@@ -440,13 +439,13 @@ test('should throw when a server is already running on the given port and strictawait new Promise(resolve => server.close(resolve));});-for (const host of ['localhost', '127.0.0.1', '0.0.0.0', '::1']) {- test(`should detect the server if a web-server is already running on ${host}`, async ({ runInlineTest }) => {+for (const host of ['localhost', '127.0.0.1', '0.0.0.0']) {+ test(`should detect the server if a web-server is already running on ${host}`, async ({ runInlineTest }, { workerIndex }) => {+ const port = workerIndex * 2 + 10500;const server = createHttpServer((req: http.IncomingMessage, res: http.ServerResponse) => {res.end('<html><body>hello</body></html>');});- await new Promise<void>(resolve => server.listen(0, host, resolve));- const port = (server.address() as AddressInfo).port;+ await new Promise<void>(resolve => server.listen(port, host, resolve));try {const result = await runInlineTest({'test.spec.ts': `