{"id":13368,"library":"jest-codemods","title":"Jest Codemods","description":"jest-codemods is a utility package providing a collection of automated code transformations (codemods) designed to simplify the migration of existing JavaScript and TypeScript test files to the Jest testing framework. It supports migrations from a wide array of popular testing libraries, including AVA, Chai, Expect.js, Jasmine, Mocha, proxyquire, Should.js, Tape, Sinon, and Node-Tap. Currently at version 0.35.0, the project maintains an active release cadence, frequently incorporating new features, bug fixes, and dependency updates. Its primary differentiator is the comprehensive support for various source frameworks, offering both an interactive command-line interface (CLI) for ease of use and direct integration with jscodeshift for more granular control over transformations, making it an indispensable tool for projects transitioning to Jest by significantly reducing manual refactoring efforts.","status":"active","version":"0.35.0","language":"javascript","source_language":"en","source_url":"https://github.com/skovhus/jest-codemods","tags":["javascript","codemod","jest","ava","tape","mocha","chai","proxyquire","migrate"],"install":[{"cmd":"npm install jest-codemods","lang":"bash","label":"npm"},{"cmd":"yarn add jest-codemods","lang":"bash","label":"yarn"},{"cmd":"pnpm add jest-codemods","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core dependency for running the codemods, as jest-codemods builds on top of its transformation engine.","package":"jscodeshift","optional":false}],"imports":[{"note":"This is the recommended and most common way to run jest-codemods, offering an interactive CLI experience to select desired transformations.","symbol":"jest-codemods CLI","correct":"npx jest-codemods [path] [options]"},{"note":"For direct, non-interactive use of a specific codemod, install `jscodeshift` globally and point it to the transformer file within the `jest-codemods` package. Do not attempt to import transformers as modules in user code.","wrong":"import { ava } from 'jest-codemods'","symbol":"Specific Transformer (e.g., AVA)","correct":"jscodeshift -t node_modules/jest-codemods/dist/transformers/ava.js <files...>"},{"note":"This transformer helps add explicit `@jest/globals` imports for Jest's global APIs, useful for projects moving away from implicit globals. It's run via `jscodeshift` directly, similar to other specific transformers.","wrong":"import { addJestGlobals } from 'jest-codemods'","symbol":"Jest Globals Import Transformer","correct":"jscodeshift -t node_modules/jest-codemods/dist/transformers/jest-globals-import.js <files...>"}],"quickstart":{"code":"npx jest-codemods my-project-root-folder --dry\nnpx jest-codemods my-project-root-folder\n","lang":"bash","description":"This demonstrates how to perform a dry run first to preview changes, and then execute the interactive codemods across your project's test files."},"warnings":[{"fix":"Run with `--dry` option first to preview changes. Always commit your code before running codemods and review diffs carefully after.","message":"Codemods are powerful but not foolproof. Always review the changes made by `jest-codemods` after execution, especially for complex transformations or edge cases, as manual tweaks may be required.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Ensure your changes are committed or stashed before running `jest-codemods` without `--dry`, or only use `--force` if you have a reliable backup strategy in place.","message":"Using the `--force` option bypasses Git safety checks, which can lead to unrecoverable data loss if your working tree is not clean or changes are not backed up. Exercise extreme caution.","severity":"breaking","affected_versions":">=0.1.0"},{"fix":"After other migrations, run `jscodeshift -t node_modules/jest-codemods/dist/transformers/jest-globals-import.js <files...>` to add explicit global imports. Ensure you are on `jest-codemods` version `0.32.0` or higher to use this transformer.","message":"Earlier versions (pre-0.32.0) did not include the `jest-globals-import` transformer, which automatically adds explicit `@jest/globals` imports. If migrating older code, ensure you run this specific transformer or handle global imports manually if needed.","severity":"gotcha","affected_versions":"<0.32.0"},{"fix":"Ensure your Node.js environment is updated to version 12 or newer before installing and running `jest-codemods`.","message":"The package requires Node.js version 12 or higher. Running with older Node.js versions may lead to unexpected errors or installation failures.","severity":"gotcha","affected_versions":"<=0.35.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure `npx` is available (comes with npm 5.2+). If not, install `jest-codemods` globally: `npm install -g jest-codemods` or locally within your project.","cause":"`npx` is not installed or the `jest-codemods` package is not found in your `node_modules`.","error":"command not found: jest-codemods"},{"fix":"Commit or stash your current changes before running the codemod. If you understand the risks and want to proceed, use the `--force` option: `npx jest-codemods <path> --force`.","cause":"jest-codemods detects uncommitted changes in your Git repository, preventing accidental data loss.","error":"Error: This transform is only safe to run on a clean Git working tree. You can override this safety check with --force."},{"fix":"Ensure your `jscodeshift` version is up-to-date. If the issue persists, you might need to manually fix the syntax in the problematic files or use a specific `jscodeshift` parser option if available and applicable.","cause":"jscodeshift (the underlying transformation engine) might not be able to parse your source code due to unsupported syntax features (e.g., very new JS/TS features not yet supported by its parser) or misconfigured parser options.","error":"SyntaxError: Unknown word (or similar jscodeshift parsing errors)"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"jest-codemods","cli_version":null}