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
61 changes: 61 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Test & Coverage

on:
push:
branches:
- master

permissions:
contents: read
id-token: write
checks: write

jobs:
test:
name: Test & Upload Coverage
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'

- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 8.15.9

- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV

- name: Setup pnpm cache
uses: actions/cache@v4
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Run tests with coverage
run: pnpm test

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage/lcov.info
flags: unittests
name: codecov-codemod
fail_ci_if_error: true
verbose: true
111 changes: 111 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
name: Publish Package

on:
workflow_dispatch:
inputs:
tag:
description: 'Distribution tag'
required: true
type: choice
options:
- latest
- next
- rc
- dev
- alpha
- beta
branch:
description: 'Target branch'
required: true
type: choice
options:
- master
- next

permissions:
contents: write
id-token: write

jobs:
publish:
name: Publish to NPM
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ inputs.branch }}
fetch-depth: 0

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
registry-url: 'https://registry.npmjs.org'

- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 8.15.9

- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV

- name: Setup pnpm cache
uses: actions/cache@v4
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Build
run: pnpm run build

- name: Run tests
run: pnpm test

- name: Run lint
run: pnpm run lint

- name: Publish to NPM
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_CONFIG_PROVENANCE: true
run: |
echo "//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}" > .npmrc
npm publish --tag ${{ inputs.tag }} --provenance --access public

- name: Create Summary
if: success()
run: |
echo "## ✅ Publication Successful" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Package published to npm with tag: **${{ inputs.tag }}**" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Installation" >> $GITHUB_STEP_SUMMARY
echo '```bash' >> $GITHUB_STEP_SUMMARY
if [ "${{ inputs.tag }}" = "latest" ]; then
echo "npm install @suites/codemod" >> $GITHUB_STEP_SUMMARY
else
echo "npm install @suites/codemod@${{ inputs.tag }}" >> $GITHUB_STEP_SUMMARY
fi
echo '```' >> $GITHUB_STEP_SUMMARY

- name: Create Failure Summary
if: failure()
run: |
echo "## ❌ Publication Failed" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "The package could not be published. Check the logs above for details." >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Common Issues" >> $GITHUB_STEP_SUMMARY
echo "- Ensure NPM_TOKEN secret is configured correctly" >> $GITHUB_STEP_SUMMARY
echo "- Check if the version already exists on npm" >> $GITHUB_STEP_SUMMARY
echo "- Verify build and tests pass successfully" >> $GITHUB_STEP_SUMMARY
2 changes: 1 addition & 1 deletion .releaserc.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"@semantic-release/git",
{
"assets": ["CHANGELOG.md", "package.json"],
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
"message": "chore(release): ${nextRelease.version}\n\n${nextRelease.notes}"
}
],
"@semantic-release/github"
Expand Down
114 changes: 102 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ Automated code transformations for Suites projects. Built on [jscodeshift](https
## Usage

```bash
npx @suites/codemod <path> [options]
npx @suites/codemod <transform> <path> [options]
```

**Example:**
```bash
npx @suites/codemod src/**/*.spec.ts
npx @suites/codemod automock/2/to-suites-v3 src/**/*.spec.ts
```

Run with `--dry-run` to preview changes without modifying files.

## Available Transforms

- **`automock-to-suites`** (default) - Migrate test files from Automock to Suites testing framework
- **`automock/2/to-suites-v3`** - Migrate test files from Automock v2 to Suites v3 testing framework

## Example

Expand Down Expand Up @@ -79,20 +79,20 @@ describe('UserService', () => {
**More examples:**
```bash
# Preview changes
npx @suites/codemod src --dry-run
npx @suites/codemod automock/2/to-suites-v3 src --dry-run

# Ignore certain files
npx @suites/codemod src --ignore "**/*.integration.ts"
npx @suites/codemod automock/2/to-suites-v3 src --ignore "**/*.integration.ts"

# List all transforms
npx @suites/codemod --list-transforms
```

## Transform Details

### `automock-to-suites`
### `automock/2/to-suites-v3`

Intelligently migrates Automock test files to Suites framework.
Intelligently migrates Automock v2 test files to Suites v3 framework.

**What it transforms:**
- Import statements: `@automock/jest` -> `@suites/unit`
Expand Down Expand Up @@ -154,6 +154,32 @@ The codemod uses [jscodeshift](https://github.com/facebook/jscodeshift) to:

**TypeScript Support:** First-class support with fallback parser for complex syntax (generics, type guards, decorators, JSX/TSX).

## Architecture

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 migration
- `automock/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

## Contributing

Contributions welcome! To contribute:
Expand All @@ -167,18 +193,36 @@ Contributions welcome! To contribute:

### Adding New Transforms

1. Create transform file in `src/transforms/`
2. Register in `src/transforms/index.ts`
3. Add test fixtures in `fixtures/`
4. Add integration tests in `test/integration/`
5. Update this README
1. Create transform directory: `src/transforms/<framework>/<version>/<transform-name>.ts`
2. Export `applyTransform` function from your transform
3. Register in `src/transforms/index.ts`:
```typescript
{
name: 'framework/version/transform-name',
description: 'Description of what it does',
path: './transforms/framework/version/transform-name',
}
```
4. Add test fixtures in `fixtures/`
5. Add integration tests in `test/integration/`
6. Update this README

**Example:**
```typescript
// src/transforms/automock/3/to-suites-v4.ts
export { applyTransform } from '../../../transform';
```

### Project Structure

```
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
Expand All @@ -191,6 +235,52 @@ test/
fixtures/ # Test fixtures (before/after)
```

## Local Development

### Running Locally

From within the codemod repository:

```bash
# 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
```

### Using npm link for Testing

```bash
# 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
```

### Running Tests

```bash
# All tests
pnpm test

# Specific test file
pnpm test path/to/test.spec.ts

# With coverage
pnpm test --coverage
```

## License

MIT (c) [Omer Morad](https://github.com/omermorad)
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@
"typescript"
],
"publishConfig": {
"registry": "http://localhost:4873",
"access": "public"
"access": "public",
"provenance": true
},
"packageManager": "pnpm@8.15.9"
}
Loading