jpskill.com
🛠️ 開発・MCP コミュニティ

typescript-e2e-testing

TypeScript/NestJSプロジェクトで、JestやSupertest、Docker上のKafka/PostgreSQLなどを用いて、E2Eや統合テストの構築、実行、デバッグ、最適化を支援し、特にGWTパターンや不安定なテスト、テスト環境の構築に関する課題解決をサポートするSkill。

📜 元の英語説明(参考)

E2E and integration testing for TypeScript/NestJS projects using Jest, supertest, and real infrastructure via Docker (Kafka, PostgreSQL, MongoDB, Redis) with the Given-When-Then pattern. Use whenever the user is working on `.e2e-spec.ts` files or anything under `test/e2e/`, or asks to set up, write, review, run, debug, or optimize E2E or integration tests — including flaky tests, docker-compose for tests, Kafka/Redpanda consumers, test isolation, or GWT compliance.

🇯🇵 日本人クリエイター向け解説

一言でいうと

TypeScript/NestJSプロジェクトで、JestやSupertest、Docker上のKafka/PostgreSQLなどを用いて、E2Eや統合テストの構築、実行、デバッグ、最適化を支援し、特にGWTパターンや不安定なテスト、テスト環境の構築に関する課題解決をサポートするSkill。

※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。

⚡ おすすめ: コマンド1行でインストール(60秒)

下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。

🍎 Mac / 🐧 Linux
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o typescript-e2e-testing.zip https://jpskill.com/download/23728.zip && unzip -o typescript-e2e-testing.zip && rm typescript-e2e-testing.zip
🪟 Windows (PowerShell)
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/23728.zip -OutFile "$d\typescript-e2e-testing.zip"; Expand-Archive "$d\typescript-e2e-testing.zip" -DestinationPath $d -Force; ri "$d\typescript-e2e-testing.zip"

完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して typescript-e2e-testing.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → typescript-e2e-testing フォルダができる
  3. 3. そのフォルダを C:\Users\あなたの名前\.claude\skills\(Win)または ~/.claude/skills/(Mac)へ移動
  4. 4. Claude Code を再起動

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。

詳しい使い方ガイドを見る →
最終更新
2026-05-18
取得日時
2026-05-18
同梱ファイル
35

📖 Skill本文(日本語訳)

※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

[Skill 名] typescript-e2e-testing

E2E テストスキル

E2E テストは、Docker を介して実際のインフラストラクチャを使用し、ユーザー視点から完全なワークフローを検証します。


ワークフロー

包括的なステップバイステップのガイダンスについては、適切なワークフローを使用してください。

ワークフロー 使用する状況
E2E テストのセットアップ 新規または既存のプロジェクトに E2E インフラストラクチャをセットアップする場合
E2E テストの作成 適切な GWT パターンで新しい E2E テストケースを作成する場合
E2E テストのレビュー 既存のテストの品質と正確性をレビューする場合
E2E テストの実行 適切な検証を行ってテストを実行する場合
E2E テストのデバッグ 失敗するテストを体系的に修正する場合
E2E テストの最適化 テストスイートのパフォーマンスを向上させる場合

ワークフロー選択ガイド

重要: E2E テストタスクを開始する前に、ユーザーの意図を特定し、適切なワークフローを読み込んでください。

ユーザーの意図を検出 → ワークフローを選択

ユーザーの発言 / 要望 読み込むワークフロー ファイル
「E2E テストをセットアップする」、「docker-compose を設定する」、「プロジェクトに E2E を追加する」、「テストヘルパーを作成する」 Setup workflows/setup/workflow.md
「E2E テストを作成する」、「統合テストを追加する」、「このエンドポイントをテストする」、「e2e-spec を作成する」 Writing workflows/writing/workflow.md
「E2E テストをレビューする」、「テスト品質を確認する」、「テストを監査する」、「このテストは正しいか?」 Reviewing workflows/review/workflow.md
「E2E テストを実行する」、「テストを実行する」、「Docker を起動してテストする」、「テストがパスするか確認する」 Running workflows/running/workflow.md
「E2E テストを修正する」、「テストをデバッグする」、「テストが失敗している」、「不安定なテスト」、「接続エラー」 Debugging workflows/debugging/workflow.md
「E2E テストを高速化する」、「テストを最適化する」、「テストが遅い」、「テスト時間を短縮する」 Optimizing workflows/optimize/workflow.md

