Skip to content

zengwmFE/ai-unit-test

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AI Unit Test Generator

This small project is meant to produce unit tests for a React frontend by leveraging an OpenAI-compatible API via LangChain.js.

Usage

  1. Install dependencies:
    npm install
  2. Set your API key in the environment:
    export DASHSCOPE_API_KEY="your-key-here"
  3. Run the generator pointing at the React project:
    npm run generate -- ../react-frontend

The script will scan src/components/**/*.js and src/data/**/*.js files (excluding *.test.js) and ask the model (via LangChain.js) to produce Jest/React Testing Library tests. Generated tests are saved as sibling *.test.js files next to the source files.

To speed up generation, files are processed in parallel. You can control concurrency with:

export GENERATE_CONCURRENCY=5  # default is 3

Configuration (whitelist & blacklist)

You can control which files are processed via ai-unit-test.config.json in this project root.

  • includePatterns: whitelist of folders / files (glob, relative to the React project root passed on the CLI)
  • excludePatterns: blacklist of folders / files (glob, relative to the React project root)
  • changeDetection: "git" | "missing" | "mtime" | "all" (default "git")
  • gitBaseRef / gitHeadRef: used when changeDetection="git" (default origin/main and HEAD)

Example:

{
  "includePatterns": [
    "src/components/**/*.js",
    "src/data/**/*.js"
  ],
  "excludePatterns": [
    "**/*.test.js",
    "src/components/__generated__/**",
    "src/components/**/stories/**"
  ],
  "changeDetection": "git",
  "gitBaseRef": "origin/main",
  "gitHeadRef": "HEAD"
}

About

openai langchain 实现unit test自动补全

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors