UNPKG

scai

Version:

> **AI-powered CLI for local code analysis, commit message suggestions, and natural-language queries.** 100% local, private, GDPR-friendly, made in Denmark/EU with ❤️.

38 lines (37 loc) 1.61 kB
import { execSync } from "child_process"; import path from "path"; export const runTestsModule = { name: "runTestsModule", description: "Runs generated Jest tests with safety checks for a single file", async run(input) { const { filepath } = input; if (!filepath) { throw new Error("No filepath provided to runTestsModule."); } const absoluteFilePath = path.resolve(filepath); try { // Step 1: TypeScript syntax check for this file only using tsconfig.test.json // Step 1: TypeScript syntax check for this file only execSync(`npx tsc --noEmit --project tsconfig.test.json`, { stdio: "inherit" }); // Step 2: Dry-run Jest for this file only execSync(`npx jest --config ${path.resolve("jest.config.ts")} --dryRun ${absoluteFilePath}`, { stdio: "inherit" }); // Step 3: Full Jest run for this file only execSync(`npx jest --config ${path.resolve("jest.config.ts")} ${absoluteFilePath}`, { stdio: "inherit" }); return { content: "✅ Tests ran successfully", filepath, mode: "skip", summary: "All tests passed successfully." }; } catch (error) { const errorMessage = error?.message || String(error); return { content: `❌ Test run failed:\n${errorMessage}`, filepath, mode: "skip", summary: errorMessage // provides failure context for repair }; } } };