ワークフロー実行プロトコル

  1. 常に最初にワークフローファイルを読み込む - アクションを起こす前にワークフロー全体を読んでください。
  2. 各ステップを順番に実行する - 次に進む前にチェックポイントを完了してください。
  3. 指示に従って知識ファイルを読み込む - 各ワークフローは、どの references/ ファイルを読むべきかを指定しています。
  4. 完了後にコンプライアンスを検証する - 関連する参照ファイルを再読し、品質を確保してください。

重要: 各ワークフローには、タスクの完了前後に references/ フォルダーから関連する知識を読み込むための指示が含まれています。


知識ベースの構造

references/
├── common/              # 共通のテストの基礎
│   ├── knowledge.md     # コア E2E の概念とテストピラミッド
│   ├── rules.md         # 必須のテストルール (GWT、タイムアウト、ロギング)
│   ├── best-practices.md # テスト設計とクリーンアップパターン
│   ├── test-case-creation-guide.md # すべてのシナリオに対応する GWT テンプレート
│   ├── nestjs-setup.md  # NestJS アプリのブートストラップと Jest 設定
│   ├── debugging.md     # VS Code 設定とログ分析
│   └── examples.md      # カテゴリ別の包括的な例
│
├── kafka/               # Kafka 固有のテスト
│   ├── knowledge.md     # なぜ一般的なアプローチが失敗するのか、アーキテクチャ
│   ├── rules.md         # Kafka 固有のテストルール
│   ├── test-helper.md   # KafkaTestHelper の実装
│   ├── docker-setup.md  # Redpanda/Kafka Docker 設定
│   ├── performance.md   # 最適化手法
│   ├── isolation.md     # プリサブスクリプションパターンの詳細
│   └── examples.md      # Kafka テストの例
│
├── postgres/            # PostgreSQL 固有のテスト
│   ├── knowledge.md     # PostgreSQL テストの概念
│   ├── rules.md         # クリーンアップ、トランザクション、アサーションルール
│   ├── test-helper.md   # PostgresTestHelper の実装
│   └── examples.md      # CRUD、トランザクション、制約の例
│
├── mongodb/             # MongoDB 固有のテスト
│   ├── knowledge.md     # MongoDB テストの概念
│   ├── rules.md         # ドキュメントのクリーンアップとアサーションルール
│   ├── test-helper.md   # MongoDbTestHelper の実装
│   ├── docker-setup.md  # Docker とメモリサーバーのセットアップ
│   └── examples.md      # ドキュメントと集計の例
│
├── redis/               # Redis 固有のテスト
│   ├── knowledge.md     # Redis テストの概念
│   ├── rules.md         # TTL と pub/sub ルール
│   ├── test-helper.md   # RedisTestHelper の実装
│   ├── docker-setup.md  # Docker 設定
│   └── examples.md      # キャッシュ、セッション、レート制限の例
│
└── api/                 # API テスト (REST, GraphQL, gRPC)
    ├── knowledge.md     # API テストの概念
    ├── rules.md         # リクエスト/レスポンスのアサーションルール
    ├── test-helper.md   # 認証と Supertest ヘルパー
    ├── examples.md      # REST、GraphQL、検証の例
    └── mocking.md       # MSW と Nock による外部 API モック

タスク別クイックリファレンス

ヒント: 詳細なステップバイステップのガイダンスについては、上記の「ワークフロー」セクションを使用してください。

