Files
AI/참고/playwright-main/tests/mcp/init-agents.spec.ts
2026-05-12 19:40:31 +09:00

93 lines
3.1 KiB
TypeScript

/**
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { test, expect, writeFiles } from './fixtures';
import { utils } from '../../packages/playwright-core/lib/coreBundle';
import path from 'path';
import fs from 'fs';
const { spawnAsync } = utils;
async function runInitAgents(options?: { args?: string[], cwd?: string }): Promise<{stdout: string, stderr: string, code: number | null, error?: Error}> {
const result = await spawnAsync('npx', [
'playwright', 'init-agents',
...(options?.args || []),
], {
cwd: options?.cwd,
shell: true,
});
return result;
}
test('create seed file default', async ({ }) => {
const baseDir = await writeFiles({
'playwright.config.ts': `
module.exports = {};
`,
});
await runInitAgents({
cwd: baseDir,
args: ['--loop', 'claude'],
});
expect(fs.existsSync(path.join(baseDir, 'seed.spec.ts'))).toBe(true);
});
test('create seed file with --project', async ({ }) => {
const baseDir = await writeFiles({
'playwright.config.ts': `
module.exports = { projects: [{ name: 'foo', testDir: 'foo/e2e' }, { name: 'bar', testDir: 'bar/e2e' }, ] };
`,
});
await runInitAgents({
cwd: baseDir,
args: ['--loop', 'vscode', '--project', 'bar'],
});
expect(fs.existsSync(path.join(baseDir, 'bar', 'e2e', 'seed.spec.ts'))).toBe(true);
});
test('create seed file with --config', async ({ }) => {
const baseDir = await writeFiles({
'custom/playwright.config.ts': `
module.exports = { projects: [{ name: 'foo', testDir: 'foo/e2e' }, { name: 'bar', testDir: 'bar/e2e' }, ] };
`,
});
await runInitAgents({
cwd: baseDir,
args: ['--loop', 'vscode', '--config', 'custom/playwright.config.ts', '--project', 'bar'],
});
expect(fs.existsSync(path.join(baseDir, 'custom', 'bar', 'e2e', 'seed.spec.ts'))).toBe(true);
});
test('claude generates correct mcp config', async ({ }) => {
const baseDir = await writeFiles({
'playwright.config.ts': `module.exports = {};`,
});
await runInitAgents({ cwd: baseDir, args: ['--loop', 'claude'] });
const mcpJson = JSON.parse(fs.readFileSync(path.join(baseDir, '.mcp.json'), 'utf-8'));
if (process.platform === 'win32') {
expect(mcpJson.mcpServers['playwright-test'].command).toBe('cmd');
expect(mcpJson.mcpServers['playwright-test'].args).toEqual(['/c', 'npx', 'playwright', 'run-test-mcp-server']);
} else {
expect(mcpJson.mcpServers['playwright-test'].command).toBe('npx');
expect(mcpJson.mcpServers['playwright-test'].args).toEqual(['playwright', 'run-test-mcp-server']);
}
});