systemPatterns.json•3.25 kB
{
  "schema": "memory_document_v2",
  "metadata": {
    "id": "82e38f95-68eb-4910-9032-b400b6a2cde2",
    "title": "システムパターン",
    "documentType": "system_patterns",
    "path": "systemPatterns.json",
    "tags": [
      "core",
      "system-patterns"
    ],
    "lastModified": "2025-03-24T12:49:30.304Z",
    "createdAt": "2025-03-23T18:09:48.304Z",
    "version": 1
  },
  "content": {
    "technicalDecisions": [
      {
        "id": "td-001",
        "title": "ts-mockitoからjest.fnへの移行",
        "context": "テストコードではts-mockitoを使用してモックを作成していたが、Jestの標準モック機能に統一したい",
        "decision": "ts-mockitoの関数をJestのネイティブモック関数に置き換える変換スクリプトを開発する",
        "status": "implemented",
        "impact": [
          "依存パッケージの削減",
          "テストコードの一貫性の向上",
          "Jestエコシステムの活用"
        ]
      },
      {
        "id": "td-002",
        "title": "型チェックのスキップ",
        "context": "ts-mockitoとjest.fnのモックの型の扱いが異なるため、型エラーが発生する",
        "decision": "@ts-nocheckディレクティブを追加して型チェックをスキップする",
        "status": "implemented",
        "impact": [
          "型チェックエラーを回避できる",
          "長期的にはより適切な型定義の作成が必要かもしれない"
        ]
      },
      {
        "id": "td-003",
        "title": "自動変換の範囲",
        "context": "すべてのts-mockito関数を適切にJestに変換する必要がある",
        "decision": "以下のパターンを自動変換する:\n- mock<T>() → オブジェクトリテラル + 型キャスト\n- instance() → 直接オブジェクト参照\n- when().thenReturn() → jest.fn().mockReturnValue()\n- when().thenResolve() → jest.fn().mockResolvedValue()\n- when().thenThrow() → jest.fn().mockImplementation(() => { throw ... })\n- verify().called() → expect().toHaveBeenCalled()\n- verify().never() → expect().not.toHaveBeenCalled()\n- verify().times() → expect().toHaveBeenCalledTimes()\n- verify().atLeast() → expect().toHaveBeenCalledTimes() (注釈付き)\n- deepEqual() → 引数そのまま\n- anyString() → expect.any(String)\n- anything() → expect.anything()\n- fail() → expect(message).toBe(false)",
        "status": "implemented",
        "impact": [
          "手作業での変換が不要に",
          "一貫性のある変換が可能に"
        ]
      }
    ],
    "directoryStructure": [
      {
        "path": "./tests",
        "description": "テストコードディレクトリ",
        "contents": [
          "unit/ - ユニットテスト",
          "integration/ - 統合テスト",
          "mocks/ - モックのヘルパー",
          "utils/ - テスト用ユーティリティ"
        ]
      },
      {
        "path": "./replace-ts-mockito-with-jestfn.ts",
        "description": "ts-mockitoをjest.fnに置き換えるスクリプト",
        "content": "ESモジュール形式のNode.jsスクリプト"
      }
    ]
  }
}