testing-guidelines

bởi sentry

Hướng dẫn viết bài kiểm thử. Sử dụng khi thêm chức năng mới, sửa lỗi hoặc khi cần kiểm thử. Nhấn mạnh vào kiểm thử tích hợp, các fixture thực tế và…

npx skills add https://github.com/getsentry/warden --skill testing-guidelines

Testing Guidelines

Follow these principles when writing tests for this codebase.

Core Principles

1. Mock External Services, Use Real Fixtures

ALWAYS mock third-party network services. ALWAYS use fixtures based on real-world data.

  • Fixtures must be scrubbed of PII (use dummy data like foo@example.com, user-123)
  • Capture real API responses, then sanitize them
  • Never make actual network calls in tests

2. Prefer Integration Tests Over Unit Tests

Focus on end-to-end style tests that validate inputs and outputs, not implementation details.

  • Test the public interface, not internal methods
  • Unit tests are valuable for edge cases in pure functions, but integration tests are the priority
  • If refactoring breaks tests but behavior is unchanged, the tests were too coupled to implementation

3. Minimize Edge Case Testing

Don't test every variant of a problem.

  • Cover the common path thoroughly
  • Skip exhaustive input permutations
  • Skip unlikely edge cases that add maintenance burden without value
  • One representative test per category of input is usually sufficient

4. Always Add Regression Tests for Bugs

When a bug is identified, ALWAYS add a test that would have caught it.

  • The test should fail before the fix and pass after
  • Name it descriptively to document the bug
  • This prevents the same bug from recurring

Note: Regression tests are for unintentional broken behavior (bugs), not intentional changes. Intentional feature removals, deprecations, or breaking changes do NOT need regression tests—these are design decisions, not defects.

5. Cover Every User Entry Point

ALWAYS have at least one basic test for each customer/user entry point.

  • CLI commands, API endpoints, public/exported functions
  • Test the common/happy path first
  • This proves the entry point works at all

Note: "Entry point" means the public interface—exported functions, CLI commands, API routes. Internal/private functions are NOT entry points, even if they handle user-facing flags or options. Test entry points; internal functions get coverage through those tests.

6. Tests Validate Before Manual QA

Tests are how we validate ANY functionality works before manual testing.

  • Write tests first or alongside code, not as an afterthought
  • If you can't test it, reconsider the design
  • Passing tests should give confidence to ship

Technical Guidelines

File Organization

  • Test files use *.test.ts extension
  • Co-locate tests with source: foo.ts → foo.test.ts

Test Isolation

Every test must:

  • Run independently without affecting other tests
  • Use temporary directories for file operations
  • Clean up resources in afterEach hooks
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
import { mkdirSync, rmSync, writeFileSync } from 'node:fs';
import { join } from 'node:path';
import { tmpdir } from 'node:os';

describe('my feature', () => {
  let tempDir: string;

  beforeEach(() => {
    tempDir = join(tmpdir(), `warden-test-${Date.now()}`);
    mkdirSync(tempDir, { recursive: true });
  });

  afterEach(() => {
    rmSync(tempDir, { recursive: true, force: true });
  });

  it('does something with files', () => {
    writeFileSync(join(tempDir, 'test.ts'), 'content');
    // ... test code
  });
});

Pure Function Tests

For pure functions without side effects, no special setup is needed:

import { describe, it, expect } from 'vitest';
import { matchGlob } from './matcher.js';

describe('matchGlob', () => {
  it('matches exact paths', () => {
    expect(matchGlob('src/index.ts', 'src/index.ts')).toBe(true);
  });
});

Running Tests

pnpm test              # Run all tests in watch mode
pnpm test:run          # Run all tests once

Checklist Before Submitting

  • New entry points have at least one happy-path test
  • Bug fixes (not intentional changes) include a regression test
  • External services are mocked with sanitized fixtures
  • Tests validate behavior, not implementation
  • No shared state between tests

Thêm skills từ sentry

add-ai-integration
sentry
Thêm tích hợp nhà cung cấp AI mới vào Sentry JavaScript SDK. Sử dụng khi đóng góp một công cụ đo lường AI mới (OpenAI, Anthropic, Vercel AI, LangChain, v.v.)…
add-cdn-bundle
sentry
Tạo một gói CDN mới cho trình duyệt với các tính năng được chỉ định
agent-prompt
sentry
Hướng dẫn tham khảo để viết các prompt và kỹ năng agent hiệu quả. Sử dụng khi tạo kỹ năng mới
agents-md
sentry
Kỹ năng này nên được sử dụng khi người dùng yêu cầu "tạo AGENTS.md", "cập nhật AGENTS.md", "bảo trì tài liệu agent", "thiết lập CLAUDE.md", hoặc cần duy trì agent…
agents-md
sentry
Tạo và duy trì tài liệu agent tối giản, tín hiệu cao dưới 60 dòng. Áp dụng các phương pháp tốt nhất dựa trên nghiên cứu cho tài liệu hướng đến agent; chất lượng hướng dẫn giảm dần theo độ dài. Yêu cầu ba phần chính: Package Manager, File-Scoped Commands (kiểm
agents-md
sentry
Kỹ năng này nên được sử dụng khi người dùng yêu cầu "tạo AGENTS.md", "cập nhật AGENTS.md", "duy trì tài liệu agent", "thiết lập CLAUDE.md", hoặc cần giữ cho agent…
ai-sdk
sentry
ai-sdk — một kỹ năng có thể cài đặt cho các tác nhân AI, được xuất bản bởi getsentry/webvitals.com.
analytics
sentry
Công cụ và khám phá các sự kiện analytics trong giao diện người dùng của Sentry. Sử dụng khi thêm theo dõi vào các nút, trang, cửa sổ modal hoặc tương tác tùy chỉnh, khi định nghĩa mới…