Code transformation toolkit for the Suites testing framework
Automated code transformations for Suites projects. Built on jscodeshift with intelligent AST-based transformations, built-in validation, and TypeScript-first support.
npx @suites/codemod <transform> <path> [options]Example:
npx @suites/codemod automock/2/to-suites-v3 src/**/*.spec.tsRun with --dry-run to preview changes without modifying files.
automock/2/to-suites-v3- Migrate test files from Automock v2 to Suites v3 testing framework
import { TestBed } from '@automock/jest';
describe('UserService', () => {
let service: UserService;
beforeAll(() => {
const { unit } = TestBed.create(UserService)
.mock(UserRepository)
.using({ findById: jest.fn() })
.compile();
service = unit;
});
});import { TestBed } from '@suites/unit';
describe('UserService', () => {
let service: UserService;
beforeAll(async () => {
const { unit } = await TestBed.solitary(UserService)
.mock(UserRepository)
.final({ findById: jest.fn() })
.compile();
service = unit;
});
});| Option | Description | Default |
|---|---|---|
-d, --dry-run |
Preview changes without writing files | false |
-f, --force |
Bypass git safety checks | false |
-p, --parser <parser> |
Parser: tsx, ts, babel |
tsx |
-e, --extensions <exts> |
File extensions to transform | .ts,.tsx |
-i, --ignore <patterns> |
Ignore file patterns (comma-separated) | - |
--print |
Print output to stdout | false |
-v, --verbose |
Show detailed logs | false |
--skip-validation |
Skip validation checks | false |
--list-transforms |
List all available transforms | - |
More examples:
# Preview changes
npx @suites/codemod automock/2/to-suites-v3 src --dry-run
# Ignore certain files
npx @suites/codemod automock/2/to-suites-v3 src --ignore "**/*.integration.ts"
# List all transforms
npx @suites/codemod --list-transformsIntelligently migrates Automock v2 test files to Suites v3 framework.
What it transforms:
- Import statements:
@automock/jest->@suites/unit - TestBed API:
TestBed.create()->TestBed.solitary().compile() - Mock configuration:
.using()->.impl()or.final() - Type annotations:
jest.Mocked<T>->Mocked<T>from@suites/unit - Async/await: Adds
async/awaitto test hooks as needed - Mock retrieval: Intelligently selects
.impl()vs.final()strategy - Jest globals: Preserves
jestimports where needed - Type casts: Removes obsolete type assertions
Mock Strategy Selection:
The codemod automatically chooses between .impl() and .final():
.impl()- Used when mocks are retrieved viaunitRef.get()and need runtime manipulation (spy assertions, dynamic mock configuration).final()- Used when mocks are provided as final implementations without retrieval
Validation:
Built-in validation ensures:
- No
@automockimports remain TestBed.create()is converted toTestBed.solitary().compile()is called with properawait- Mock strategies are correctly applied
- Retrieved mocks use
.impl()strategy
- Node.js:
^16.10.0 || ^18.12.0 || >=20.0.0 - Project Type: TypeScript or JavaScript
- Git: Clean working directory recommended (bypass with
--force)
"Working directory is not clean"
- Commit your changes or use
--forceto bypass
"No files found"
- Check your path and file extensions:
--extensions .spec.ts,.test.ts
Parser errors
- Try the babel parser:
--parser babel
Validation failed
- Run with
--verbosefor detailed logs - Review validation errors in the output
- Use
--skip-validationto bypass (not recommended)
For more help, see troubleshooting guide or open an issue.
The codemod uses jscodeshift to:
- Parse TypeScript/JavaScript into an Abstract Syntax Tree (AST)
- Apply intelligent transformations (imports, TestBed API, mocks, types)
- Validate the transformed code
- Output the result
TypeScript Support: First-class support with fallback parser for complex syntax (generics, type guards, decorators, JSX/TSX).
This codemod follows the Codemod Registry pattern used by React, Next.js, and other major frameworks:
Transform Naming: <framework>/<version>/<transform>
automock/2/to-suites-v3- Current migrationautomock/3/to-suites-v4- Future migrations- Supports multiple transforms per version
- Extensible to other frameworks (e.g.,
jest/28/to-v29)
Directory Structure:
src/transforms/
automock/ # Framework namespace
2/ # Source version
to-suites-v3.ts # Migration transform
3/ # Future: next version
to-suites-v4.ts
Design Benefits:
- No default transform - explicit selection prevents mistakes
- Version-based organization supports migration chains
- Framework namespacing allows multi-framework support
- Clear source → target versioning
Contributions welcome! To contribute:
- Fork the repository
- Create a feature branch:
git checkout -b feature/my-feature - Make your changes and add tests
- Run tests:
npm testand linter:npm run lint - Commit:
git commit -m "feat: add feature" - Push and open a Pull Request
- Create transform directory:
src/transforms/<framework>/<version>/<transform-name>.ts - Export
applyTransformfunction from your transform - Register in
src/transforms/index.ts:{ name: 'framework/version/transform-name', description: 'Description of what it does', path: './transforms/framework/version/transform-name', }
- Add test fixtures in
fixtures/ - Add integration tests in
test/integration/ - Update this README
Example:
// src/transforms/automock/3/to-suites-v4.ts
export { applyTransform } from '../../../transform';src/
analyzers/ # Code analysis utilities
transforms/ # Transform implementations
automock/ # Framework namespace
2/ # Version-specific transforms
to-suites-v3.ts
index.ts # Transform registry
validators/ # Post-transform validation
utils/ # Shared utilities
cli.ts # CLI interface
runner.ts # Transform runner
transform.ts # Main transform logic
test/
integration/ # Integration tests
transforms/ # Transform unit tests
fixtures/ # Test fixtures (before/after)
From within the codemod repository:
# Build first
pnpm build
# Run on a target repository
node dist/cli.js automock/2/to-suites-v3 /path/to/repo --dry-run
# Run on test fixtures
node dist/cli.js automock/2/to-suites-v3 fixtures/simple-final --dry-run
# Verbose output for debugging
node dist/cli.js automock/2/to-suites-v3 /path/to/repo --dry-run --verbose# In the codemod repo
npm link
# Now use it anywhere like npx
codemod automock/2/to-suites-v3 /path/to/repo --dry-run
# Unlink when done
npm unlink -g @suites/codemod# All tests
pnpm test
# Specific test file
pnpm test path/to/test.spec.ts
# With coverage
pnpm test --coverageMIT (c) Omer Morad
- @suites/unit - The Suites testing framework
- jscodeshift - JavaScript codemod toolkit
- @automock/jest - Automock testing framework
Need help? Open an issue on GitHub or check the Suites documentation.