Writes unit tests for vscode-deephaven using Vitest and TypeScript. Use when writing tests, adding unit tests for new features, or verifying service/component behavior. Covers test structure, mocking patterns, parameterized tests, and vscode-deephaven-specific conventions.
Writes unit tests for vscode-deephaven using Vitest and TypeScript. Use when writing tests, adding unit tests for new features, or verifying service/component behavior. Covers test structure, mocking patterns, parameterized tests, and vscode-deephaven-specific conventions.
Test Writing for vscode-deephaven
Running Tests
Use npx vitest run for all test execution. Avoid npm test (starts watch mode).
# Run all tests
npx vitest run
# Run specific test file
npx vitest run src/path/to/file.spec.ts
# Run multiple specific files
npx vitest run src/mcp/tools/getColumnStats.spec.ts src/mcp/tools/getTableStats.spec.ts
Codebase-Specific Conventions
1. Shared VS Code Mocks
Always check __mocks__/vscode.ts before creating new mocks. Read the file to see what's available (e.g., Uri, EventEmitter, DiagnosticCollection, etc.).
Import modules at top of file, not within tests using await import().
4. Prefer it.each for Test Variations
Default to it.each for testing multiple scenarios. This includes cases with different inputs, outputs, mock configurations, or state variations.
When to Use it.each
Use it.each whenever you test the same code path with:
Different input/output pairs
Different mock return values representing state scenarios
Different configuration states (enabled/disabled, connected/disconnected)
Edge cases and boundary conditions
Reference quality checks (same vs different object references)
Key principle: If mocks represent state scenarios that can be expressed as values, use it.each. Don't avoid it just because mocks differ - different mock values are perfect for parameterization.