import { readdirSync, mkdirSync } from 'fs'; import { readdir, rm, writeFile } from 'fs/promises'; import { join } from 'path'; import { promisify } from 'util'; import { chromium } from '@playwright/test'; import type { Browser, Page } from '@playwright/test'; import { execa } from 'execa'; import type { ResultPromise } from 'execa'; import tkKill from 'tree-kill'; import { describe, it, beforeAll, afterAll, expect } from 'vitest'; import { createRouter, createMemoryHistory } from 'vue-router'; import type { RouteRecordRaw } from 'vue-router'; const kill = promisify(tkKill); /** * Function to generate sample routes for a given route path using Vue Router. * Initializes a new Vue Router instance per route path. */ function generateSampleRoutes(routePath: string): string[] { // Ensure unique route names by appending a random string const routeName = `TestRoute${Math.random().toString(36) .substring(2, 15)}`; const routeRecord: RouteRecordRaw = { path: routePath, name: routeName, component: { template: '
' }, // Dummy component }; const router = createRouter({ history: createMemoryHistory(), routes: [routeRecord], }); const routeMatcher = router.getRoutes().find((r) => r.name === routeName); if (!routeMatcher) { throw new Error(`Route not found for path: ${routePath}`); } // Extract route parameters from the path. const paramNames: RouteParameter[] = extractRouteParams(routePath); // Generate combinations of parameters including permutations of optional parameters. const paramCombinations = generateParamCombinations(paramNames); const sampleRoutes: string[] = []; for (const paramsObj of paramCombinations) { const resolvedRoute = router.resolve({ name: routeName, params: paramsObj }); sampleRoutes.push(resolvedRoute.path); } return sampleRoutes; } interface RouteParameter { name: string; pattern: string | null; modifier: string; optional: boolean; } /** * Extracts route parameters from the route path using regular expressions. */ function extractRouteParams(path: string): RouteParameter[] { const dynamicSegmentRegex = /:([a-zA-Z0-9_]+)(?:\(([^)]+)\))?([+*?])?/g; const params: RouteParameter[] = []; let match; while ((match = dynamicSegmentRegex.exec(path)) !== null) { const paramName = match[1]; // Group 1: Parameter name. const pattern = match[2] || null; // Group 2: Pattern inside parentheses, if any. const modifier = match[3] || ''; // Group 3: Modifier (e.g., '?', '*', '+'), if any. const isOptional = modifier === '?' || modifier === '*'; params.push({ name: paramName, pattern, modifier, optional: isOptional, }); } return params; } /** * Generates all combinations of parameters, including permutations of optional * parameters. */ function generateParamCombinations(params: RouteParameter[]): Record