Instruction file imported from CardanoTools/aiken-devtools-mcp (
.github/instructions/vitest-tests.instructions.md). Copyright stays with the author.
Vitest Test Guidelines
When writing tests for aiken-devtools-mcp, follow these patterns:
- Use Vitest - This project uses Vitest as the test framework
- Test file naming - Use
*.test.tssuffix for test files - Organize tests - Group related tests using
describe()blocks - Write descriptive test names - Use clear, specific test descriptions with
test()orit() - Use type-safe assertions - Leverage TypeScript types with Vitest's
expect()API - Mock external dependencies - Use Vitest's mocking capabilities for external calls
- Test both success and error cases - Cover happy paths and error scenarios
- Keep tests isolated - Each test should be independent and not rely on other tests' state
- Use beforeEach/afterEach - Set up and clean up test state properly
- Add coverage - Aim for good test coverage, run
npm testto check coverage
Example Test Structure
import { describe, test, expect, beforeEach } from 'vitest';
describe('Aiken Example Tool', () => {
beforeEach(() => {
// Setup test state
});
test('should return success on valid input', async () => {
const result = await exampleFunction({ projectDir: '.' });
expect(result.success).toBe(true);
});
test('should handle errors gracefully', async () => {
const result = await exampleFunction({ projectDir: '/invalid' });
expect(result.success).toBe(false);
expect(result.error).toBeDefined();
});
});