npm installnpm testnpm run test:watchnpm run test:coveragesrc/
├── services/
│ ├── __tests__/
│ │ └── KnowledgeGraph.test.ts
│ └── KnowledgeGraph.ts
├── utils/
│ ├── __tests__/
│ │ ├── markdown.test.ts
│ │ └── config.test.ts
│ ├── markdown.ts
│ └── config.ts
└── ...
- markdown.ts: Link extraction, tag extraction, note parsing, serialization, word counting
- config.ts: Configuration validation and example generation
- KnowledgeGraph.ts: Graph building, path finding, related notes, analysis, tag/folder queries
- LocalConnector tests (requires mocking file system)
- RemoteConnector tests (requires mocking HTTP)
- CanvasService tests
- DataviewService tests
- TemplateService tests
- PeriodicNotesService tests
- Branches: 70%
- Functions: 70%
- Lines: 70%
- Statements: 70%
Tests run automatically on:
- Push to
main,master, ordevelopbranches - Pull requests to these branches
GitHub Actions tests on Node.js versions:
- 18.x
- 20.x
- 22.x
import { MyService } from '../MyService.js';
describe('MyService', () => {
let service: MyService;
beforeEach(() => {
service = new MyService();
});
describe('myMethod', () => {
it('should do something', () => {
const result = service.myMethod('input');
expect(result).toBe('expected');
});
it('should handle edge cases', () => {
expect(() => service.myMethod('')).toThrow();
});
});
});- Arrange-Act-Assert pattern
- Test both success and error cases
- Use descriptive test names
- Keep tests isolated and independent
- Mock external dependencies
- Test edge cases and boundary conditions
npm test -- markdown.test.tsnpm test -- --testNamePattern="extractInternalLinks"Add to .vscode/launch.json:
{
"type": "node",
"request": "launch",
"name": "Jest Current File",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"args": [
"${fileBasenameNoExtension}",
"--config",
"jest.config.js"
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
}If you see errors about ESM modules:
- Ensure
"type": "module"is in package.json - Use
.jsextensions in imports - Check jest.config.js has ESM preset
# Rebuild TypeScript
npm run build# Clear Jest cache
npx jest --clearCache- jest: Test framework
- ts-jest: TypeScript support for Jest
- @types/jest: TypeScript types for Jest
See .github/workflows/test.yml for CI configuration.
Add to README:

[](https://codecov.io/gh/YOUR_USERNAME/obsidian-mcp)