Skip to main content
Codeflash now supports JavaScript and TypeScript projects with optimized test data serialization using V8 native serialization.

Prerequisites

Before installing Codeflash for JavaScript, ensure you have:
  1. Node.js 16 or above installed
  2. A JavaScript/TypeScript project with a package manager (npm, yarn, pnpm, or bun)
  3. Project dependencies installed
Good to have (optional):
  1. Unit Tests that Codeflash uses to ensure correctness of the optimizations
Node.js Runtime RequiredCodeflash JavaScript support uses V8 serialization API, which is available natively in Node.js. Make sure you’re running on Node.js 16+ for optimal compatibility.
node --version  # Should show v16.0.0 or higher
1

Install Codeflash CLI

Install Codeflash globally or as a development dependency in your project:
npm install --save-dev codeflash
Development Dependency RecommendedCodeflash is intended for development and CI workflows. Installing as a dev dependency keeps your production bundle clean.
2

Run Automatic Configuration

Navigate to your project’s root directory (where your package.json file is) and run:
codeflash init
When running codeflash init, you will see the following prompts:
1. Enter your Codeflash API key (or login with Codeflash)
2. Which JavaScript/TypeScript module do you want me to optimize? (e.g. src/)
3. Where are your tests located? (e.g. tests/, __tests__/, *.test.js)
4. Which test framework do you use? (jest/vitest/mocha/ava/other)
5. Which code formatter do you use? (prettier/eslint/biome/disabled)
6. Which git remote should Codeflash use for Pull Requests? (if multiple remotes exist)
7. Help us improve Codeflash by sharing anonymous usage data?
8. Install the GitHub app
9. Install GitHub actions for Continuous optimization?
After you have answered these questions, the Codeflash configuration will be saved in a 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
3

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.
  1. Visit the Codeflash Web App
  2. Sign up with your GitHub account (free)
  3. 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!
4

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:
// These types are preserved perfectly:
const testData = {
  date: new Date(),                    // βœ… Date objects
  map: new Map([['key', 'value']]),   // βœ… Map instances
  set: new Set([1, 2, 3]),            // βœ… Set instances
  buffer: Buffer.from('hello'),        // βœ… Buffers
  typed: new Uint8Array([1, 2, 3]),   // βœ… TypedArrays
  bigint: 9007199254740991n,          // βœ… BigInt
  regex: /pattern/gi,                  // βœ… RegExp
  undef: undefined,                    // βœ… undefined (not null!)
  circular: {}                         // βœ… Circular references
};
testData.circular.self = testData.circular;
Why Not JSON?JSON serialization would cause bugs to slip through:
  • Date becomes string β†’ date arithmetic fails silently
  • Map becomes {} β†’ .get() calls return undefined
  • undefined becomes null β†’ type checks break
  • TypedArrays become plain objects β†’ binary operations fail
V8 serialization catches these issues during optimization verification.

Try It Out!

Once configured, you can start optimizing your JavaScript/TypeScript code immediately:
# Optimize a specific function
codeflash --file path/to/your/file.js --function functionName

# Or optimize all functions in your codebase
codeflash --all

Troubleshooting

Make sure:
  • βœ… All project dependencies are installed
  • βœ… Your node_modules directory exists
# Reinstall dependencies
npm install
# or
yarn install
If you encounter serialization errors:Functions and classes cannot be serialized:
// ❌ Won't work - contains function
const data = { callback: () => {} };

// βœ… Works - pure data
const data = { value: 42, items: [1, 2, 3] };
Symbols are not serializable:
// ❌ Won't work
const data = { [Symbol('key')]: 'value' };

// βœ… Use string keys
const data = { key: 'value' };
Not all functions can be optimized - some code is already optimal. This is expected.Use the --verbose flag for detailed output:
codeflash optimize --verbose
This will show:
  • πŸ” Which functions are being analyzed
  • 🚫 Why certain functions were skipped
  • ⚠️ Detailed error messages
  • πŸ“Š Performance analysis results
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)
# Test if your test framework can discover tests
npm test -- --listTests  # Jest
# or
npx vitest list  # Vitest

Configuration

Your codeflash.config.js file controls how Codeflash analyzes your JavaScript project:
module.exports = {
  // Source code to optimize
  module: 'src',

  // Test location
  tests: 'tests',

  // Test framework
  testFramework: 'jest',

  // Serialization strategy (automatically set to 'v8')
  serialization: 'v8',

  // Formatter
  formatter: 'prettier',

  // Additional options
  exclude: ['node_modules', 'dist', 'build'],
  verbose: false
};

Next Steps