Chat
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data โ all from the browser, and deployed in milliseconds.
Viewing readonly version of main branch: v1234View latest version
This directory contains the test suite for the Anthropic Streaming Chat MCP application.
test/
โโโ components/ # Component tests
โ โโโ Message.test.tsx # Message component tests
โโโ utils/ # Test utilities and helpers
โ โโโ test-helpers.ts # Common test utilities
โโโ setup.ts # Global test setup and configuration
โโโ README.md # This file
# Run all tests npm test # Run tests in watch mode (re-runs on file changes) npm run test:watch # Run tests with coverage npm run test:coverage # Generate HTML coverage report npm run test:coverage-report
# Run all tests deno test --allow-all test/ # Run tests in watch mode deno test --allow-all --watch test/ # Run specific test file deno test --allow-all test/components/Message.test.tsx # Run tests with coverage deno test --allow-all --coverage=coverage test/ deno coverage coverage --html
- Message.test.tsx: Tests for the Message component including:
- Basic rendering with different message types
- Block content rendering (text, code, MCP tools)
- Action button functionality
- Props validation
- test-helpers.ts: Common utilities for creating mock data and assertions
- setup.ts: Global test configuration and environment setup
import { assertEquals, assertExists } from "https://deno.land/std@0.208.0/assert/mod.ts";
import { render, cleanup } from "https://esm.sh/@testing-library/react@14.0.0?deps=react@18.2.0,react-dom@18.2.0";
Deno.test("Component Name - Test Category", async (t) => {
await t.step("should do something specific", () => {
// Test implementation
});
// Cleanup after test
cleanup();
});
import { createMockMessage, createMockCallback } from "../utils/test-helpers.ts";
// Create mock data
const message = createMockMessage({
role: "assistant",
content: "Test content"
});
// Create mock callbacks
const mockOnDelete = createMockCallback();
The test environment includes:
- React Testing Library: For component testing
- Deno Standard Library: For assertions
- Mock DOM: Simulated browser environment
- Mock APIs: localStorage, fetch, crypto.randomUUID
- Test Helpers: Utilities for creating mock data
Test coverage reports are generated in the coverage/
directory when running coverage commands. The HTML report provides detailed information about:
- Line coverage
- Function coverage
- Branch coverage
- Uncovered code sections
- Test Structure: Use descriptive test names and group related tests
- Cleanup: Always cleanup after component tests
- Mocking: Use provided test helpers for consistent mock data
- Assertions: Use specific assertions that clearly indicate what's being tested
- Isolation: Each test should be independent and not rely on other tests
- Create test files in the appropriate subdirectory
- Follow the naming convention:
ComponentName.test.tsx
- Import necessary testing utilities
- Use the established test structure and helpers
- Add cleanup calls for component tests
- Update this README if adding new test categories
- Import Errors: Ensure all imports use the correct ESM URLs with React version pinning
- Component Not Rendering: Check that all required props are provided
- Mock Issues: Verify that mocks are properly set up in setup.ts
- Timeout Errors: Increase timeout in test configuration if needed
- Use
console.log
in tests to debug values - Check the HTML output with
container.innerHTML
- Verify mock function calls with
mockFn.calls
- Use
--inspect
flag with Deno for debugging