/** * Utilities for parsing test files to extract hooks and tests * Supports Playwright hooks: test.beforeAll, test.afterAll, test.beforeEach, test.afterEach */ import type { TestPathway } from '../types'; export interface ParsedHook { code: string; name: string; suitePath?: string[]; scope: 'file' | 'suite'; statements: ParsedTestStatement[]; } export interface ParsedTestStatement { code: string; isVariableDeclaration: boolean; intentComment?: string; screenStateAnnotation?: string; scenarioAnnotation?: string; scenarioAnnotationLine?: number; stepId?: string; } export interface ParsedTest { name: string; code: string; suitePath?: string[]; fullName: string; statements: ParsedTestStatement[]; testBodyStartLine?: number; } export interface ParsedSuite { name: string; suitePath: string[]; beforeAll: ParsedHook[]; afterAll: ParsedHook[]; beforeEach: ParsedHook[]; afterEach: ParsedHook[]; tests: ParsedTest[]; nestedSuites: ParsedSuite[]; suiteVariables: string[]; } export interface ParsedTestFile { fileHooks: { beforeAll: ParsedHook[]; afterAll: ParsedHook[]; beforeEach: ParsedHook[]; afterEach: ParsedHook[]; }; tests: ParsedTest[]; suites: ParsedSuite[]; fileVariables: string[]; } /** * Extract text from a comment, handling both CommentLine and CommentBlock types * @param comment - Babel comment object * @returns Extracted comment text with markers stripped if needed */ export declare function extractCommentText(comment: any): string; export interface ScenarioAnnotationComponents { ordinalId?: string; title?: string; } export declare function parseScenarioAnnotationComponents(annotation: string): ScenarioAnnotationComponents; export declare class TestFileParser { /** * Generate full test name with suite prefix * @param suitePath - Array of suite names from root to current suite * @param testName - Original test name * @returns Full test name with suite prefix (e.g., "LoginSuite__testLogin") */ static generateTestFullName(suitePath: string[], testName: string): string; /** * Find all parent describe blocks for a given AST path * @param path - Babel AST path * @returns Array of suite names from root to current (empty if not in any describe block) */ static findSuitePath(path: any): string[]; /** * Extract statements from a function body (BlockStatement or Expression) * @param body - The function body (BlockStatement or Expression) * @param generateStepIds - Whether to generate stepIds for statements (for tests, not hooks) * @returns Object containing parsed statements and body code */ private static extractStatementsFromFunctionBody; /** * Parse a test file to extract hooks and tests, supporting test.describe() blocks * @param script - The test file content * @param testPathways - Optional array of test pathways to filter (suite path + test name) * @returns Parsed structure with hooks and tests */ static parseTestFile(script: string, testPathways?: TestPathway[]): ParsedTestFile; /** * Flatten suite structure into execution-ready format * Separates per-test hooks (beforeEach/afterEach) from per-suite hooks (beforeAll/afterAll) * @param parsed - Parsed test file structure * @returns Flattened structure ready for execution */ static flattenForExecution(parsed: ParsedTestFile): { fileLevelHooks: { beforeAll: ParsedHook[]; afterAll: ParsedHook[]; beforeEach: ParsedHook[]; afterEach: ParsedHook[]; }; fileVariables: string[]; tests: Array<{ test: ParsedTest; suitePath: string[]; suiteBeforeEachHooks: ParsedHook[]; suiteAfterEachHooks: ParsedHook[]; suiteVariables: string[]; }>; suites: Array<{ suitePath: string[]; beforeAll: ParsedHook[]; afterAll: ParsedHook[]; testIndices: number[]; suiteVariables: string[]; }>; }; /** * Construct a test script with imports and a single test using AST * This is more robust than string interpolation * @param originalScript - The full original script (to extract imports) * @param testName - The test name * @param testBodyCode - The test body code (already extracted) * @returns A complete script with imports and the test */ static constructTestScriptWithImports(originalScript: string, testName: string, testBodyCode: string): string; /** * Construct a script with imports from the original script + suite variables + hook code * This ensures hooks can access imported classes/functions (e.g., SignInPage) and suite-level variables */ static constructHookScriptWithImports(originalScript: string, hookCode: string): string; /** * Extract test body code from a repaired script * The repaired script contains imports + a single test, we need just the test body * @param script - The repaired script (with imports and test) * @returns The test body code (function body) or null if not found */ static extractTestBodyFromScript(script: string): string | null; /** * Reconstruct the full test file with repairs applied to specific tests * Preserves all structure (imports, hooks, suites, file variables, unrepaired tests) * @param originalScript - The original test file content * @param parsed - The parsed test file structure * @param testRepairs - Map of TestPathway (JSON stringified) -> repaired test body code * @returns The reconstructed test file with repairs applied */ static reconstructTestFileWithRepairs(originalScript: string, parsed: ParsedTestFile, testRepairs: Map): string; } //# sourceMappingURL=test-file-parser.d.ts.map