testing-strategy

Design testing patterns for Node.js/TypeScript applications using Vitest.

Updated Mar 8, 2026
One-click install
npx skills add https://github.com/AndreaCadonna/sbobuz-web-game-app --skill testing-strategy-andreacadonna
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: testing-strategy
Source: https://github.com/AndreaCadonna/sbobuz-web-game-app/tree/main/skills/testing-strategy
Command: npx skills add https://github.com/AndreaCadonna/sbobuz-web-game-app --skill testing-strategy-andreacadonna

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Teams struggle to keep tests fast, reliable, and well-scoped across unit, integration, and end-to-end levels; this guidance codifies patterns to reduce flakiness, speed feedback loops, and ensure meaningful coverage for Node.js/TypeScript applications using Vitest.

Core Features & Use Cases

  • Test Pyramid Guidance: Clear distinctions between unit, integration, and E2E tests with recommendations on count, speed, and dependencies.
  • Unit Test Conventions: Colocated *.test.ts files, pure-function focus, and helper utilities to build concise, deterministic tests.
  • Integration Test Patterns: Test DB lifecycle, fixtures, truncation between tests, and serial execution recommendations for shared resources.
  • Mocking Strategy: When to mock I/O boundaries, how to use vi.mock and fake timers, and guidance to avoid over-mocking.
  • Vitest Configuration & Coverage: Sample vitest configs, separate integration config, and coverage thresholds to enforce quality.
  • Flaky Test Mitigation: Checklist for race conditions, time dependencies, shared state, and randomization fixes.

Quick Start

Run unit tests with Vitest and run integration tests using the vitest.integration.config.ts while starting the test database fixtures defined in tests/integration/setup.ts.

Frequently Asked Questions about testing-strategy

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I organize unit and integration tests in Vitest for a Node.js app?

Structure unit tests by colocating *.test.ts files next to source code, and run integration tests using a separate vitest.integration.config.ts file. This separation isolates fast, deterministic unit tests from slower integration tests that require database fixtures and lifecycle management.

What is the best mocking strategy for Vitest to avoid flaky tests?

The best mocking strategy for Vitest is to mock I/O boundaries with vi.mock and fake timers while avoiding over-mocking internal logic. This maintains determinism and prevents flaky tests caused by race conditions, time dependencies, and shared state.

How do I set up a test database for Vitest integration tests in Node.js?

Set up a test database for Vitest integration tests by defining fixtures in tests/integration/setup.ts and executing tests serially. Truncate data between runs to manage the test lifecycle, ensuring a clean database state and preventing shared resource conflicts.

What are the recommended coverage thresholds for Vitest in a TypeScript project?

Configure coverage thresholds directly within the vitest config file to enforce quality metrics for your TypeScript project. Setting explicit limits ensures meaningful coverage across unit and integration suites, preventing superficial tests from passing continuous integration checks.

Why does my Vitest test suite have flaky tests and how do I fix them?

Flaky Vitest tests are usually caused by race conditions, time dependencies, shared state, or randomization. Fix them by applying a mitigation checklist to isolate shared state, apply fake timers, remove time dependencies, and ensure deterministic test execution.

Does Vitest support separate configurations for unit and integration testing in Node.js?

Yes, Vitest supports separate configurations by using distinct files like vitest.integration.config.ts for integration tests. This allows different lifecycle setups, coverage thresholds, and serial execution rules for shared resources compared to standard unit tests.