新しい E2E 構造のセットアップ

ワークフロー: E2E テストのセットアップ

  1. references/common/knowledge.md を読む - E2E の基礎を理解する
  2. references/common/nestjs-setup.md を読む - プロジェクトのセットアップ
  3. 必要に応じて、テクノロジー固有の docker-setup.md ファイルを読む

テストケースの作成

ワークフロー: E2E テストの作成

  1. 必須: references/common/rules.md を読む - GWT パターン、タイムアウト
  2. references/common/test-case-creation-guide.md を読む - テンプレート
  3. テクノロジー固有のファイルを読む:
    • Kafka: references/kafka/knowledge.mdtest-helper.mdisolation.md
    • PostgreSQL: references/postgres/rules.mdtest-helper.md
    • MongoDB: references/mongodb/rules.mdtest-helper.md
    • Redis: references/redis/rules.mdtest-helper.md
    • API: references/api/rules.mdtest-helper.md

テスト品質のレビュー

ワークフロー: E2E テストのレビュー

  1. references/common/rules.md を読む - ag を確認する

(原文がここで切り詰められています)

📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

E2E Testing Skill

E2E testing validates complete workflows from user perspective, using real infrastructure via Docker.


Workflows

For comprehensive step-by-step guidance, use the appropriate workflow:

Workflow When to Use
Setup E2E Test Setting up E2E infrastructure for a new or existing project
Writing E2E Test Creating new E2E test cases with proper GWT pattern
Review E2E Test Reviewing existing tests for quality and correctness
Running E2E Test Executing tests with proper verification
Debugging E2E Test Systematically fixing failing tests
Optimize E2E Test Improving test suite performance

Workflow Selection Guide

IMPORTANT: Before starting any E2E testing task, identify the user's intent and load the appropriate workflow.

Detect User Intent → Select Workflow

User Says / Wants Workflow to Load File
"Set up E2E tests", "configure docker-compose", "add E2E to project", "create test helpers" Setup workflows/setup/workflow.md
"Write E2E tests", "add integration tests", "test this endpoint", "create e2e-spec" Writing workflows/writing/workflow.md
"Review E2E tests", "check test quality", "audit tests", "is this test correct?" Reviewing workflows/review/workflow.md
"Run E2E tests", "execute tests", "start docker and test", "check if tests pass" Running workflows/running/workflow.md
"Fix E2E tests", "debug tests", "tests are failing", "flaky test", "connection error" Debugging workflows/debugging/workflow.md
"Speed up E2E tests", "optimize tests", "tests are slow", "reduce test time" Optimizing workflows/optimize/workflow.md

Workflow Execution Protocol

  1. ALWAYS load the workflow file first - Read the full workflow before taking action
  2. Follow each step in order - Complete checkpoints before proceeding
  3. Load knowledge files as directed - Each workflow specifies which references/ files to read
  4. Verify compliance after completion - Re-read relevant reference files to ensure quality

Important: Each workflow includes instructions to load relevant knowledge from the references/ folder before and after completing tasks.


Knowledge Base Structure

