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 ❤️.
69 lines (56 loc) • 2.36 kB
JavaScript
"use strict";
/* import path from 'path';
import { PromptModule } from '../../types.js';
import { generate } from '../../lib/generate.js';
import { detectFileType } from '../../fileRules/detectFileType.js';
import { Config } from '../../config.js';
export const generateTestsModule: PromptModule = {
name: 'tests',
description: 'Generate a Jest test file for the class/module',
async run({ content, filepath }) {
if (!filepath) throw new Error('Missing filepath in pipeline context');
const model = Config.getModel();
const lang = detectFileType(filepath);
const repoRoot = Config.getIndexDir();
// Compute relative import path (repo-relative, without extension)
const relativePath = path.relative(repoRoot, filepath);
const { dir, name, ext } = path.parse(relativePath);
const importPath = './' + path.join(dir, name).replace(/\\/g, '/');
// Where the test should be written (next to source file)
const absParsed = path.parse(filepath);
const testPath = path.join(absParsed.dir, `${absParsed.name}.test${ext}`);
const prompt = `
You are a senior ${lang.toUpperCase()} engineer. Generate a Jest test file for the module below.
Requirements:
- Use the 'jest' test framework.
- Always include imports at the top:
import { describe, it, expect } from '@jest/globals';
import * as moduleUnderTest from '${importPath}';
- Cover only one public method: the most relevant or central function.
- Include one edge case for that method.
- Preserve and consider existing code comments in the module.
- Only output valid ${lang} code; do not include markdown fences or explanations.
- Use this scaffold at minimum:
import { describe, it, expect } from '@jest/globals';
import * as moduleUnderTest from '${importPath}';
describe('moduleUnderTest', () => {
it('should ...', () => {
// test implementation
});
});
--- MODULE CODE ---
${content}
--- END MODULE CODE ---
`.trim();
const response = await generate({ content: prompt });
if (!response) throw new Error('⚠️ No test code returned from model');
return {
originalContent: content,
content: response.content, // the test code
filepath, // original file path
newFilepath: testPath,
mode: "newFile" // ensure it gets written as a new file
};
}
};
*/