mcpField
T
tdd

tdd

github.com/blogic-czTesting & quality386 installsUpdated 1d ago
Repository

About tdd

A coding skill for applying test-driven development to utilities, services, complex logic, and bug fixes. It guides developers through a test-first Red-Green-Refactor cycle and includes Effect-specific patterns.

Key features

  1. 01Red-Green-Refactor workflow
  2. 02Test-first bug reproduction
  3. 03Effect service testing patterns
  4. 04Guidance on test scope and locations
  5. 05Reference guides and examples

Use cases

  1. 01Developing a utility or complex business logic
  2. 02Fixing a bug by first writing a reproducing test
  3. 03Testing Effect services with mock layers

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/blogic-cz/blogic-marketplace --skill tdd

After installing, type/tddin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

references/
anti-patterns.md
commands.md
effect-tdd-patterns.md
red-green-refactor.md
test-first-examples.md

Details

From the project README

Test-Driven Development (TDD)

Apply this skill to execute strict test-first development: write a failing test, implement the minimum code to pass, then refactor while keeping tests green.

Decide when to use TDD

Use this decision table:

SituationUse this skill?Default action
New utility functionYesRun TDD cycle immediately
New Effect serviceYesDefine behavior through tests first
Complex business logicYesLock behavior with tests before implementation
Bug fixYesReproduce bug with failing test first
UI styling/layout-only changeNoUse standard implementation flow
Exploratory prototypingNoPrototype first, then switch to TDD once behavior stabilizes
TRPC endpoint (simple CRUD)Usually noUse testing-patterns by default; use this skill only when user explicitly requests test-first/RGR

Execute Red-Green-Refactor

Follow one behavior at a time through three phases.

1. RED - Write Failing Test First
import { describe, expect, it } from "vitest";
import { calculateDiscount } from "../calculate-discount";

describe("calculateDiscount", () => {
  it("applies 10% discount for orders over 100", () => {
    // This test fails first: function does not exist yet
    expect(calculateDiscount(150)).toBe(135);
  });
});

Run test to see it fail:

bun run vitest run packages/common/src/__tests__/calculate-discount.test.ts
2. GREEN - Implement Minimum Code

Write the minimum code to make the test pass:

// packages/common/src/calculate-discount.ts
export function calculateDiscount(amount: number): number {
  if (amount > 100) {
    return amount * 0.9;
  }
  return amount;
}

Run test to see it pass:

bun run vitest run packages/common/src/__tests__/calculate-discount.test.ts
3. REFACTOR - Improve Without Breaking Behavior

Improve code quality while keeping tests green:

const DISCOUNT_THRESHOLD = 100;
const DISCOUNT_RATE = 0.1;

export function calculateDiscount(amount: number): number {
  if (amount <= DISCOUNT_THRESHOLD) {
    return amount;
  }
  return amount * (1 - DISCOUNT_RATE);
}

Run tests again to verify refactoring didn't break anything.

For extended examples, failure diagnostics, and iterative expansions, read references/red-green-refactor.md.


Keep test scope lean

Prefer lighter tests first and escalate only when needed:

  1. Unit tests (preferred) - Pure functions and Effect services with mock layers.
  2. TRPC integration tests - Full TRPC + persistence behavior.
  3. E2E tests - Browser-level flows and user journeys.
SituationTest TypeAction
Pure function, parser, utilUnitWrite immediately
Effect service with dependenciesUnit with mock layersWrite immediately
TRPC procedure (DB logic)TRPC integrationFollow testing-patterns decision process
User-facing flow, UI behaviorE2EFollow testing-patterns decision process

Apply Effect-specific TDD patterns

Use test-first service design with explicit layers.

  1. Define interface via test - Make behavior explicit before implementation.
  2. Create mock layer - Isolate dependencies and keep tests deterministic.
  3. Implement service - Satisfy the tests with the minimal behavior.
  4. Refactor - Improve readability and structure while preserving behavior.
import { describe, expect, it } from "@effect/vitest";
import { Effect, Layer } from "effect";

describe("PricingService", () => {
  // 1. Define what the service should do via tests
  it.effect("calculates base price without discount", () =>
    Effect.gen(function* () {
      const service = yield* PricingService;
      const result = yield* service.calculatePrice({
        itemId: "item-1",
        quantity: 2,
      });
      expect(result.total).toBe(200);
    }).pipe(Effect.provide(testLayer)),
  );

  it.effect("applies bulk discount for quantity > 10", () =>
    Effect.gen(function* () {
      const service = yield* PricingService;
      const result = yield* service.calculatePrice({
        itemId: "item-1",
        quantity: 15,
      });
      expect(result.total).toBe(1350); // 15% discount
    }).pipe(Effect.provide(testLayer)),
  );
});
Mock Layer Factory Pattern
// Create parameterized mock layers for different test scenarios
const createMockInventoryLayer = (inventory: Map<string, number>) =>
  Layer.succeed(InventoryService, {
    getStock: (itemId) => Effect.succeed(inventory.get(itemId) ?? 0),
    reserveStock: (itemId, qty) => Effect.succeed(void 0),
  });

// Use in tests
const testLayer = PricingService.layer.pipe(
  Layer.provide(createMockInventoryLayer(new Map([["item-1", 100]]))),
);

For deeper guidance (error-path testing, layer composition, anti-vi.mock() rationale), read references/effect-tdd-patterns.md.


Use project-convention test locations (examples)

Treat these paths as project conventions/examples; adapt if a repository uses different test layout.

Code LocationTest Location
packages/X/src/file.tspackages/X/src/__tests__/file.test.ts
apps/web-app/src/infrastructure/trpc/routers/X.tsapps/web-app/src/__tests__/X.test.ts
apps/web-app/src/routes/**apps/web-app/e2e/feature.e2e.ts

Use supporting references for depth

Load targeted references instead of expanding this file during execution:

  • Use references/commands.md for runnable command patterns.
  • Use references/anti-patterns.md for failure-mode walkthroughs and corrections.

Resources

references/
  • red-green-refactor.md - Detailed TDD cycle workflow with examples
  • effect-tdd-patterns.md - Effect service testing, mock layers, error cases
  • test-first-examples.md - Step-by-step TDD examples for this codebase
  • commands.md - Command catalog and correct/incorrect invocation patterns
  • anti-patterns.md - Detailed TDD anti-pattern walkthroughs with fixes
Related Skills
  • testing-patterns - Test syntax, TRPC integration tests, E2E patterns
  • effect-ts - Effect service design, layers, error handling

Comments

Markdown supported