references/
├── common/              # Shared testing fundamentals
│   ├── knowledge.md     # Core E2E concepts and test pyramid
│   ├── rules.md         # Mandatory testing rules (GWT, timeouts, logging)
│   ├── best-practices.md # Test design and cleanup patterns
│   ├── test-case-creation-guide.md # GWT templates for all scenarios
│   ├── nestjs-setup.md  # NestJS app bootstrap and Jest config
│   ├── debugging.md     # VS Code config and log analysis
│   └── examples.md      # Comprehensive examples by category
│
├── kafka/               # Kafka-specific testing
│   ├── knowledge.md     # Why common approaches fail, architecture
│   ├── rules.md         # Kafka-specific testing rules
│   ├── test-helper.md   # KafkaTestHelper implementation
│   ├── docker-setup.md  # Redpanda/Kafka Docker configs
│   ├── performance.md   # Optimization techniques
│   ├── isolation.md     # Pre-subscription pattern details
│   └── examples.md      # Kafka test examples
│
├── postgres/            # PostgreSQL-specific testing
│   ├── knowledge.md     # PostgreSQL testing concepts
│   ├── rules.md         # Cleanup, transaction, assertion rules
│   ├── test-helper.md   # PostgresTestHelper implementation
│   └── examples.md      # CRUD, transaction, constraint examples
│
├── mongodb/             # MongoDB-specific testing
│   ├── knowledge.md     # MongoDB testing concepts
│   ├── rules.md         # Document cleanup and assertion rules
│   ├── test-helper.md   # MongoDbTestHelper implementation
│   ├── docker-setup.md  # Docker and Memory Server setup
│   └── examples.md      # Document and aggregation examples
│
├── redis/               # Redis-specific testing
│   ├── knowledge.md     # Redis testing concepts
│   ├── rules.md         # TTL and pub/sub rules
│   ├── test-helper.md   # RedisTestHelper implementation
│   ├── docker-setup.md  # Docker configuration
│   └── examples.md      # Cache, session, rate limit examples
│
└── api/                 # API testing (REST, GraphQL, gRPC)
    ├── knowledge.md     # API testing concepts
    ├── rules.md         # Request/response assertion rules
    ├── test-helper.md   # Auth and Supertest helpers
    ├── examples.md      # REST, GraphQL, validation examples
    └── mocking.md       # MSW and Nock external API mocking

Quick Reference by Task

Tip: For detailed step-by-step guidance, use the Workflows section above.

Setup New E2E Structure

Workflow: Setup E2E Test

  1. Read references/common/knowledge.md - Understand E2E fundamentals
  2. Read references/common/nestjs-setup.md - Project setup
  3. Read technology-specific docker-setup.md files as needed

Write Test Cases

Workflow: Writing E2E Test

  1. MANDATORY: Read references/common/rules.md - GWT pattern, timeouts
  2. Read references/common/test-case-creation-guide.md - Templates
  3. Read technology-specific files:
    • Kafka: references/kafka/knowledge.mdtest-helper.mdisolation.md
    • PostgreSQL: references/postgres/rules.mdtest-helper.md
    • MongoDB: references/mongodb/rules.mdtest-helper.md
    • Redis: references/redis/rules.mdtest-helper.md
    • API: references/api/rules.mdtest-helper.md

Review Test Quality

Workflow: Review E2E Test

  1. Read references/common/rules.md - Check against mandatory patterns
  2. Read references/common/best-practices.md - Quality standards
  3. Read technology-specific rules.md files

Run E2E Tests

Workflow: Running E2E Test

  1. Verify Docker infrastructure is running
  2. Run tests sequentially with npm run test:e2e > /tmp/e2e-${E2E_SESSION}-output.log 2>&1
  3. Follow failure protocol if tests fail

Debug Failing Tests

Workflow: Debugging E2E Test

  1. Read references/common/debugging.md
  2. Create /tmp/e2e-${E2E_SESSION}-failures.md tracking file
  3. Fix ONE test at a time

Optimize Test Performance

Workflow: Optimize E2E Test

  1. Read references/common/best-practices.md - Performance patterns
  2. Read references/kafka/performance.md for Kafka tests
  3. Measure baseline before making changes

Examples

  • Read references/common/examples.md for general patterns
  • Read technology-specific examples.md for detailed scenarios

Core Principles

0. Context Efficiency (Temp File Output)

ALWAYS redirect E2E test output to temp files, NOT console. E2E output is verbose and bloats agent context.

IMPORTANT: Redirect output to temp files only (NO console output). Use unique session ID to prevent conflicts.

# Generate unique session ID at start of debugging session
export E2E_SESSION=$(date +%s)-$$

