Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,19 @@ jobs:
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

test-codemods:
runs-on: ubuntu-latest
name: Test
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Setup Node.js and deps
uses: ./.github/actions/setup-deps

- name: Test
run: yarn test:codemods

test-rn-0-83-1:
runs-on: ubuntu-latest
name: Test RN 0.83.1
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules/
.yarn
codemods/**/tests/fixtures/**
2 changes: 1 addition & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ npmPreapprovedPackages:
- react
- react-native
- universal-test-renderer
- '@testing-library/react-native'
- '@react-native/*'
- '@types/react'
- '@types/universal-test-renderer'
- hermes-compiler

yarnPath: .yarn/releases/yarn-4.11.0.cjs
6 changes: 6 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ This document provides context for the any code assistant to understand the `@te
- **Tech Stack:** TypeScript, React Native, Jest.
- **Architecture:** The library simulates the React Native runtime on top of `universal-test-renderer`.

## Project Guidelines

- Small API surface
- Expose all features of the underlying platform (react, react-reconciler) for Testing Libraries to use
- Render host elements only, yet provide escape hatches to fibers when needed

## Building and Running

The project uses `yarn` for dependency management and script execution.
Expand Down
33 changes: 33 additions & 0 deletions codemods/v14-async-functions/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Dependencies
node_modules/
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Build artifacts
target/
dist/
build/

# Temporary files
*.tmp
*.temp
.cache/

# Environment files
.env
.env.local

# IDE files
.vscode/
.idea/
*.swp
*.swo

# OS files
.DS_Store
Thumbs.db

# Package bundles
*.tar.gz
*.tgz
58 changes: 58 additions & 0 deletions codemods/v14-async-functions/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# RNTL v14: Make render(), act(), renderHook(), and fireEvent() calls async

This codemod migrates your test files from React Native Testing Library v13 to v14 by automatically transforming synchronous function calls to async versions and making test functions async when needed.

## What it does

- Transforms `render()`, `act()`, `renderHook()`, and `fireEvent()` calls to `await render()`, `await act()`, etc.
- Makes test functions (`test()`, `it()`, hooks) async when needed
- Handles `fireEvent.press()`, `fireEvent.changeText()`, `fireEvent.scroll()`, `screen.rerender()`, `screen.unmount()`, and renderer methods
- Only transforms calls imported from `@testing-library/react-native`

## Usage

```bash
# Run the codemod
npx codemod@latest run rntl-v14-async-functions --target ./path/to/your/tests
```

### Custom render functions

If you have custom render helper functions (like `renderWithProviders`, `renderWithTheme`), specify them so they get transformed too:

```bash
npx codemod@latest run rntl-v14-async-functions --target ./path/to/your/tests --param customRenderFunctions="renderWithProviders,renderWithTheme"
```

## Example

**Before:**

```typescript
test('renders component', () => {
render(<MyComponent />);
expect(screen.getByText('Hello')).toBeOnTheScreen();
});
```

**After:**

```typescript
test('renders component', async () => {
await render(<MyComponent />);
expect(screen.getByText('Hello')).toBeOnTheScreen();
});
```

## Limitations

- Helper functions are not transformed by default (use `customRenderFunctions` param if needed)
- Namespace imports (`import * as RNTL`) are not handled

## Next steps

1. Run the codemod on your test files
2. Review the changes
3. Manually update any remaining helper functions if needed
4. Update your RNTL version to v14 (`rntl-v14-update-deps` codemod)
5. Run your tests to verify everything works
19 changes: 19 additions & 0 deletions codemods/v14-async-functions/codemod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
schema_version: '1.0'

name: 'rntl-v14-async-functions'
version: '0.1.0'
description: 'Codemod to migrate sync RNTL function and method calls to async for RNTL v14'
author: 'Maciej Jastrzebski'
license: 'MIT'
workflow: 'workflow.yaml'

targets:
languages: ['typescript', 'tsx', 'javascript', 'jsx']

keywords: ['transformation', 'migration']

registry:
access: 'public'
visibility: 'public'

capabilities: []
14 changes: 14 additions & 0 deletions codemods/v14-async-functions/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "@testing-library/react-native-v14-async-functions",
"version": "0.1.0",
"description": "Codemod to migrate render() calls to await render() for RNTL v14",
"type": "module",
"scripts": {
"test": "yarn dlx codemod@latest jssg test -l tsx ./scripts/codemod.ts",
"check-types": "tsc --noEmit"
},
"devDependencies": {
"@codemod.com/jssg-types": "^1.3.0",
"typescript": "^5.8.3"
}
}
Loading