( setupScript: string, )
| 29 | |
| 30 | /** Loads and validates a setup script module from the given path. */ |
| 31 | export async function loadSetupScript( |
| 32 | setupScript: string, |
| 33 | ): Promise<SetupFunction> { |
| 34 | const absolutePath = path.isAbsolute(setupScript) |
| 35 | ? setupScript |
| 36 | : path.join(process.cwd(), setupScript); |
| 37 | |
| 38 | if (!(await fileExists(absolutePath))) { |
| 39 | throw new Error(`Setup script not found: ${absolutePath}`); |
| 40 | } |
| 41 | |
| 42 | const validModule = await logger.task( |
| 43 | `Loading setup script from ${absolutePath}`, |
| 44 | async () => { |
| 45 | const url = pathToFileURL(absolutePath).toString(); |
| 46 | const module: unknown = await import(url); |
| 47 | const validated = await validateAsync(setupScriptModuleSchema, module, { |
| 48 | filePath: absolutePath, |
| 49 | }); |
| 50 | return { message: 'Setup script loaded successfully', result: validated }; |
| 51 | }, |
| 52 | ); |
| 53 | |
| 54 | return validModule.default; |
| 55 | } |
| 56 | |
| 57 | /** Executes the setup function with the provided Playwright page. */ |
| 58 | export async function runSetup( |
no test coverage detected