Mmdjastrzebski

rntl-v14-update-deps

Codemod to update dependencies for RNTL v14 migration

transformationmigrationdependencies
Public
0 executions
0 stars
How to Use
Run this codemod on your codebase using one of the following commands

The easiest way to run this codemod without installing anything globally:

Documentation

RNTL v14: Update Dependencies

This codemod updates your package.json file to prepare for React Native Testing Library v14 migration by:

  • ✅ Removing @types/react-test-renderer (no longer needed)
  • ✅ Removing react-test-renderer (replaced by universal-test-renderer)
  • ✅ Moving @testing-library/react-native from dependencies to devDependencies if present
  • ✅ Adding @testing-library/react-native@^14.0.0-alpha.5 to devDependencies if not present
  • ✅ Updating @testing-library/react-native to ^14.0.0-alpha.5
  • ✅ Adding universal-test-renderer@0.10.1 to devDependencies (always added)

What it does

This codemod automatically updates your package.json dependencies to match the requirements for RNTL v14. It:

  1. Removes deprecated packages: @types/react-test-renderer and react-test-renderer are removed from all dependency types (dependencies, devDependencies, peerDependencies, optionalDependencies)

  2. Moves RNTL to devDependencies: If @testing-library/react-native is in dependencies, it's moved to devDependencies

  3. Ensures RNTL is present: If @testing-library/react-native is not present, it's added to devDependencies with version ^14.0.0-alpha.5

  4. Updates RNTL version: Updates @testing-library/react-native to ^14.0.0-alpha.5

  5. Adds universal-test-renderer: Always adds universal-test-renderer@0.10.1 to devDependencies

Usage

Running the codemod

bash

Example transformations

Before:

json

After:

json

Moving from dependencies to devDependencies:

Before:

json

After:

json

Adding if not present:

Before:

json

After:

json

Important Notes

  1. After running the codemod, you'll need to run your package manager to install the new dependencies:

    bash
  2. Version resolution: The codemod sets @testing-library/react-native to ^14.0.0-alpha.5. You can manually update this to a different version if needed.

  3. Always adds packages: The codemod always ensures both @testing-library/react-native and universal-test-renderer are present in devDependencies, even if they weren't there before.

Testing

Run the test suite:

bash

Limitations

  1. Package manager: The codemod updates package.json but doesn't run the package manager install command. You need to run npm install / yarn install / pnpm install manually after the codemod completes.

  2. Version pinning: If you have a specific alpha version pinned, the codemod will update it to ^14.0.0-alpha.5. You may want to review and adjust the version after running the codemod.

  3. Workspace projects: For monorepos with multiple package.json files, the codemod will process each one individually.

Migration Guide

  1. Run this codemod to update your dependencies
  2. Run your package manager to install the new dependencies:
    bash
  3. Run the render-async codemod to update your test code:
    bash
  4. Review and test your changes
  5. Update your RNTL version to a specific alpha version if needed

Contributing

If you find issues or have suggestions for improvements, please open an issue or submit a pull request to the React Native Testing Library repository.

Ready to contribute?

Build your own codemod and share it with the community.