# Standard pattern - redirect to file only (no console output)
npm run test:e2e > /tmp/e2e-${E2E_SESSION}-output.log 2>&1

# Read summary only (last 50 lines)
tail -50 /tmp/e2e-${E2E_SESSION}-output.log

# Get failure details
grep -B 2 -A 15 "FAIL\|✕" /tmp/e2e-${E2E_SESSION}-output.log

# Cleanup when done
rm -f /tmp/e2e-${E2E_SESSION}-*.log /tmp/e2e-${E2E_SESSION}-*.md

Temp Files (with ${E2E_SESSION} unique per agent):

  • /tmp/e2e-${E2E_SESSION}-output.log - Full test output
  • /tmp/e2e-${E2E_SESSION}-failures.log - Filtered failure output
  • /tmp/e2e-${E2E_SESSION}-failures.md - Tracking file for one-by-one fixing
  • /tmp/e2e-${E2E_SESSION}-debug.log - Debug runs
  • /tmp/e2e-${E2E_SESSION}-verify.log - Verification runs

1. Real Infrastructure

Test against actual services via Docker. Never mock databases or message brokers for E2E tests.

2. GWT Pattern (Mandatory)

ALL E2E tests MUST follow Given-When-Then:

it('should create user and return 201', async () => {
  // GIVEN: Valid user data
  const userData = { email: 'test@example.com', name: 'Test' };

  // WHEN: Creating user
  const response = await request(httpServer)
    .post('/users')
    .send(userData)
    .expect(201);

  // THEN: User created with correct data
  expect(response.body.data.email).toBe('test@example.com');
});

3. Test Isolation

Each test MUST be independent:

  • Clean database state in beforeEach
  • Use unique identifiers (consumer groups, topics)
  • Wait for async operations to complete

4. Specific Assertions

Assert exact values, not just existence:

// WRONG
expect(response.body.data).toBeDefined();

// CORRECT
expect(response.body).toMatchObject({
  code: 'SUCCESS',
  data: { email: 'test@example.com', name: 'Test' }
});

Project Structure

project-root/
├── src/
├── test/
│   ├── e2e/
│   │   ├── feature.e2e-spec.ts
│   │   ├── setup.ts
│   │   └── helpers/
│   │       ├── test-app.helper.ts
│   │       ├── postgres.helper.ts
│   │       ├── mongodb.helper.ts
│   │       ├── redis.helper.ts
│   │       └── kafka.helper.ts
│   └── jest-e2e.config.ts
├── docker-compose.e2e.yml
├── .env.e2e
└── package.json

Essential Jest Configuration

// test/jest-e2e.config.ts
const config: Config = {
  preset: 'ts-jest',
  testEnvironment: 'node',
  testMatch: ['**/*.e2e-spec.ts'],
  testTimeout: 25000,
  maxWorkers: 1,           // CRITICAL: Sequential execution
  clearMocks: true,
  forceExit: true,
  detectOpenHandles: true,
};

Technology-Specific Timeouts

Technology Wait Time Strategy
Kafka 10-20s max (polling) Smart polling with 50ms intervals
PostgreSQL <1s Direct queries
MongoDB <1s Direct queries
Redis <100ms In-memory operations
External API 1-5s Network latency

Failure Resolution Protocol

CRITICAL: Fix ONE test at a time. NEVER run full suite repeatedly while fixing.

