This document provides agent guidance on testing procedures and standards for the PatternFly MCP codebase.
High - This document should be processed when working with tests or implementing changes that require testing.
See the Guidelines Index for a complete list of all guidelines.
Refer to testing standards for project-wide requirements.
- Unit Tests (
src/__tests__/*.test.ts): Focus on individual module logic, helpers, and creator functions. - E2E Tests (
tests/*.test.ts): Validate full server lifecycle, transport (stdio/http), and tool/resource execution. - Integration Tests (
npm run test:integration): Verify interactions between server components.
-
Focus on Behavior: Test what the user (MCP client) observes. Verify that tools return the expected content and errors. See functionality and testing guidance.
-
Pragmatic Typings: Explicit
anyis allowed in tests to avoid over-modeling mocks and stubs. Avoid "type threading" in tests; do not attempt to perfectly type every mock. Focus on validating observable behavior. Use lightweight local type aliases if needed. -
Don't Test Dependencies: Assume
@patternflypackages and the MCP SDK work as intended. Test our integration and custom logic. -
Reproducers Required: Every bug fix must include a test case that reproduces the issue and verifies the fix.
-
Suggestive Failure: Tools should be tested for "suggestive failure". If a resource is not found, the tool should attempt to suggest the closest match using available metadata or fuzzy matching.
Test Example:
it('returns suggestions for misspelled component name', async () => { const tool = usePatternFlyDocsTool(); const result = tool[2]({ name: 'ton' }); // Misspelling "Button" await expect(result).rejects.toThrow(/Did you mean "Button"?/); });
- Jest Mocks: Use
jest.mock()for file system (node:fs/promises) and network (fetch) operations. - Snapshot Testing: Use
toMatchSnapshot()for large or complex tool outputs (e.g., documentation processing results). - Snapshot Verification: Always inspect snapshot changes. Only update snapshots (
-u) if the change is intentional and correct. - Mocking MCP SDK: When testing server startup, mocks should simulate transport behavior without requiring actual network/IPC overhead where possible.
- Happy Path: Verify standard tool/resource usage works as expected.
- Error Handling: Verify that invalid parameters, missing files, and network failures return user-friendly error messages (e.g., "Did you mean 'Button'?").
- Edge Cases: Test empty inputs, extreme
maxDocsToLoadvalues, and complex URL patterns. - Security: Verify that
resolveLocalPathFunctioncorrectly prevents path traversal.
- Unit Tests:
npm test - E2E/Integration:
npm run test:integration - Manual Verification: Use the MCP Inspector to manually verify tool and resource behavior.
- Coverage: Ensure new logic is covered by at least one unit test.