Skip to main content
ClaudeWave
EN, English
Slash Command1.4k repo starsupdated 22d ago

run-tests

The run-tests command executes project tests using a tiered approach that first identifies and runs tests affected by recent code changes, then proceeds to the full unit test suite and integration tests if earlier phases pass. Use this command during development to quickly validate changes before committing, leveraging framework detection for Node.js, Python, Go, and Rust projects with detailed failure analysis and flaky test identification.

Install in Claude Code
Copy
mkdir -p ~/.claude/commands && curl -fsSL https://raw.githubusercontent.com/CloudAI-X/claude-workflow-v2/HEAD/commands/run-tests.md -o ~/.claude/commands/run-tests.md
Then start a new Claude Code session; the slash command loads automatically.

run-tests.md

# Run Tests

Run tests efficiently with tiered approach: affected tests first, then full suite.

## Phase 1: Detect Test Framework

Identify testing setup:

```bash
# Node.js
cat package.json | grep -E '"(jest|vitest|mocha|ava|tap)"'

# Python
ls pytest.ini pyproject.toml setup.cfg 2>/dev/null | head -1

# Go
ls *_test.go 2>/dev/null | head -1

# Rust
ls Cargo.toml 2>/dev/null
```

## Phase 2: Identify Affected Tests

Based on git diff, find related tests:

```bash
# Get changed files
git diff --name-only HEAD~1

# Find corresponding test files
# Convention: foo.ts -> foo.test.ts or foo.spec.ts
```

## Phase 3: Run Tests (Tiered Approach)

### Tier 1: Affected Tests Only (Fast)

```bash
# Node.js with Jest/Vitest
npm test -- --findRelatedTests [changed files]
npx vitest run --changed

# Python with pytest
pytest [specific test files] -x --tb=short

# Go
go test -run [TestName] ./...
```

### Tier 2: Full Unit Test Suite

If Tier 1 passes:

```bash
npm test
pytest tests/unit/
go test ./...
cargo test
```

### Tier 3: Integration Tests

If Tier 2 passes:

```bash
npm run test:integration
pytest tests/integration/
go test -tags=integration ./...
```

## Phase 4: Analyze Failures

For each failure:

1. Parse error message
2. Identify failing assertion
3. Trace to source code
4. Suggest fix

## Output Format

```
## Test Results: [PASS/FAIL]

### Summary
- Total: X tests
- Passed: Y
- Failed: Z
- Skipped: W
- Duration: [time]

### Failed Tests
1. **test_name** - `file:line`
   - Expected: [value]
   - Actual: [value]
   - Likely cause: [analysis]
   - Suggested fix: [fix]

### Flaky Test Detection
- [Any tests that passed on retry]

### Coverage (if available)
- Lines: X%
- Branches: Y%
- Functions: Z%

### Recommendation
[SAFE TO COMMIT / FIX REQUIRED / INVESTIGATE FLAKY]
```

## Continue Until Green

If tests fail:

1. Report the failure clearly
2. Attempt to fix the failing code (not just the test)
3. Re-run tests
4. Repeat until green or max 3 attempts

## Usage

This command ships with the project-starter plugin. Invoke with: `/project-starter:run-tests`