This small project is meant to produce unit tests for a React frontend by leveraging an OpenAI-compatible API via LangChain.js.
- Install dependencies:
npm install
- Set your API key in the environment:
export DASHSCOPE_API_KEY="your-key-here"
- 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 3You 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"(defaultorigin/mainandHEAD)
Example:
{
"includePatterns": [
"src/components/**/*.js",
"src/data/**/*.js"
],
"excludePatterns": [
"**/*.test.js",
"src/components/__generated__/**",
"src/components/**/stories/**"
],
"changeDetection": "git",
"gitBaseRef": "origin/main",
"gitHeadRef": "HEAD"
}