detect_project_state
Analyzes project structure to detect existing Playwright configuration, migrated tests, page objects, and WDIO setup for understanding current migration state.
Instructions
Analyzes project structure to detect existing Playwright configuration, migrated tests, page objects, and WDIO setup. Helps understand current migration state.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| projectFiles | Yes | JSON string containing file paths and their contents to analyze |
Implementation Reference
- src/handlers/toolHandlers.js:233-343 (handler)The implementation of the `handleDetectProjectState` function, which analyzes project files to identify test frameworks, config files, and project structure.
export async function handleDetectProjectState(args) { const { projectFiles } = args; let files = {}; try { files = JSON.parse(projectFiles); } catch (e) { return { content: [{ type: 'text', text: 'Error: projectFiles must be a valid JSON object with file paths as keys and contents as values', }], isError: true, }; } const state = { hasPlaywrightConfig: false, hasWdioConfig: false, playwrightConfigPath: null, wdioConfigPath: null, playwrightTests: [], wdioTests: [], mixedTests: [], pageObjects: [], existingStructure: { testsDir: null, pagesDir: null, fixturesDir: null, }, packageJson: null, recommendations: [], }; for (const [filePath, content] of Object.entries(files)) { const lowerPath = filePath.toLowerCase(); if (lowerPath.includes('playwright.config')) { state.hasPlaywrightConfig = true; state.playwrightConfigPath = filePath; state.existingConfig = parsePlaywrightConfig(content); } if (lowerPath.includes('wdio.conf')) { state.hasWdioConfig = true; state.wdioConfigPath = filePath; } if (lowerPath.match(/\.(spec|test)\.(js|ts)$/)) { const ast = parseCode(content); const framework = detectFramework(ast); if (framework.isPlaywright) { state.playwrightTests.push(filePath); } else if (framework.isWdio) { state.wdioTests.push(filePath); } else if (framework.isMixed) { state.mixedTests.push(filePath); } } if (lowerPath.includes('page') && lowerPath.match(/\.(js|ts)$/)) { if (content.includes('export class') && content.includes('constructor(page)')) { state.pageObjects.push(filePath); } } if (lowerPath.includes('/tests/') || lowerPath.includes('/test/')) { state.existingStructure.testsDir = filePath.split('/tests/')[0] + '/tests/' || filePath.split('/test/')[0] + '/test/'; } if (lowerPath.includes('/pages/')) { state.existingStructure.pagesDir = filePath.split('/pages/')[0] + '/pages/'; } if (lowerPath.includes('/fixtures/')) { state.existingStructure.fixturesDir = filePath.split('/fixtures/')[0] + '/fixtures/'; } if (lowerPath.endsWith('package.json')) { try { state.packageJson = JSON.parse(content); } catch (e) { // Ignore } } } // Generate recommendations if (state.hasPlaywrightConfig && state.wdioTests.length > 0) { state.recommendations.push('Playwright already configured. Migrate remaining WDIO tests.'); } if (!state.hasPlaywrightConfig && state.hasWdioConfig) { state.recommendations.push('Use migrate_config tool to convert wdio.conf to playwright.config'); } if (state.mixedTests.length > 0) { state.recommendations.push(`${state.mixedTests.length} tests have mixed WDIO/Playwright code - complete migration`); } if (state.pageObjects.length > 0) { state.recommendations.push(`${state.pageObjects.length} existing page objects found - can be reused or extended`); } if (state.existingStructure.pagesDir) { state.recommendations.push(`Use existing pages directory: ${state.existingStructure.pagesDir}`); } return { content: [{ type: 'text', text: JSON.stringify(state, null, 2), }], }; }