{"id":33902601,"url":"https://github.com/suites-dev/codemod","last_synced_at":"2026-03-10T07:01:32.333Z","repository":{"id":327179106,"uuid":"1108169469","full_name":"suites-dev/codemod","owner":"suites-dev","description":"Suites codemod scripts","archived":false,"fork":false,"pushed_at":"2025-12-03T23:38:25.000Z","size":197,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-12-05T01:02:43.619Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://suites.dev/docs/migration-guides","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/suites-dev.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-12-02T05:43:06.000Z","updated_at":"2025-12-02T22:38:04.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/suites-dev/codemod","commit_stats":null,"previous_names":["suites-dev/codemod"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/suites-dev/codemod","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/suites-dev%2Fcodemod","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/suites-dev%2Fcodemod/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/suites-dev%2Fcodemod/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/suites-dev%2Fcodemod/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/suites-dev","download_url":"https://codeload.github.com/suites-dev/codemod/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/suites-dev%2Fcodemod/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30326893,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-10T05:25:20.737Z","status":"ssl_error","status_checked_at":"2026-03-10T05:25:17.430Z","response_time":106,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-12-12T00:45:27.545Z","updated_at":"2026-03-10T07:01:32.187Z","avatar_url":"https://github.com/suites-dev.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @suites/codemod\n\n[![npm version](https://img.shields.io/npm/v/@suites/codemod.svg)](https://www.npmjs.com/package/@suites/codemod)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n\u003e Code transformation toolkit for the Suites testing framework\n\nAutomated code transformations for Suites projects. Built on [jscodeshift](https://github.com/facebook/jscodeshift) with intelligent AST-based transformations, built-in validation, and TypeScript-first support.\n\n## Usage\n\n```bash\nnpx @suites/codemod \u003ccodemod\u003e \u003csource\u003e [options]\n```\n\n**Example:**\n```bash\nnpx @suites/codemod automock/2/to-suites-v3 src/**/*.spec.ts\n```\n\nRun with `--dry` or `-d` to preview changes without modifying files.\n\n## Available Codemods\n\n- **`automock/2/to-suites-v3`** - Migrate test files from Automock v2 to Suites v3 testing framework\n\n## Example\n\n### Before (Automock)\n\n```typescript\nimport { TestBed } from '@automock/jest';\n\ndescribe('UserService', () =\u003e {\n  let service: UserService;\n\n  beforeAll(() =\u003e {\n    const { unit } = TestBed.create(UserService)\n      .mock(UserRepository)\n      .using({ findById: jest.fn() })\n      .compile();\n    service = unit;\n  });\n});\n```\n\n### After (Suites)\n\n```typescript\nimport { TestBed } from '@suites/unit';\n\ndescribe('UserService', () =\u003e {\n  let service: UserService;\n\n  beforeAll(async () =\u003e {\n    const { unit } = await TestBed.solitary(UserService)\n      .mock(UserRepository)\n      .final({ findById: jest.fn() })\n      .compile();\n    service = unit;\n  });\n});\n```\n\n## CLI Reference\n\n### Arguments\n\n| Argument | Description | Default |\n|----------|-------------|---------|\n| `codemod` | Codemod slug to run. See available transforms below. | - |\n| `source` | Path to source files or directory to transform including glob patterns. | `.` |\n\n### Options\n\n| Option | Description | Default |\n|--------|-------------|---------|\n| `-v, --version` | Output the current version | - |\n| `-d, --dry` | Dry run (no changes are made to files) | `false` |\n| `-f, --force` | Bypass Git safety checks and forcibly run codemods | `false` |\n| `-p, --print` | Print transformed files to stdout, useful for development | `false` |\n| `--verbose` | Show more information about the transform process | `false` |\n| `--parser \u003cparser\u003e` | Parser to use: `tsx`, `ts`, `babel` | `tsx` |\n| `-h, --help` | Display help message | - |\n\n**Examples:**\n```bash\n# Preview changes (dry run)\nnpx @suites/codemod automock/2/to-suites-v3 src --dry\n\n# Print output to stdout\nnpx @suites/codemod automock/2/to-suites-v3 src/file.ts -p\n\n# Verbose output\nnpx @suites/codemod automock/2/to-suites-v3 src --verbose\n\n# Use different parser\nnpx @suites/codemod automock/2/to-suites-v3 src --parser babel\n```\n\n## Transform Details\n\n### `automock/2/to-suites-v3`\n\nIntelligently migrates Automock v2 test files to Suites v3 framework.\n\n**What it transforms:**\n- Import statements: `@automock/jest` -\u003e `@suites/unit`\n- TestBed API: `TestBed.create()` -\u003e `TestBed.solitary().compile()`\n- Mock configuration: `.using()` -\u003e `.impl()` or `.final()`\n- Type annotations: `jest.Mocked\u003cT\u003e` -\u003e `Mocked\u003cT\u003e` from `@suites/unit`\n- Async/await: Adds `async`/`await` to test hooks as needed\n- Mock retrieval: Intelligently selects `.impl()` vs `.final()` strategy\n- Jest globals: Preserves `jest` imports where needed\n- Type casts: Removes obsolete type assertions\n\n**Mock Strategy Selection:**\n\nThe codemod automatically chooses between `.impl()` and `.final()`:\n\n- **`.impl()`** - Used when mocks are retrieved via `unitRef.get()` and need runtime manipulation (spy assertions, dynamic mock configuration)\n- **`.final()`** - Used when mocks are provided as final implementations without retrieval\n\n**Validation:**\n\nBuilt-in validation ensures:\n- No `@automock` imports remain\n- `TestBed.create()` is converted to `TestBed.solitary()`\n- `.compile()` is called with proper `await`\n- Mock strategies are correctly applied\n- Retrieved mocks use `.impl()` strategy\n\n## Requirements\n\n- **Node.js**: `^16.10.0 || ^18.12.0 || \u003e=20.0.0`\n- **Project Type**: TypeScript or JavaScript\n- **Git**: Clean working directory recommended (bypass with `--force`)\n\n## Troubleshooting\n\n**\"Working directory is not clean\"**\n- Commit your changes or use `--force` to bypass\n\n**\"No files found\"**\n- Check your source path and ensure it contains `.ts` or `.tsx` files\n\n**Parser errors**\n- Try the babel parser: `--parser babel`\n\n**Validation failed**\n- Run with `--verbose` for detailed logs\n- Review validation errors in the output\n- Fix the issues reported by validators\n\nFor more help, see [troubleshooting guide](https://github.com/suites-dev/codemod/issues) or open an issue.\n\n## How It Works\n\nThe codemod uses [jscodeshift](https://github.com/facebook/jscodeshift) to:\n1. Parse TypeScript/JavaScript into an Abstract Syntax Tree (AST)\n2. Apply intelligent transformations (imports, TestBed API, mocks, types)\n3. Validate the transformed code\n4. Output the result\n\n**TypeScript Support:** First-class support with fallback parser for complex syntax (generics, type guards, decorators, JSX/TSX).\n\n## Architecture\n\nThis codemod follows the **Codemod Registry** pattern used by React, Next.js, and other major frameworks:\n\n**Transform Naming:** `\u003cframework\u003e/\u003cversion\u003e/\u003ctransform\u003e`\n- `automock/2/to-suites-v3` - Current migration\n- `automock/3/to-suites-v4` - Future migrations\n- Supports multiple transforms per version\n- Extensible to other frameworks (e.g., `jest/28/to-v29`)\n\n**Directory Structure:**\n```\nsrc/transforms/\n  automock/              # Framework namespace\n    2/                   # Source version\n      to-suites-v3.ts    # Migration transform\n    3/                   # Future: next version\n      to-suites-v4.ts\n```\n\n**Design Benefits:**\n- No default transform - explicit selection prevents mistakes\n- Version-based organization supports migration chains\n- Framework namespacing allows multi-framework support\n- Clear source → target versioning\n\n## Contributing\n\nContributions welcome! To contribute:\n\n1. Fork the repository\n2. Create a feature branch: `git checkout -b feature/my-feature`\n3. Make your changes and add tests\n4. Run tests: `npm test` and linter: `npm run lint`\n5. Commit: `git commit -m \"feat: add feature\"`\n6. Push and open a Pull Request\n\n### Adding New Transforms\n\n1. Create transform directory: `src/transforms/\u003cframework\u003e/\u003cversion\u003e/\u003ctransform-name\u003e.ts`\n2. Export `applyTransform` function from your transform\n3. Register in `src/transforms/index.ts`:\n   ```typescript\n   {\n     name: 'framework/version/transform-name',\n     description: 'Description of what it does',\n     path: './transforms/framework/version/transform-name',\n   }\n   ```\n4. Add test fixtures in `fixtures/`\n5. Add integration tests in `test/integration/`\n6. Update this README\n\n**Example:**\n```typescript\n// src/transforms/automock/3/to-suites-v4.ts\nexport { applyTransform } from '../../../transform';\n```\n\n### Project Structure\n\n```\nsrc/\n  analyzers/        # Code analysis utilities\n  transforms/       # Transform implementations\n    automock/       # Framework namespace\n      2/            # Version-specific transforms\n        to-suites-v3.ts\n    index.ts        # Transform registry\n  validators/       # Post-transform validation\n  utils/            # Shared utilities\n  cli.ts            # CLI interface\n  runner.ts         # Transform runner\n  transform.ts      # Main transform logic\n\ntest/\n  integration/      # Integration tests\n  transforms/       # Transform unit tests\n  fixtures/         # Test fixtures (before/after)\n```\n\n## License\n\nMIT (c) [Omer Morad](https://github.com/omermorad)\n\n## Links\n\n- [Suites Documentation](https://suites.dev)\n- [GitHub Repository](https://github.com/suites-dev/codemod)\n- [Issue Tracker](https://github.com/suites-dev/codemod/issues)\n- [NPM Package](https://www.npmjs.com/package/@suites/codemod)\n\n## Related Projects\n\n- [@suites/unit](https://github.com/suites-dev/suites) - The Suites testing framework\n- [jscodeshift](https://github.com/facebook/jscodeshift) - JavaScript codemod toolkit\n- [@automock/jest](https://github.com/automock/automock) - Automock testing framework\n\n---\n\n**Need help?** Open an issue on [GitHub](https://github.com/suites-dev/codemod/issues) or check the [Suites documentation](https://suites.dev).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsuites-dev%2Fcodemod","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsuites-dev%2Fcodemod","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsuites-dev%2Fcodemod/lists"}