跳到主内容
智客 ZICQ

技能库 智客分类:运维与云 typescript-e2e-testing

Typescript E2e Testing

E2E和TypeScript/NestJS项目集成测试使用Jest,超测试,并通过多克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克 当用户正在编制`.e2e-spec.ts ' 文件或`test/e2e/'之下的任何文件时使用,或要求设置、写作、审查、运行、调试或优化E2E或集成测试——包括片状测试、用于测试的多克编组、Kafka/Redpanda消费者、测试隔离或GWT合规.

2250 安装量

官方网址:skills.sh

技能介绍

先看中文介绍;官方 description 原文单独保留,不改写 SKILL.md。

做什么

E2E和TypeScript/NestJS项目的集成测试,使用Jest,超测试,并通过多克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克

何时用

官方 description 未单独写出 Use when。按规范,代理会在用户任务与这段 description 的关键词匹配时激活本技能。

代理如何加载

按 Agent Skills 渐进披露:启动时只加载 name 与 description(约 100 token);任务匹配后才读入整份 SKILL.md 正文;scripts/、references/、assets/ 仅在需要时再读。 本文件正文结构:E2E Testing Skill、Workflows、Workflow Selection Guide、Detect User Intent → Select Workflow、Workflow Execution Protocol、Knowledge Base Structure。 其中含规范建议的小节:分步指令、边界情况。

文件分析

文件分析:除 SKILL.md 外,正文引用了 references/common/knowledge.md、references/common/nestjs-setup.md、references/common/rules.md、references/common/test-case-creation-guide.md、references/kafka/knowledge.md、references/postgres/rules.md,属于带资源的技能包,这些文件按需再读。

官方 description(原文)

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.

E2E Testing SkillWorkflowsWorkflow Selection GuideDetect User Intent → Select WorkflowWorkflow Execution ProtocolKnowledge Base StructureQuick Reference by TaskSetup New E2E StructureWrite Test CasesReview Test QualityRun E2E TestsDebug Failing Tests

来源分类:skills.sh agent-skill

SKILL.md 与 Agent 调用

官方规范 ↗
name
typescript-e2e-testing
description
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.
  1. 发现技能客户端向 Agent 提供名称与描述目录。
  2. 匹配与调用用户指定或任务匹配后,载入 SKILL.md 指令。
  3. 按需加载按步骤读取参考文档、使用脚本与素材。
指令中引用的文件 · 11
  • references/common/knowledge.md
  • references/common/nestjs-setup.md
  • references/common/rules.md
  • references/common/test-case-creation-guide.md
  • references/kafka/knowledge.md
  • references/postgres/rules.md
  • references/mongodb/rules.md
  • references/redis/rules.md
  • references/api/rules.md
  • references/common/best-practices.md
  • references/common/debugging.md

以下路径提取自原文;文件是否齐全请以来源仓库中的完整目录为准。

具体调用语法与可用工具以目标 Agent 客户端为准。 查看调用机制说明 ↗

安装这个技能

Skills CLI ↗

先选择目标 Agent 和安装范围,保留技能包的附属文件,安装后检查客户端能否发现该技能。

该技能引用了附属文件,请从来源获取完整目录;仅复制 SKILL.md 可能缺少依赖。

交给 Agent 安装

复制安装指令给支持 Agent Skills 的代理,确认其中的目标目录与客户端匹配。

把 Agent Skill「typescript-e2e-testing」安装到我的项目:SKILL.md 原文与官方 description 见 https://zicq.com/zh/skills/skl-a77785097b96a5d1-Typescript-E2e-Testing.html
请存为 .cursor/skills/typescript-e2e-testing/SKILL.md 或 .claude/skills/typescript-e2e-testing/SKILL.md,frontmatter 的 name 与 description 保持原样,不要改写。
该技能还带 scripts/、references/、assets/ 等文件,请从 https://github.com/bmad-labs/skills 取完整目录,不要只建一个 SKILL.md。

GitHub 完整包 ↗

终端安装 · Skills CLI

需要 Node.js 与 npx。先查看仓库技能列表,确认实际名称。

npx skills add 'https://github.com/bmad-labs/skills' --list

npx skills add 'https://github.com/bmad-labs/skills' --skill 'typescript-e2e-testing'

CLI 会交互选择目标 Agent,默认安装到项目;用户级安装使用 -g。先通过查看命令核对仓库内容,再用 npx skills list 检查已安装技能。

阅读排版

name: typescript-e2e-testing description: 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.

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.md → test-helper.md → isolation.md
    • PostgreSQL: references/postgres/rules.md → test-helper.md
    • MongoDB: references/mongodb/rules.md → test-helper.md
    • Redis: references/redis/rules.md → test-helper.md
    • API: references/api/rules.md → test-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: '[email protected]', 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('[email protected]');
});

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: '[email protected]', 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

相关技能

运维与云

Docker Essentials

用于容器管理,图像操作,调试的基本道克命令和工作流程.

运维与云

Find Skills

从开放的代理技能生态系统中发现并安装技能. 使用时:(1)用户问"我如何做X",X可能拥有现有技能,(2)用户说"为X找到技能"或"是否为X有技能",(3)用户问"你能否做X",X是专门能力,(4)用户想扩展代理能力,(5)用户想搜索工具,模板,或工作流程,(6)用户提到他们希望…

运维与云

Azure Diagnostics

Azure上使用AppLens,AzureMonitor,资源健康,安全分型的调试Azure生产问题. 当:调试生产问题,故障解答应用服务,应用服务高CPU,应用服务部署失败,故障解答容器应用,故障解答功能,故障解答AKS,VM RDP,Linux SSH,VM黑屏幕,无法连接到…

运维与云

Azure Prepare

准备 azd 用于部署的Azure项目:为Azure开发者CLI(azd)工作流程生成azure.yaml,基础设施(Bicep/Terraform)和多克文件. 仅当用户明确想要使用 azd 作为部署工具时使用, 或项目已经有一个 azure 。 雅姆尔文件。 不使用: 非az…