Back to list
hanayashiki

tdd

by hanayashiki

VSCode Plugin and Language Service for OpenAPI documents

0🍴 0📅 Jan 10, 2026

SKILL.md


name: tdd description: Test-Driven Development workflow for packages/server. Write failing test first, then implement the fix. user_invocable: true allowed_tools:

  • Read
  • Write
  • Edit
  • Glob
  • Grep
  • Bash(pnpm test :)
  • Bash(npm run test:*)

TDD Workflow

This skill enforces Test-Driven Development for the packages/server package.

Workflow

1. Red: Write a Failing Test First

Before writing any implementation code, create or update a test file in packages/server/test/:

// Example test structure
import { describe, it, expect } from "vitest";
import dedent from "dedent";

describe("featureName", () => {
  it("should do the expected behavior", () => {
    // Arrange
    const input = ...;

    // Act
    const result = functionUnderTest(input);

    // Assert
    expect(result).toBe(expectedValue);
  });
});

Run the test to confirm it fails:

cd packages/server && pnpm test -- --run test/<test-file>.test.ts

The test MUST fail before proceeding. If it passes, the test is not testing new behavior.

2. Green: Write Minimal Implementation

Write the minimum code needed to make the test pass:

  • Only implement what's required to pass the test
  • Don't add extra features or optimizations
  • Don't refactor yet

Run the test again:

cd packages/server && pnpm test -- --run test/<test-file>.test.ts

The test MUST pass before proceeding.

3. Refactor: Clean Up the Code

Now that tests are green, improve the code:

  • Remove duplication
  • Improve naming
  • Simplify logic
  • Ensure consistent style

Run tests after each refactoring step to ensure nothing breaks:

cd packages/server && pnpm test

Test File Conventions

  • Test files: packages/server/test/*.test.ts
  • Use vitest with describe, it, expect
  • Use dedent for multi-line string fixtures
  • Import types from @openapi-lsp/core/openapi

Example TDD Session

Task: Add validation for empty arrays

Step 1 - Red:

it("should return error for empty array", () => {
  const result = validate([]);
  expect(result.ok).toBe(false);
  expect(result.error).toBe("Array cannot be empty");
});

Run test → FAIL ✗

Step 2 - Green:

function validate(arr: unknown[]) {
  if (arr.length === 0) {
    return { ok: false, error: "Array cannot be empty" };
  }
  return { ok: true };
}

Run test → PASS ✓

Step 3 - Refactor:

function validate(arr: unknown[]): Result<void, string> {
  if (arr.length === 0) {
    return Err("Array cannot be empty");
  }
  return Ok(undefined);
}

Run test → PASS ✓

Running Tests

# Run specific test file
cd packages/server && pnpm test -- --run test/serializeSchema.test.ts

# Run all tests
npm run test

# Run tests in watch mode (during development)
cd packages/server && pnpm test

Score

Total Score

60/100

Based on repository quality metrics

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

+10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

3ヶ月以内に更新がある

0/10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

0/5

Reviews

💬

Reviews coming soon