Claude-code-templates test-detect
Auto-detect testing framework and run relevant tests. Identifies Jest, Vitest, Playwright, Cypress, pytest, Go test, and others. Can run all tests, specific file tests, or generate basic tests for new code. Usage - /test-detect, /test-detect src/auth/login.ts, /test-detect generate src/utils.ts
git clone https://github.com/davila7/claude-code-templates
T=$(mktemp -d) && git clone --depth=1 https://github.com/davila7/claude-code-templates "$T" && mkdir -p ~/.claude/skills && cp -r "$T/cli-tool/components/skills/development/test-detect" ~/.claude/skills/davila7-claude-code-templates-test-detect && rm -rf "$T"
cli-tool/components/skills/development/test-detect/SKILL.mdTest Detect
Automatically detect the testing framework in the current project and run the right tests.
Workflow
Step 1: Detect the testing framework
Check for these files in order (first match wins):
| Check | Framework | Run Command |
|---|---|---|
exists OR in devDeps | Vitest | |
exists OR in devDeps | Jest | |
exists | Playwright | |
exists | Cypress | |
or or with | pytest | |
exists | Go test | |
exists | Rust/cargo | |
exists | ExUnit | |
with | RSpec | |
has | npm test | |
Report the detected framework before proceeding.
Step 2: Parse arguments
Check
$ARGUMENTS for the mode:
- No arguments or "all": Run the full test suite (Step 3)
- File path (e.g.,
): Run tests for that file (Step 4)src/auth/login.ts - "generate" + file path (e.g.,
): Generate tests (Step 5)generate src/utils.ts
Step 3: Run full test suite
Run the detected test command. After completion:
- Report total tests, passed, failed, skipped
- If tests fail, show the first 3 failure messages with file:line references
- Suggest: "Run
to investigate a specific failure"/test-detect <failing-file>
Step 4: Run tests for a specific file
Given a source file path, find its test file:
Search strategy (try in order):
(Jest convention)__tests__/<filename>.test.<ext>
(co-located)<filename>.test.<ext>
(alternative convention)<filename>.spec.<ext>
(Go/Python convention)test/<filename>_test.<ext>
(pytest convention)tests/test_<filename>.<ext>
(Go convention)<filename>_test.go
Use Glob to find matches. If found, run only that test file:
| Framework | Command |
|---|---|
| Vitest | |
| Jest | |
| Playwright | |
| pytest | |
| Go | |
| Cargo | |
If no test file found, ask: "No tests found for this file. Want me to generate them? Run
/test-detect generate <file>"
Step 5: Generate tests
Read the source file and analyze:
- Identify all exported functions/classes/components
- Determine the appropriate test patterns for the framework
- Generate a test file with:
- Import statements
block per function/classdescribe
/it
blocks covering: happy path, edge cases, error casestest- Framework-appropriate assertions and mocking
Save to the conventional location for the detected framework:
- Jest/Vitest:
or__tests__/<filename>.test.<ext>
(match existing convention)<filename>.test.<ext> - pytest:
tests/test_<filename>.py - Go:
(same directory)<filename>_test.go - RSpec:
spec/<filename>_spec.rb
Show the generated file path and ask if the user wants to run the new tests.
Tips
- If multiple frameworks are detected (e.g., Vitest for unit tests + Playwright for e2e), mention both and default to the unit test framework
- For monorepos, detect from the closest config file to the current directory
- If
has bothpackage.json
andtest
/test:unit
scripts, prefer the specific one when context is cleartest:e2e