UNPKG

scai

Version:

> AI-powered CLI tool for commit messages **and** pull request reviews — using local models.

37 lines (34 loc) 1.38 kB
// src/pipeline/modules/generateTestsModule.ts import fs from 'fs/promises'; import path from 'path'; import { Config } from '../../config.js'; import { generate } from '../../lib/generate.js'; export const generateTestsModule = { name: 'generateTests', description: 'Generate a Jest test file for the class/module', async run({ content, filepath }) { const model = Config.getModel(); const lang = Config.getLanguage(); if (!filepath) throw new Error('Missing filepath in pipeline context'); const prompt = ` You are a senior ${lang.toUpperCase()} engineer. Given the following class or module, generate a Jest test file. Guidelines: - Use the 'jest' test framework - Cover public methods and one edge case - Name the file <original>.test.ts - Only return valid TypeScript code --- CODE START --- ${content} --- CODE END --- `.trim(); const response = await generate({ content: prompt }, model); if (!response) throw new Error('⚠️ No test code returned from model'); const { dir, name } = path.parse(filepath); const testPath = path.join(dir, `${name}.test.ts`); await fs.writeFile(testPath, response.content, 'utf-8'); console.log(`✅ Test file saved to: ${testPath}`); return { content, filepath }; // unchanged input } };