Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/extension/src/ui/connect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ const ConnectApp: React.FC = () => {
};

const VersionMismatchError: React.FC<{ extensionVersion: string }> = ({ extensionVersion }) => {
const readmeUrl = 'https://github.com/microsoft/playwright-mcp/blob/main/packages/extension/README.md';
const chromeWebStoreUrl = 'https://chromewebstore.google.com/detail/playwright-mcp-bridge/mmlmfjhmonkocbjadbfplnigmagldckm';
const readmeUrl = 'https://github.com/microsoft/playwright/blob/main/packages/extension/README.md';
const chromeWebStoreUrl = 'https://chromewebstore.google.com/detail/playwright-extension/mmlmfjhmonkocbjadbfplnigmagldckm';
return (
<div>
Playwright client trying to connect requires newer extension version (current version: {extensionVersion}).{' '}
Expand Down
21 changes: 13 additions & 8 deletions packages/playwright/src/plugins/webServerPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
* 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';
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';

Expand Down Expand Up @@ -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 }) {
Expand Down
1 change: 0 additions & 1 deletion packages/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
27 changes: 13 additions & 14 deletions tests/playwright-test/web-server.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -376,12 +375,12 @@ test('should be able to specify a custom baseURL with the server', async ({ runI
await 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';
Expand Down Expand Up @@ -409,12 +408,12 @@ test('should be able to use an existing server when reuseExistingServer:true', a
await 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';
Expand All @@ -440,13 +439,13 @@ test('should throw when a server is already running on the given port and strict
await 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': `
Expand Down
Loading