chore: move from esm to cjs before upstreaming (#986)

This commit is contained in:
Pavel Feldman
2025-09-03 08:00:58 -07:00
committed by GitHub
parent 8d86ce4958
commit 2461f32d05
92 changed files with 250 additions and 259 deletions

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { test, expect } from './fixtures.js';
import { test, expect } from './fixtures';
test('test snapshot tool list', async ({ client }) => {
const { tools } = await client.listTools();

View File

@@ -14,10 +14,9 @@
* limitations under the License.
*/
import url from 'node:url';
import path from 'node:path';
import { spawnSync } from 'node:child_process';
import { test, expect } from './fixtures.js';
import { test, expect } from './fixtures';
test('cdp server', async ({ cdpServer, startClient, server }) => {
await cdpServer.start();
@@ -84,9 +83,6 @@ test('should throw connection error and allow re-connecting', async ({ cdpServer
});
});
// NOTE: Can be removed when we drop Node.js 18 support and changed to import.meta.filename.
const __filename = url.fileURLToPath(import.meta.url);
test('does not support --device', async () => {
const result = spawnSync('node', [
path.join(__filename, '../../cli.js'), '--device=Pixel 5', '--cdp-endpoint=http://localhost:1234',

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { test, expect } from './fixtures.js';
import { test, expect } from './fixtures';
test('browser_click', async ({ client, server, mcpBrowser }) => {
server.setContent('/', `

View File

@@ -17,7 +17,7 @@
import fs from 'node:fs';
import { Config } from '../config.js';
import { test, expect } from './fixtures.js';
import { test, expect } from './fixtures';
test('config user data dir', async ({ startClient, server, mcpMode }, testInfo) => {
server.setContent('/', `

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { test, expect } from './fixtures.js';
import { test, expect } from './fixtures';
test('browser_console_messages', async ({ client, server }) => {
server.setContent('/', `

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { test, expect } from './fixtures.js';
import { test, expect } from './fixtures';
test('browser_navigate', async ({ client, server }) => {
expect(await client.callTool({

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { test, expect } from './fixtures.js';
import { test, expect } from './fixtures';
test('--device should work', async ({ startClient, server, mcpMode }) => {
const { client } = await startClient({

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { test, expect } from './fixtures.js';
import { test, expect } from './fixtures';
test('alert dialog', async ({ client, server }) => {
server.setContent('/', `<button onclick="alert('Alert')">Button</button>`, 'text/html');

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { test, expect } from './fixtures.js';
import { test, expect } from './fixtures';
test('browser_evaluate', async ({ client, server }) => {
expect(await client.callTool({

View File

@@ -15,7 +15,7 @@
*/
import fs from 'fs/promises';
import { test, expect } from './fixtures.js';
import { test, expect } from './fixtures';
test('browser_file_upload', async ({ client, server }, testInfo) => {
server.setContent('/', `

View File

@@ -15,7 +15,6 @@
*/
import fs from 'fs';
import url from 'url';
import path from 'path';
import { chromium } from 'playwright';
@@ -23,7 +22,7 @@ import { test as baseTest, expect as baseExpect } from '@playwright/test';
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { ListRootsRequestSchema } from '@modelcontextprotocol/sdk/types.js';
import { TestServer } from './testserver/index.ts';
import { TestServer } from './testserver/index';
import type { Config } from '../config';
import type { BrowserContext } from 'playwright';
@@ -186,8 +185,6 @@ async function createTransport(args: string[], mcpMode: TestOptions['mcpMode'],
transport: Transport,
stderr: Stream | null,
}> {
// NOTE: Can be removed when we drop Node.js 18 support and changed to import.meta.filename.
const __filename = url.fileURLToPath(import.meta.url);
if (mcpMode === 'docker') {
const dockerArgs = ['run', '--rm', '-i', '--network=host', '-v', `${test.info().project.outputDir}:/app/test-results`];
const transport = new StdioClientTransport({
@@ -202,7 +199,7 @@ async function createTransport(args: string[], mcpMode: TestOptions['mcpMode'],
const transport = new StdioClientTransport({
command: 'node',
args: [path.join(path.dirname(__filename), '../cli.js'), ...args],
args: [path.join(__dirname, '../cli.js'), ...args],
cwd: path.dirname(test.info().config.configFile!),
stderr: 'pipe',
env: {

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { test, expect } from './fixtures.js';
import { test, expect } from './fixtures';
test('browser_fill_form (textbox)', async ({ client, server }) => {
server.setContent('/', `

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { test, expect } from './fixtures.js';
import { test, expect } from './fixtures';
for (const mcpHeadless of [false, true]) {
test.describe(`mcpHeadless: ${mcpHeadless}`, () => {

View File

@@ -14,20 +14,16 @@
* limitations under the License.
*/
import fs from 'node:fs';
import url from 'node:url';
import fs from 'fs';
import { ChildProcess, spawn } from 'node:child_process';
import path from 'node:path';
import { ChildProcess, spawn } from 'child_process';
import path from 'path';
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { test as baseTest, expect } from './fixtures.js';
import { test as baseTest, expect } from './fixtures';
import type { Config } from '../config.d.ts';
// NOTE: Can be removed when we drop Node.js 18 support and changed to import.meta.filename.
const __filename = url.fileURLToPath(import.meta.url);
const test = baseTest.extend<{ serverEndpoint: (options?: { args?: string[], noPort?: boolean }) => Promise<{ url: URL, stderr: () => string }> }>({
serverEndpoint: async ({ mcpHeadless }, use, testInfo) => {
let cp: ChildProcess | undefined;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { test, expect } from './fixtures.js';
import { test, expect } from './fixtures';
test('stitched aria frames', async ({ client }) => {
expect(await client.callTool({

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { test, expect } from './fixtures.js';
import { test, expect } from './fixtures';
test('browser_install', async ({ client, mcpBrowser }) => {
test.skip(mcpBrowser !== 'chromium', 'Test only chromium');

View File

@@ -16,7 +16,7 @@
import fs from 'fs';
import { test, expect, formatOutput } from './fixtures.js';
import { test, expect, formatOutput } from './fixtures';
test('test reopen browser', async ({ startClient, server, mcpMode }) => {
const { client, stderr } = await startClient();

View File

@@ -15,7 +15,7 @@
*/
import child_process from 'child_process';
import fs from 'fs/promises';
import { test, expect } from './fixtures.js';
import { test, expect } from './fixtures';
test('library can be used from CommonJS', { annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright-mcp/issues/456' } }, async ({}, testInfo) => {
const file = testInfo.outputPath('main.cjs');

View File

@@ -21,7 +21,7 @@ import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/
import { runMainBackend, runOnPauseBackendLoop } from '../src/mcp/mdb.js';
import { test, expect } from './fixtures.js';
import { test, expect } from './fixtures';
import type * as mcpServer from '../src/mcp/server.js';
import type { ServerBackendOnPause } from '../src/mcp/mdb.js';

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { test, expect } from './fixtures.js';
import { test, expect } from './fixtures';
test('browser_network_requests', async ({ client, server }) => {
server.setContent('/', `

View File

@@ -16,7 +16,7 @@
import fs from 'fs';
import { test, expect } from './fixtures.js';
import { test, expect } from './fixtures';
test('save as pdf unavailable', async ({ startClient, server }) => {
const { client } = await startClient();

View File

@@ -18,7 +18,7 @@ import fs from 'fs';
import path from 'path';
import { pathToFileURL } from 'url';
import { test, expect } from './fixtures.js';
import { test, expect } from './fixtures';
import { createHash } from '../src/utils/guid.js';
const p = process.platform === 'win32' ? 'c:\\non\\existent\\folder' : '/non/existent/folder';

View File

@@ -16,7 +16,7 @@
import fs from 'fs';
import { test, expect } from './fixtures.js';
import { test, expect } from './fixtures';
test('browser_take_screenshot (viewport)', async ({ startClient, server }, testInfo) => {
const { client } = await startClient({

View File

@@ -17,7 +17,7 @@
import fs from 'fs';
import path from 'path';
import { test, expect } from './fixtures.js';
import { test, expect } from './fixtures';
test('session log should record tool calls', async ({ startClient, server }, testInfo) => {
const { client, stderr } = await startClient({

View File

@@ -14,20 +14,16 @@
* limitations under the License.
*/
import fs from 'node:fs';
import url from 'node:url';
import fs from 'fs';
import { ChildProcess, spawn } from 'node:child_process';
import path from 'node:path';
import { ChildProcess, spawn } from 'child_process';
import path from 'path';
import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js';
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { test as baseTest, expect } from './fixtures.js';
import { test as baseTest, expect } from './fixtures';
import type { Config } from '../config.d.ts';
// NOTE: Can be removed when we drop Node.js 18 support and changed to import.meta.filename.
const __filename = url.fileURLToPath(import.meta.url);
const test = baseTest.extend<{ serverEndpoint: (options?: { args?: string[], noPort?: boolean }) => Promise<{ url: URL, stderr: () => string }> }>({
serverEndpoint: async ({ mcpHeadless }, use, testInfo) => {
let cp: ChildProcess | undefined;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { test, expect } from './fixtures.js';
import { test, expect } from './fixtures';
import type { Client } from '@modelcontextprotocol/sdk/client/index.js';

View File

@@ -16,7 +16,6 @@
*/
import fs from 'fs';
import url from 'node:url';
import http from 'http';
import https from 'https';
import path from 'path';
@@ -25,9 +24,6 @@ import debug from 'debug';
const fulfillSymbol = Symbol('fulfil callback');
const rejectSymbol = Symbol('reject callback');
// NOTE: Can be removed when we drop Node.js 18 support and changed to import.meta.filename.
const __filename = url.fileURLToPath(import.meta.url);
export class TestServer {
private _server: http.Server;
readonly debugServer: any;

View File

@@ -16,7 +16,7 @@
import fs from 'fs';
import { test, expect } from './fixtures.js';
import { test, expect } from './fixtures';
test('check that trace is saved', async ({ startClient, server, mcpMode }, testInfo) => {
const outputDir = testInfo.outputPath('output');

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { test, expect } from './fixtures.js';
import { test, expect } from './fixtures';
test('browser_type', async ({ client, server }) => {
server.setContent('/', `

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { test, expect } from './fixtures.js';
import { test, expect } from './fixtures';
test.use({ mcpArgs: ['--caps=verify'] });

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { test, expect } from './fixtures.js';
import { test, expect } from './fixtures';
test('browser_connect(vscode) works', async ({ startClient, playwright, browserName }) => {
const { client } = await startClient({
@@ -27,7 +27,7 @@ test('browser_connect(vscode) works', async ({ startClient, playwright, browserN
name: 'browser_connect',
arguments: {
connectionString: server.wsEndpoint(),
lib: import.meta.resolve('playwright'),
lib: require.resolve('playwright'),
}
})).toHaveResponse({
result: 'Successfully connected.'

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { test, expect } from './fixtures.js';
import { test, expect } from './fixtures';
test('browser_wait_for(text)', async ({ client, server }) => {
server.setContent('/', `

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { test, expect } from './fixtures.js';
import { test, expect } from './fixtures';
test('do not falsely advertise user agent as a test driver', async ({ client, server, mcpBrowser }) => {
test.skip(mcpBrowser === 'firefox');