All skills
bmad-labs avatar

/typescript-e2e-testing

@3bcc7a6
by bmad-labsbmad-labs/skills15 stars
4

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.

Use this Skill: https://skilld.dev/gh/bmad-labs/skills/typescript-e2e-testing

This session only. Nothing lands on disk.

referencesredistest-helper.md

≈1.2k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Redis Test Helper

Complete Implementation

// test/helpers/redis.helper.ts
import { Redis } from 'ioredis';

export class RedisTestHelper {
  constructor(private redis: Redis) {}

  /**
   * Clear all keys in current database
   */
  async flushDb(): Promise<void> {
    await this.redis.flushdb();
  }

  /**
   * Clear all keys in all databases
   */
  async flushAll(): Promise<void> {
    await this.redis.flushall();
  }

  /**
   * Set test data with optional TTL
   */
  async setTestData(key: string, value: any, ttl?: number): Promise<void> {
    const serialized = JSON.stringify(value);
    if (ttl) {
      await this.redis.setex(key, ttl, serialized);
    } else {
      await this.redis.set(key, serialized);
    }
  }

  /**
   * Get and parse JSON data
   */
  async getTestData<T>(key: string): Promise<T | null> {
    const value = await this.redis.get(key);
    return value ? JSON.parse(value) : null;
  }

  /**
   * Assert key exists with expected value
   */
  async assertKeyExists(key: string, expectedValue?: any): Promise<void> {
    const exists = await this.redis.exists(key);
    expect(exists).toBe(1);

    if (expectedValue !== undefined) {
      const value = await this.redis.get(key);
      expect(JSON.parse(value!)).toEqual(expectedValue);
    }
  }

  /**
   * Assert key does not exist
   */
  async assertKeyNotExists(key: string): Promise<void> {
    const exists = await this.redis.exists(key);
    expect(exists).toBe(0);
  }

  /**
   * Get TTL for a key
   */
  async getKeyTtl(key: string): Promise<number> {
    return this.redis.ttl(key);
  }

  /**
   * Assert TTL is within expected range
   */
  async assertKeyTtl(
    key: string,
    minTtl: number,
    maxTtl: number
  ): Promise<void> {
    const ttl = await this.redis.ttl(key);
    expect(ttl).toBeGreaterThanOrEqual(minTtl);
    expect(ttl).toBeLessThanOrEqual(maxTtl);
  }

  /**
   * Assert hash field value
   */
  async assertHashField(
    key: string,
    field: string,
    expectedValue: any
  ): Promise<void> {
    const value = await this.redis.hget(key, field);
    expect(JSON.parse(value!)).toEqual(expectedValue);
  }

  /**
   * Assert set contains value
   */
  async assertSetContains(key: string, value: string): Promise<void> {
    const isMember = await this.redis.sismember(key, value);
    expect(isMember).toBe(1);
  }

  /**
   * Assert list length
   */
  async assertListLength(key: string, expectedLength: number): Promise<void> {
    const length = await this.redis.llen(key);
    expect(length).toBe(expectedLength);
  }

  /**
   * Get all keys matching pattern
   */
  async getKeysByPattern(pattern: string): Promise<string[]> {
    return this.redis.keys(pattern);
  }

  /**
   * Delete keys by pattern
   */
  async deleteByPattern(pattern: string): Promise<number> {
    const keys = await this.redis.keys(pattern);
    if (keys.length === 0) return 0;
    return this.redis.del(...keys);
  }
}

Usage Example

describe('Cache E2E', () => {
  let helper: RedisTestHelper;
  let redis: Redis;

  beforeAll(async () => {
    redis = new Redis(process.env.REDIS_URL);
    helper = new RedisTestHelper(redis);
  });

  beforeEach(async () => {
    await helper.flushDb();
  });

  afterAll(async () => {
    await redis.quit();
  });

  it('should cache user profile', async () => {
    // GIVEN: User exists in database
    await userRepository.save({ id: 'user-1', name: 'Test' });

    // WHEN: Fetching user (triggers cache)
    await request(httpServer)
      .get('/users/user-1')
      .expect(200);

    // THEN: Profile cached with TTL
    await helper.assertKeyExists('user:profile:user-1', {
      id: 'user-1',
      name: 'Test',
    });
    await helper.assertKeyTtl('user:profile:user-1', 3500, 3600);
  });
});

API Reference

Method Description
flushDb() Clear all keys in current database
flushAll() Clear all keys in all databases
setTestData(key, value, ttl?) Set JSON data with optional TTL
getTestData(key) Get and parse JSON data
assertKeyExists(key, expected?) Assert key exists with optional value check
assertKeyNotExists(key) Assert key does not exist
getKeyTtl(key) Get TTL for a key
assertKeyTtl(key, min, max) Assert TTL is within range
assertHashField(key, field, value) Assert hash field value
assertSetContains(key, value) Assert set contains value
assertListLength(key, length) Assert list length
getKeysByPattern(pattern) Get keys matching pattern
deleteByPattern(pattern) Delete keys matching pattern

Source: SKILL.md on GitHub

1 alert16d5 checks · Risk SAFE
  • Gen Agent Trust Hub16d

    This skill provides comprehensive workflows and reference materials for E2E testing in TypeScript/NestJS projects. It uses standard development tools like Jest, Docker, and shell commands. No malicious patterns or security risks were detected.

  • Socket16d

    No alerts

  • Snyk16d

    Risk: LOW · No issues

  • Runlayer7mo

    30/103 files flagged

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 3bcc7a6. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 days ago.

Activeupdated 5 months ago
  • TypeScript
  • jest
  • nestjs
  • e2e-testing
  • supertest
  • docker
  • kafka
  • postgres
  • mongodb
  • redis
  • integration-testing
  • gwt-pattern

README badge

README badge for bmad-labs/skills

Writes E2E and integration tests for NestJS projects using Jest and supertest against real Docker infrastructure (Kafka, PostgreSQL, MongoDB, Redis) following the Given-When-Then pattern. Covers test setup, writing, review, debugging, and optimization workflows with technology-specific helpers and isolation strategies for each service.

Generated from the current SKILL.md.

Does this skill work with NestJS only?
The skill is built for NestJS projects using Jest and supertest, but the patterns and workflows apply to any TypeScript backend with HTTP endpoints. Technology-specific helpers exist for Kafka, PostgreSQL, MongoDB, and Redis.
Do I need Docker running to use this skill?
Yes. The skill assumes real infrastructure via Docker (Kafka, PostgreSQL, MongoDB, Redis). Tests execute against actual services, not mocks.
What if my E2E tests are flaky or failing?
The Debugging E2E Test workflow provides a systematic protocol: fix one test at a time using isolated test runs, verify with 3-5 consecutive runs before moving to the next failure, then run the full suite only once all tests pass individually.
Does this skill cover GraphQL or gRPC testing?
Yes. The API testing reference includes examples for REST, GraphQL, and gRPC, plus external API mocking with MSW and Nock.
What is the Given-When-Then pattern and is it mandatory?
GWT is the mandatory test structure: Given describes setup state, When describes the action under test, Then describes expected outcomes. All E2E tests in this skill must follow this pattern.

Generated from the current SKILL.md. These answers refresh after source changes.