When E2E tests fail:

  1. Initialize session (once at start):
    export E2E_SESSION=$(date +%s)-$$
  2. Create tracking file: /tmp/e2e-${E2E_SESSION}-failures.md with all failing tests
  3. Select ONE failing test - work on only this test
  4. Run ONLY that test (never full suite):
    npm run test:e2e -- -t "test name" > /tmp/e2e-${E2E_SESSION}-debug.log 2>&1
    tail -50 /tmp/e2e-${E2E_SESSION}-debug.log
  5. Fix the issue - analyze error, make targeted fix
  6. Verify fix - run same test 3-5 times:
    for i in {1..5}; do npm run test:e2e -- -t "test name" > /tmp/e2e-${E2E_SESSION}-run$i.log 2>&1 && echo "Run $i: PASS" || echo "Run $i: FAIL"; done
  7. Mark as FIXED in tracking file
  8. Move to next failing test - repeat steps 3-7
  9. Run full suite ONLY ONCE after ALL individual tests pass
  10. Cleanup: rm -f /tmp/e2e-${E2E_SESSION}-*.log /tmp/e2e-${E2E_SESSION}-*.md

WHY: Running full suite wastes time and context. Each failing test pollutes output, making debugging harder.


Common Patterns

Database Cleanup (PostgreSQL/MongoDB)

beforeEach(async () => {
  await new Promise(r => setTimeout(r, 500)); // Wait for in-flight
  await repository.clear();  // PostgreSQL
  // OR
  await model.deleteMany({}); // MongoDB
});

Kafka Test Helper Pattern

// Use pre-subscription + buffer clearing (NOT fromBeginning: true)
const kafkaHelper = new KafkaTestHelper();
await kafkaHelper.subscribeToTopic(outputTopic, false);
// In beforeEach: kafkaHelper.clearMessages(outputTopic);

Redis Cleanup

beforeEach(async () => {
  await redis.flushdb();
});

External API Mock (MSW)

mockServer.use(
  http.post('https://api.external.com/endpoint', () => {
    return HttpResponse.json({ status: 'success' });
  })
);

Async Event Verification (Kafka)

// Use smart polling instead of fixed waits
await kafkaHelper.publishEvent(inputTopic, event, event.id);
const messages = await kafkaHelper.waitForMessages(outputTopic, 1, 20000);
expect(messages[0].value).toMatchObject({ id: event.id });

Debugging Commands

All commands redirect output to temp files only (no console output).

# Initialize session (once at start)
export E2E_SESSION=$(date +%s)-$$

# Run specific test (no console output)
npm run test:e2e -- -t "should create user" > /tmp/e2e-${E2E_SESSION}-output.log 2>&1 && tail -50 /tmp/e2e-${E2E_SESSION}-output.log

# Run specific file
npm run test:e2e -- test/e2e/user.e2e-spec.ts > /tmp/e2e-${E2E_SESSION}-output.log 2>&1 && tail -50 /tmp/e2e-${E2E_SESSION}-output.log

# Run full suite
npm run test:e2e > /tmp/e2e-${E2E_SESSION}-output.log 2>&1 && tail -50 /tmp/e2e-${E2E_SESSION}-output.log

# Get failure details from last run
grep -B 2 -A 15 "FAIL\|✕" /tmp/e2e-${E2E_SESSION}-output.log

# Debug with breakpoints (requires console for interactive debugging)
node --inspect-brk node_modules/.bin/jest --config test/jest-e2e.config.ts --runInBand

# View application logs (limited)
tail -100 logs/e2e-test.log
grep -i error logs/e2e-test.log | tail -50

# Cleanup session files
rm -f /tmp/e2e-${E2E_SESSION}-*.log /tmp/e2e-${E2E_SESSION}-*.md

Anti-Patterns to Avoid

  1. Multiple WHEN actions - Split into separate tests
  2. Conditional assertions - Create deterministic test cases
  3. Shared state between tests - Clean in beforeEach
  4. Mocking databases - Use real connections
  5. Skipping cleanup - Always clean before AND after
  6. Fixing multiple tests at once - Fix one at a time
  7. Generic assertions - Assert specific values
  8. fromBeginning: true for Kafka - Use pre-subscription + buffer clearing

同梱ファイル

※ ZIPに含まれるファイル一覧。`SKILL.md` 本体に加え、参考資料・サンプル・スクリプトが入っている場合があります。