feat(workflow): Add workflow plugin v1.0.0
Git workflow, code quality, context management and testing commands: - commit, push, pr, issue - git operations - simplify, refactor, verify, check - code quality - catchup, onboard, save, cleanup - context management - test, format, sync - development utilities Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
145
plugins/workflow/commands/test.md
Normal file
145
plugins/workflow/commands/test.md
Normal file
@@ -0,0 +1,145 @@
|
||||
---
|
||||
description: Smart test runner - runs tests for changed files only
|
||||
argument-hint: [pattern] - Optional test pattern or file to run
|
||||
---
|
||||
|
||||
# Smart Test Runner
|
||||
|
||||
## Pre-computed Context
|
||||
|
||||
**Test Framework Detection:**
|
||||
!`cat package.json 2>/dev/null | grep -E '"(jest|vitest|mocha|ava|tape)"' | head -3 || echo "No JS test framework"`
|
||||
|
||||
**Python Test Framework:**
|
||||
!`cat pyproject.toml setup.cfg 2>/dev/null | grep -E '(pytest|unittest|nose)' | head -3 || echo "No Python test framework"`
|
||||
|
||||
**Test Scripts:**
|
||||
!`cat package.json 2>/dev/null | grep -E '"test' | head -5 || echo "No test scripts"`
|
||||
|
||||
**Changed Files:**
|
||||
!`git diff --name-only HEAD~3 2>/dev/null | head -10`
|
||||
|
||||
**Related Test Files:**
|
||||
!`git diff --name-only HEAD~3 2>/dev/null | sed 's/\.\(ts\|tsx\|js\|jsx\)$/.test.\1/' | xargs -I{} sh -c 'test -f {} && echo {}' 2>/dev/null | head -5`
|
||||
|
||||
---
|
||||
|
||||
## Instructions
|
||||
|
||||
You are running tests intelligently - focusing on changed files when possible.
|
||||
|
||||
### Detect Test Framework
|
||||
|
||||
#### JavaScript/TypeScript
|
||||
|
||||
1. **Jest**
|
||||
```bash
|
||||
npx jest --passWithNoTests
|
||||
```
|
||||
|
||||
2. **Vitest**
|
||||
```bash
|
||||
npx vitest run
|
||||
```
|
||||
|
||||
3. **npm test script**
|
||||
```bash
|
||||
npm test
|
||||
```
|
||||
|
||||
#### Python
|
||||
|
||||
1. **pytest**
|
||||
```bash
|
||||
pytest -v
|
||||
```
|
||||
|
||||
2. **unittest**
|
||||
```bash
|
||||
python -m unittest discover
|
||||
```
|
||||
|
||||
### Smart Test Selection
|
||||
|
||||
If no argument provided, run tests related to changed files:
|
||||
|
||||
#### Jest - Run related tests
|
||||
```bash
|
||||
npx jest --findRelatedTests $(git diff --name-only HEAD~3 | tr '\n' ' ')
|
||||
```
|
||||
|
||||
#### Jest - Run changed test files only
|
||||
```bash
|
||||
npx jest --testPathPattern="$(git diff --name-only HEAD~3 | grep -E '\.test\.(ts|tsx|js|jsx)$' | tr '\n' '|' | sed 's/|$//')"
|
||||
```
|
||||
|
||||
#### Vitest - Run changed
|
||||
```bash
|
||||
npx vitest run --changed HEAD~3
|
||||
```
|
||||
|
||||
#### pytest - Run specific files
|
||||
```bash
|
||||
pytest $(git diff --name-only HEAD~3 | grep -E '_test\.py$|test_.*\.py$' | tr '\n' ' ')
|
||||
```
|
||||
|
||||
### With Pattern Argument
|
||||
|
||||
If argument provided, run tests matching that pattern:
|
||||
|
||||
```bash
|
||||
# Jest
|
||||
npx jest --testPathPattern="$ARGUMENTS"
|
||||
|
||||
# Vitest
|
||||
npx vitest run "$ARGUMENTS"
|
||||
|
||||
# pytest
|
||||
pytest -k "$ARGUMENTS"
|
||||
```
|
||||
|
||||
### Test Output
|
||||
|
||||
Show test results with appropriate verbosity:
|
||||
|
||||
```bash
|
||||
# Jest with coverage
|
||||
npx jest --coverage --passWithNoTests
|
||||
|
||||
# pytest verbose
|
||||
pytest -v --tb=short
|
||||
```
|
||||
|
||||
### On Failure
|
||||
|
||||
If tests fail:
|
||||
1. Show the failing test names
|
||||
2. Show the error messages
|
||||
3. Identify the source file that likely caused the failure
|
||||
4. Suggest fix or ask if you should investigate
|
||||
|
||||
---
|
||||
|
||||
## Common Options
|
||||
|
||||
**Run all tests:**
|
||||
```bash
|
||||
/workflow:test --all
|
||||
```
|
||||
|
||||
**Run with coverage:**
|
||||
```bash
|
||||
/workflow:test --coverage
|
||||
```
|
||||
|
||||
**Run in watch mode:**
|
||||
```bash
|
||||
npx jest --watch
|
||||
# or
|
||||
npx vitest
|
||||
```
|
||||
|
||||
**Run specific test file:**
|
||||
```bash
|
||||
/workflow:test src/utils.test.ts
|
||||
```
|
||||
Reference in New Issue
Block a user