Skip to main content

API Reference

Functions

generateTests(sourceFile, config, options?)

Main entry point. Analyzes a source file, generates tests via LLM, and writes the test file.

ParameterTypeDescription
sourceFilestringPath to the source file
configAutotestConfigConfiguration object
options.dryRunbooleanIf true, don't write the file
options.onChunk(text: string) => voidStreaming callback

Returns: Promise<AutotestResult>


analyzeFile(filePath)

Parses a TypeScript/JavaScript file using the TS compiler API and extracts its structure.

ParameterTypeDescription
filePathstringPath to the source file

Returns: AnalyzedFile


resolveConfig(overrides, cwd?)

Resolves the final configuration by merging defaults, config file, package.json, and overrides.

ParameterTypeDescription
overridesPartial<AutotestConfig>CLI flags or manual overrides
cwdstringWorking directory (default: process.cwd())

Returns: AutotestConfig


detectFramework(packageJson)

Detects the test framework from a parsed package.json object.

Returns: TestFramework ('vitest' or 'jest')


getFrameworkInfo(framework)

Returns metadata about a test framework.

Returns: FrameworkInfo


Types

AutotestConfig

interface AutotestConfig {
provider: string;
model?: string;
apiKey?: string;
framework: TestFramework;
outDir?: string;
overwrite: boolean;
edgeCases: boolean;
errorHandling: boolean;
instructions?: string;
maxTokens: number;
temperature: number;
}

AutotestResult

interface AutotestResult {
sourceFile: string;
testFile: string;
testCount: number;
categories: TestCategory[];
duration: number;
tokensUsed: number;
}

AnalyzedFile

interface AnalyzedFile {
filePath: string;
fileName: string;
language: 'typescript' | 'javascript';
sourceCode: string;
exports: ExportedSymbol[];
imports: ImportStatement[];
dependencies: string[];
}

ExportedSymbol

interface ExportedSymbol {
name: string;
kind: SymbolKind;
signature: string;
jsDoc?: string;
isAsync: boolean;
isDefault: boolean;
lineNumber: number;
parameters?: ParameterInfo[];
returnType?: string;
}

ParameterInfo

interface ParameterInfo {
name: string;
type?: string;
optional: boolean;
defaultValue?: string;
}

TestFramework

type TestFramework = 'vitest' | 'jest';

SymbolKind

type SymbolKind =
| 'function'
| 'class'
| 'variable'
| 'type'
| 'interface'
| 'enum'
| 'arrow-function';

DEFAULT_CONFIG

const DEFAULT_CONFIG: AutotestConfig = {
provider: 'openai',
framework: 'vitest',
overwrite: false,
edgeCases: true,
errorHandling: true,
maxTokens: 4096,
temperature: 0.2,
};