Prerequisites
Before installing Codeflash for JavaScript, ensure you have:- Node.js 16 or above installed
- A JavaScript/TypeScript project with a package manager (npm, yarn, pnpm, or bun)
- Project dependencies installed
- Unit Tests that Codeflash uses to ensure correctness of the optimizations
Run Automatic Configuration
Navigate to your projectβs root directory (where your When running After you have answered these questions, the Codeflash configuration will be saved in a
package.json file is) and run:codeflash init, you will see the following prompts:codeflash.config.js file.Test Data Serialization StrategyCodeflash uses V8 serialization for JavaScript test data capture. This provides:
- β‘ Best performance: 2-3x faster than alternatives
- π― Perfect type preservation: Maintains Date, Map, Set, TypedArrays, and more
- π¦ Compact binary storage: Smallest file sizes
- π Framework agnostic: Works with React, Vue, Angular, Svelte, and vanilla JS
Generate a Codeflash API Key
Codeflash uses cloud-hosted AI models and integrations with GitHub. If you havenβt created one already, youβll need to create an API key to authorize your access.
- Visit the Codeflash Web App
- Sign up with your GitHub account (free)
- Navigate to the API Key page to generate your API key
Free Tier AvailableCodeflash offers a free tier with a limited number of optimizations. Perfect for trying it out on small projects!
Install the Codeflash GitHub App
Finally, if you have not done so already, Codeflash will ask you to install the GitHub App in your repository.
The Codeflash GitHub App allows the codeflash-ai bot to open PRs, review code, and provide optimization suggestions.Please install the Codeflash GitHub
app by choosing the repository you want to install
Codeflash on.
Framework Support
Codeflash JavaScript support works seamlessly with all major frameworks and testing libraries:Frontend Frameworks
- React
- Vue.js
- Angular
- Svelte
- Solid.js
Test Frameworks
- Jest
- Vitest
- Mocha
- AVA
- Playwright
- Cypress
Backend
- Express
- NestJS
- Fastify
- Koa
- Hono
Runtimes
- Node.js β (Recommended)
- Bun (Coming soon)
- Deno (Coming soon)
Understanding V8 Serialization
Codeflash uses Node.jsβs native V8 serialization API to capture and compare test data. Hereβs what makes it powerful:Type Preservation
Unlike JSON serialization, V8 serialization preserves JavaScript-specific types:Try It Out!
- Quick Start
- TypeScript Support
- Test Framework Examples
Once configured, you can start optimizing your JavaScript/TypeScript code immediately:
Troubleshooting
π¦ Module not found errors
π¦ Module not found errors
Make sure:
- β All project dependencies are installed
- β
Your
node_modulesdirectory exists
π§ V8 serialization errors
π§ V8 serialization errors
If you encounter serialization errors:Functions and classes cannot be serialized:Symbols are not serializable:
π§ͺ No optimizations found
π§ͺ No optimizations found
Not all functions can be optimized - some code is already optimal. This is expected.Use the This will show:
--verbose flag for detailed output:- π Which functions are being analyzed
- π« Why certain functions were skipped
- β οΈ Detailed error messages
- π Performance analysis results
π Test discovery issues
π Test discovery issues
Verify:
- π Your test directory path is correct in
codeflash.config.js - π Tests are discoverable by your test framework
- π Test files follow naming conventions (
*.test.js,*.spec.js)
Configuration
Yourcodeflash.config.js file controls how Codeflash analyzes your JavaScript project:
Next Steps
- Learn about Codeflash Concepts
- Explore Optimization workflows
- Set up Pull Request Optimization
- Read configuration options for advanced setups