DEV.co
Open-Source Testing · skovhus

jest-codemods

jest-codemods is an automated migration tool that converts test files from 10+ testing frameworks (Mocha, Chai, AVA, Tape, Jasmine, Sinon, etc.) to Jest syntax. It uses codemods—small AST-based programs—to perform bulk code transformations, reducing manual effort when adopting Jest.

Source: GitHub — github.com/skovhus/jest-codemods
888
GitHub stars
81
Forks
TypeScript
Primary language
MIT
License (OSI-approved)

Key facts

Objective fields from the source. Values we can't verify are shown as “Unknown” rather than guessed.

FieldValue
Repositoryskovhus/jest-codemods
Ownerskovhus
Primary languageTypeScript
LicenseMIT — OSI-approved
Stars888
Forks81
Open issues36
Latest release0.35.0 (2025-08-13)
Last updated2026-06-30
Sourcehttps://github.com/skovhus/jest-codemods

What jest-codemods is

A TypeScript-based jscodeshift wrapper that exposes framework-specific AST transformers for test suite migration. It preserves code quoting style, detects import/require statements to determine applicable transformations, and outputs warnings for incompatible patterns. Designed for Node.js test environments with optional explicit require() support for browser or non-Jest runners.

Quickstart

Get the jest-codemods source

Clone the repository and explore it locally.

terminalbash
git clone https://github.com/skovhus/jest-codemods.gitcd jest-codemods# follow the project's README for install & configuration

Need it deployed, integrated, or customized instead? DEV.co ships production installs.

Best use cases

Large Mocha/Chai migrations

Automate assertion syntax and mock/stub conversion when migrating 100+ test files from Mocha+Chai to Jest, reducing manual refactoring and human error.

AVA or Tape to Jest conversions

Bulk-convert AVA's concurrency patterns and Tape's callback-based assertions to Jest's parallel test blocks and expect API in projects with extensive test suites.

Multi-framework test consolidation

Consolidate legacy test suites using different frameworks (Jasmine + Sinon + Chai in same repo) into unified Jest setup with consistent assertion and mocking syntax.

Implementation considerations

  • Always run with --dry flag first to inspect proposed changes; even with good coverage, some assertions and mocks require manual post-migration fixes.
  • Ensure Jest and supporting packages (jest-mock, expect) are installed before running codemods; some transformations insert new imports that assume availability.
  • Original code quoting style is preserved, but review for consistency; codemod outputs may mix single/double quotes depending on source files.
  • Test against your full suite in a branch; some patterns (complex spy chains, global teardown) may not transform correctly and require manual intervention.
  • Use jscodeshift directly for fine-tuned control (e.g., targeting specific files or applying partial transformations).

When to avoid it — and what to weigh

  • Heavy custom test utilities — If your test framework wraps assertions or mocking in custom domain-specific utilities, codemods may not recognize or transform them correctly; manual review required.
  • Minimal test coverage — For projects with <5 test files or simple, homogeneous test syntax, manual migration is often faster and less error-prone than setting up and validating codemod runs.
  • Snapshot or integration test heavy suites — Codemods may incorrectly transform complex mocking, global state, or browser-specific test patterns; visual inspection and rework post-migration is expected.
  • Production test runners in browsers — If tests must run in non-Node.js environments without explicit require() support, migration may fail or require significant manual tweaks after codemod execution.

License & commercial use

MIT License. Permissive; allows commercial use, modification, and distribution with attribution. No legal restrictions on commercial deployment.

MIT is a standard permissive OSI license. Commercial use is permitted. No licensing fees, per-seat charges, or proprietary restrictions apply. Verify your own Jest license and test dependencies for any commercial constraints.

DEV.co evaluation signals

Editorial assessment — not user reviews. Directional, with an explicit confidence level.

SignalAssessment
MaintenanceActive
DocumentationAdequate
License clarityClear
Deployment complexityLow
DEV.co fitGood
Assessment confidenceHigh
Security considerations

Codemods execute arbitrary AST transformation on local files; only run on trusted or version-controlled codebases. No network communication or external dependency downloads during transformation. Use --dry flag to review changes before committing. Ensure Node.js and jscodeshift are up to date.

Alternatives to consider

Manual migration + linting rules

For small suites or heterogeneous test code, direct refactoring combined with ESLint rules (e.g., eslint-plugin-jest) may be clearer and require less validation.

TypeScript compiler or Babel plugins

If you control test syntax from the start, use Jest's TypeScript support and Babel presets to avoid test framework switching; codemods only needed if locked into legacy frameworks.

IDE refactoring + find-replace

For small migrations or framework-specific edge cases, IDE bulk-replace and multi-file edit often converge faster and with fewer surprises than codemod validation loops.

Software development agency

Build on jest-codemods with DEV.co software developers

Start with a dry run on a feature branch. Use npx jest-codemods to inspect changes, then validate thoroughly before committing. For large multi-framework projects, consider professional migration services.

Talk to DEV.co

Related open-source tools

Surfaced by semantic similarity across the DEV.co open-source index.

Related on DEV.co

Explore the category and the services that help you build with it.

jest-codemods FAQ

Do I need to install Jest before running jest-codemods?
No, codemods run without Jest installed. However, you should install Jest and any new dependencies (expect, jest-mock) before running tests post-migration, and may want to generate jest.config.js separately.
What happens to complex mocks or spies?
Codemods handle common sinon and proxyquire patterns, but complex chains, dynamic stubs, or framework-specific context may not transform correctly. Manual review is expected; use --dry to inspect first.
Can I run jest-codemods on a subset of files?
Yes. Use glob patterns: npx jest-codemods 'src/**/*.test.js' or jscodeshift with explicit file paths to target specific tests.
Are there compatibility issues with Jest?
Not generally, but ensure your Jest version supports your Node.js LTS and any new dependencies (jest-mock, expect) are compatible. Codemods output warnings for incompatible patterns; address those before committing.

Custom software development services

DEV.co helps companies turn open-source tools like jest-codemods into production software. Our software development services cover the full lifecycle — architecture, web development, integration, and maintenance — delivered by software developers and web developers who ship. Engage our software development agency to implement or customize it for your open-source testing stack.

Ready to migrate your test suite to Jest?

Start with a dry run on a feature branch. Use npx jest-codemods to inspect changes, then validate thoroughly before committing. For large multi-framework projects, consider professional migration services.