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
test: add tests for init-agents command (#37643)
Yury Semikhatsky55e9555941bd
diff --git a/tests/mcp/init-agents.spec.ts b/tests/mcp/init-agents.spec.tsnew file mode 100644index 0000000000..cedb2bd91d--- /dev/null+++ b/tests/mcp/init-agents.spec.ts@@ -0,0 +1,124 @@+/**+ * 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 { spawnAsync } from '../../packages/playwright-core/lib/server/utils/spawnAsync';++import path from 'path';+import fs from 'fs';++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('init claude agents', async ({ }) => {+ const baseDir = await writeFiles({+ 'playwright.config.ts': `+ module.exports = {};+ `,+ });++ await runInitAgents({+ cwd: baseDir,+ args: ['--loop', 'claude'],+ });+ expect(fs.existsSync(path.join(baseDir, '.claude', 'agents', 'playwright-test-planner.md'))).toBe(true);+ expect(fs.existsSync(path.join(baseDir, '.claude', 'agents', 'playwright-test-generator.md'))).toBe(true);+ expect(fs.existsSync(path.join(baseDir, '.claude', 'agents', 'playwright-test-healer.md'))).toBe(true);+});++test('init vscode agents', async ({ }) => {+ const baseDir = await writeFiles({+ 'playwright.config.ts': `+ module.exports = {};+ `,+ });++ await runInitAgents({+ cwd: baseDir,+ args: ['--loop', 'vscode'],+ });+ expect(fs.existsSync(path.join(baseDir, '.github', 'chatmodes', '🎭 generator.chatmode.md'))).toBe(true);+ expect(fs.existsSync(path.join(baseDir, '.github', 'chatmodes', ' 🎭 planner.chatmode.md'))).toBe(true);+ expect(fs.existsSync(path.join(baseDir, '.github', 'chatmodes', '🎭 healer.chatmode.md'))).toBe(true);+ expect(fs.existsSync(path.join(baseDir, '.vscode', 'mcp.json'))).toBe(true);+});++test('init opencode agents', async ({ }) => {+ const baseDir = await writeFiles({+ 'playwright.config.ts': `+ module.exports = {};+ `,+ });++ await runInitAgents({+ cwd: baseDir,+ args: ['--loop', 'opencode'],+ });+ expect(fs.existsSync(path.join(baseDir, '.opencode', 'prompts', 'playwright-test-planner.md'))).toBe(true);+ expect(fs.existsSync(path.join(baseDir, '.opencode', 'prompts', 'playwright-test-generator.md'))).toBe(true);+ expect(fs.existsSync(path.join(baseDir, '.opencode', 'prompts', 'playwright-test-healer.md'))).toBe(true);+ expect(fs.existsSync(path.join(baseDir, 'opencode.json'))).toBe(true);+});