بنقرة واحدة
superpowers-test-driven-development
Writing or fixing any code? Load first — write the failing test before the code.
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
Writing or fixing any code? Load first — write the failing test before the code.
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
استنادا إلى تصنيف SOC المهني
Got a spec or requirements for a multi-step task? Load first, before touching code.
Sync this port with upstream obra/superpowers or Reasonix main-v2: detect drift, re-port, bench-gate
Building a feature or starting from an idea? STOP. Load first for an approved design before code.
Executing a written plan step-by-step in this session, with checkpoints? Load this first.
Branch finished, tests green? Load first to merge, PR, or clean up.
Got review feedback? Load BEFORE changing anything — verify each point, push back if wrong.
| name | superpowers-test-driven-development |
| description | Writing or fixing any code? Load first — write the failing test before the code. |
Test first. Watch it fail. Write minimal code to pass.
Core principle: Didn't watch the test fail? You don't know it tests the right thing.
Break the letter of the rules = break the spirit.
Always: new features, bug fixes, refactors, behavior changes.
Exceptions (ask your human partner): throwaway prototypes, generated code, config files.
"Skip TDD just this once"? Stop. That's rationalization.
NO PRODUCTION CODE WITHOUT A FAILING TEST FIRST
Code before the test? Delete it. Start over. Don't keep it as "reference", don't "adapt" it, don't look at it. Delete means delete. Implement fresh from tests.
digraph tdd_cycle {
rankdir=LR;
red [label="RED\nWrite failing test", shape=box, style=filled, fillcolor="#ffcccc"];
verify_red [label="Verify fails\ncorrectly", shape=diamond];
green [label="GREEN\nMinimal code", shape=box, style=filled, fillcolor="#ccffcc"];
verify_green [label="Verify passes\nAll green", shape=diamond];
refactor [label="REFACTOR\nClean up", shape=box, style=filled, fillcolor="#ccccff"];
next [label="Next", shape=ellipse];
red -> verify_red;
verify_red -> green [label="yes"];
verify_red -> red [label="wrong\nfailure"];
green -> verify_green;
verify_green -> refactor [label="yes"];
verify_green -> green [label="no"];
refactor -> verify_green [label="stay\ngreen"];
verify_green -> next;
next -> red;
}
One minimal test. Shows what should happen.
```typescript test('retries failed operations 3 times', async () => { let attempts = 0; const operation = () => { attempts++; if (attempts < 3) throw new Error('fail'); return 'success'; };const result = await retryOperation(operation);
expect(result).toBe('success'); expect(attempts).toBe(3); });
Clear name, real behavior, one thing
</Good>
<Bad>
```typescript
test('retry works', async () => {
const mock = jest.fn()
.mockRejectedValueOnce(new Error())
.mockRejectedValueOnce(new Error())
.mockResolvedValueOnce('success');
await retryOperation(mock);
expect(mock).toHaveBeenCalledTimes(3);
});
Vague name, tests mock not code
One behavior. Clear name. Real code (no mocks unless unavoidable).
MANDATORY. Never skip. Run via bash:
npm test path/to/test.test.ts
Confirm: fails (not errors), failure message is the expected one, fails because feature missing (not a typo).
Passes? Testing existing behavior — fix the test. Errors? Fix, rerun till it fails right.
Simplest code that passes.
```typescript async function retryOperation(fn: () => Promise): Promise { for (let i = 0; i < 3; i++) { try { return await fn(); } catch (e) { if (i === 2) throw e; } } throw new Error('unreachable'); } ``` Just enough to pass ```typescript async function retryOperation( fn: () => Promise, options?: { maxRetries?: number; backoff?: 'linear' | 'exponential'; onRetry?: (attempt: number) => void; } ): Promise { // YAGNI } ``` Over-engineeredDon't add features, refactor other code, or "improve" past the test.
MANDATORY.
npm test path/to/test.test.ts
Confirm: passes, other tests still pass, output pristine (no errors/warnings).
Fails? Fix code, not test. Other tests fail? Fix now.
After green only: kill duplication, improve names, extract helpers. Stay green. Don't add behavior.
Next failing test, next feature.
| Quality | Good | Bad |
|---|---|---|
| Minimal | One thing. "and" in name? Split it. | test('validates email and domain and whitespace') |
| Clear | Name describes behavior | test('test1') |
| Shows intent | Demonstrates desired API | Obscures what code should do |
| Excuse | Reality |
|---|---|
| "Too simple to test" | Simple code breaks. Test takes 30 seconds. |
| "I'll test after" | Tests passing immediately prove nothing. |
| "Tests after achieve same goals" | Tests-after = "what does this do?" Tests-first = "what should this do?" |
| "Already manually tested" | Ad-hoc ≠ systematic. No record, can't re-run. |
| "Deleting X hours is wasteful" | Sunk cost. Keeping unverified code is tech debt. |
| "Keep as reference, write tests first" | You'll adapt it. That's testing after. Delete means delete. |
| "Need to explore first" | Fine. Throw away exploration, start with TDD. |
| "Test hard = design unclear" | Listen to the test. Hard to test = hard to use. |
| "TDD will slow me down" | TDD faster than debugging. Pragmatic = test-first. |
| "Manual test faster" | Manual doesn't prove edge cases. You'll re-test every change. |
| "Existing code has no tests" | You're improving it. Add tests for it. |
All mean: delete code, start over with TDD.
Bug: empty email accepted.
RED
test('rejects empty email', async () => {
const result = await submitForm({ email: '' });
expect(result.error).toBe('Email required');
});
Verify RED
$ npm test
FAIL: expected 'Email required', got undefined
GREEN
function submitForm(data: FormData) {
if (!data.email?.trim()) {
return { error: 'Email required' };
}
// ...
}
Verify GREEN
$ npm test
PASS
REFACTOR — extract validation for more fields if needed.
Can't check all? You skipped TDD. Start over.
| Problem | Solution |
|---|---|
| Don't know how to test | Write the wished-for API. Assertion first. Ask your human partner. |
| Test too complicated | Design too complicated. Simplify the interface. |
| Must mock everything | Code too coupled. Use dependency injection. |
| Test setup huge | Extract helpers. Still complex? Simplify design. |
Bug? Write a failing test reproducing it. Follow the cycle — the test proves the fix and blocks regression. Never fix bugs without a test. (See superpowers-systematic-debugging.)
Adding mocks/test utils? Consult the Testing Anti-Patterns reference (auto-included below): testing mock not real behavior; test-only methods in prod classes; mocking without understanding deps.
Production code → test exists and failed first
Otherwise → not TDD
No exceptions without your human partner's permission.