https://github.com/phmatray/autotestid
https://github.com/phmatray/autotestid
Last synced: 6 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/phmatray/autotestid
- Owner: phmatray
- Created: 2025-06-13T12:18:29.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2025-06-13T12:20:20.000Z (7 months ago)
- Last Synced: 2025-06-13T13:29:57.003Z (7 months ago)
- Language: C#
- Size: 20.5 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# AutoTestId
A .NET tool for automatically adding `data-testid` attributes to Razor components for improved testability.
## Features
- **Automatic test-id injection**: Adds `data-testid` attributes to root-level HTML elements in Razor files
- **Multiple processing modes**: Process single files, folders, projects, or entire solutions
- **Smart detection**: Only processes files that need updates
- **Preserve formatting**: Maintains your existing code formatting and indentation
- **Replace existing**: Updates existing `data-testid` attributes if present
- **Dry-run mode**: Preview changes before applying them
- **Beautiful CLI**: User-friendly command-line interface with progress reporting
## Installation
```bash
dotnet tool install -g AutoTestId
```
Or build from source:
```bash
git clone https://github.com/yourusername/AutoTestId.git
cd AutoTestId
dotnet build
```
## Usage
### Process a Single File
```bash
autotestid file Component.razor
# With custom test-id
autotestid file Component.razor --test-id "MyCustomId"
# Preview changes without modifying
autotestid file Component.razor --dry-run
```
### Process a Folder
```bash
autotestid folder ./src
# Process recursively (default)
autotestid folder ./src --recursive
# Exclude specific directories
autotestid folder ./src --exclude bin --exclude obj
# Custom file pattern
autotestid folder ./src --pattern "*.razor"
```
### Process a Project
```bash
autotestid project MyApp.csproj
# Preview changes
autotestid project MyApp.csproj --dry-run
# Exclude directories
autotestid project MyApp.csproj --exclude wwwroot
```
### Process a Solution
```bash
autotestid solution MyApp.sln
# Exclude specific projects
autotestid solution MyApp.sln --exclude-project "Tests"
# Include test projects (excluded by default)
autotestid solution MyApp.sln --include-tests
# Process only specific projects
autotestid solution MyApp.sln --include-project "MyApp.Web" --include-project "MyApp.Components"
```
## How It Works
AutoTestId processes Razor files and adds `data-testid` attributes to all root-level HTML elements:
**Before:**
```razor
@Title
@Description
@Copyright
```
**After:**
```razor
@Title
@Description
@Copyright
```
The test-id value is derived from the component filename (without extension) by default.
## Command Reference
### Global Options
- `-h, --help` - Show help information
- `-v, --version` - Show version information
### File Command
Process a single Razor file.
**Arguments:**
- `` - Path to the Razor file to process
**Options:**
- `-t, --test-id ` - Custom test ID value to use (defaults to filename)
- `-d, --dry-run` - Preview changes without modifying files
### Folder Command
Process all Razor files in a folder.
**Arguments:**
- `` - Path to the folder containing Razor files
**Options:**
- `-r, --recursive` - Process subdirectories recursively (default: true)
- `-p, --pattern ` - File pattern to match (default: *.razor)
- `-d, --dry-run` - Preview changes without modifying files
- `-e, --exclude ` - Directories to exclude (can be specified multiple times)
### Project Command
Process all Razor files in a .csproj project.
**Arguments:**
- `` - Path to the .csproj file
**Options:**
- `-d, --dry-run` - Preview changes without modifying files
- `-l, --include-linked` - Include linked files in processing
- `-e, --exclude ` - Directories to exclude (can be specified multiple times)
### Solution Command
Process all Razor files in a .sln solution.
**Arguments:**
- `` - Path to the .sln file
**Options:**
- `-d, --dry-run` - Preview changes without modifying files
- `-i, --include-project ` - Specific projects to include (can be specified multiple times)
- `-e, --exclude-project ` - Projects to exclude (can be specified multiple times)
- `-t, --include-tests` - Include test projects in processing
## Development
### Running Tests
```bash
dotnet test
```
### Building
```bash
dotnet build
```
### Running Locally
```bash
dotnet run -- file MyComponent.razor
```
## License
MIT License - see LICENSE file for details.