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.
npm install jest-codemodsVerified import paths — ran on the pinned version, not inferred.
This demonstrates how to perform a dry run first to preview changes, and then execute the interactive codemods across your project's test files.
Run with `--dry` option first to preview changes. Always commit your code before running codemods and review diffs carefully after.
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.
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.
Ensure your Node.js environment is updated to version 12 or newer before installing and running `jest-codemods`.
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.
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`.
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.