UNPKG

@competent-devs/test-forge

Version:

Package for UI unit test generation based on storybook context

91 lines (79 loc) 2.97 kB
#!/usr/bin/env node import { Command } from "commander"; import { getPrompt } from "../services/prompt-generator.js"; import { searchSimilar, collectDb } from "../rag/cli.js"; import { getSnapshots } from "../rag/utils/collectSnapshots.js"; import { processFile } from "../draft-test-forge-v2-latest/test-forge.js"; import { runVitest } from "../draft-test-forge-v2-latest/run-test.js"; import { getConfig } from "../services/config.js"; import * as path from "path"; const program = new Command(); program .name("test-forge") .option("-n, --name <string>", "Name parameter for Metadata argument") .option("-s, --similarCases <string...>", "Similar test cases") .option("-e, --error <string>", "Error message from previous tests") .option("-rdb, --regeneratedb", "Flag to run script with creating index") .option("-fp, --filePath <string>", "path to components") .option("-cp, --codePath <string>", "path to component") .option("-pp, --projectPath <string>", "path to project") .option("-c, --code <string>", "string of code to search") .option( "-rl, --resetLog", "Flag indicating if log file should be cleared before command", ) .description("A CLI tool for test-forge library") .version("1.0.0"); program .command("getPrompt") .description("Run the main function") .action(() => { const { name, similarCases = [], error = "" } = program.opts(); if (!name) { console.error("name is required!"); } console.log(similarCases); console.log(getPrompt({ name }, similarCases, { message: error })); }); program .command("getSnapshots") .description("test getSnapshots") .action(async () => { getSnapshots(); }); program .command("findSimilarTests") .description("find similar tests for provided code") .action(async () => { const { regeneratedb, filePath } = program.opts(); if (!!regeneratedb) { await collectDb(filePath); } await searchSimilar( `<div class="MuiChip-root MuiChip-filled MuiChip-sizeMedium MuiChip-colorDefault MuiChip-filledDefault css-4oop98"><span class="MuiChip-label MuiChip-labelMedium css-14vsv3w">Chip Filled</span></div>`, ); }); program .command("generateTest") .description("generate tests for provided path") .action(async () => { const { filePath, codePath, resetLog } = program.opts(); const targetStorybookFile = path.join(process.cwd(), filePath); const targetCodeFile = path.join(process.cwd(), codePath); await processFile(targetStorybookFile, targetCodeFile, !!resetLog); }); program .command("runTest") .description("run tests of specific file") .action(async () => { const { filePath } = program.opts(); await runVitest(filePath); }); program .command("findConfig") .description("find test-forge specific config file in a parent project") .action(async () => { const result = await getConfig(); console.log(result); }); program.parse(process.argv);