Legion CLI includes an intelligent test runner that auto-detects frameworks and provides structured test results.
| Framework | Detection Pattern | Command |
|---|---|---|
| Vitest | vitest.config.* |
npx vitest run |
| Jest | jest.config.* |
npx jest |
| Pytest | pytest.ini, setup.cfg, pyproject.toml |
pytest |
| Go Test | go.mod |
go test ./... |
| Cargo Test | Cargo.toml |
cargo test |
| Maven | pom.xml |
mvn test |
| Gradle | build.gradle* |
gradle test |
# Run tests in current directory
legion run "run tests"
# Run specific test file
legion run "run tests in src/utils.test.ts"
# Run tests matching pattern
legion run "run tests matching 'auth'"
The test runner tool can be called directly:
// The tool auto-detects the framework and runs tests
const result = yield* TestRunnerTool.execute({
// No parameters needed - auto-detects everything
})
{
"title": "Tests completed",
"metadata": {
"framework": "vitest",
"totalTests": 42,
"passed": 40,
"failed": 2,
"skipped": 0,
"duration": "3.2s"
},
"output": "Test Results: 40 passed, 2 failed, 0 skipped (3.2s)\n\nFailed Tests:\n src/auth.test.ts:45 - should validate token\n src/auth.test.ts:67 - should handle refresh"
}
The test runner searches for framework config files:
Current Directory
├── vitest.config.ts → Vitest
├── jest.config.js → Jest
├── pytest.ini → Pytest
├── go.mod → Go Test
├── Cargo.toml → Cargo Test
├── pom.xml → Maven
└── build.gradle → Gradle
When the AI detects test-related requests, it automatically:
Error: No test framework detected.
Install vitest, jest, or pytest.
Test Results: 40 passed, 2 failed (3.2s)
Failed Tests:
src/auth.test.ts:45 - should validate token
Expected: true
Received: false
src/auth.test.ts:67 - should handle refresh
TypeError: Cannot read property 'token' of undefined
Error: 'vitest' not found.
Run: npm install -D vitest
Test runner settings in legion.json:
{
"testRunner": {
"framework": "auto",
"timeout": 30000,
"coverage": false
}
}
$ legion run "run tests"
# Auto-detects: vitest
# Command: npx vitest run
# Output: 42 tests passed (2.1s)
$ legion run "run tests"
# Auto-detects: pytest
# Command: pytest
# Output: 128 tests passed (5.4s)
$ legion run "run tests"
# Auto-detects: cargo
# Command: cargo test
# Output: 89 tests passed (12.3s)