UNPKG

bg-server-mcp-shell

Version:

MCP server for shell - PTY with live streaming for long-running processes (dev servers, watch modes, docker-compose, etc.)

158 lines (119 loc) โ€ข 4.47 kB
Documentations : [Main](../README.md) | [Tests](README.md) # ๐Ÿงช Tests Documentation ## ๐Ÿš€ Quick Start ```bash # All tests (~7s) npm test # Fast unit tests (~1s, for development) npm run test:unit # Integration tests only (~6s) npm run test:integration # Watch mode (TDD) npm run test:watch # Verbose output (for debugging) npm run test:verbose ``` ## ๐Ÿ“Š Test Commands | Command | Tests | Time | Use Case | |---------|-------|------|----------| | `npm test` | All (20) | ~7s | Before commit, CI/CD | | `npm run test:unit` | Unit (12) | ~1s | Feature development | | `npm run test:integration` | Integration (8) | ~6s | End-to-end testing | | `npm run test:watch` | All | โˆž | Active development (TDD) | | `npm run test:verbose` | All | ~7s | Debugging failures | ## ๐Ÿ—๏ธ Test Structure ``` tests/ โ”œโ”€โ”€ tests-run.sh # ๐Ÿš€ Test runner helper โ”œโ”€โ”€ README.md # ๐Ÿ“– This documentation โ”œโ”€โ”€ unit/ # Unit tests (~1s) โ”‚ โ”œโ”€โ”€ spawn-helper.test.js # PTY spawn function โ”‚ โ””โ”€โ”€ tools/ โ”‚ โ”œโ”€โ”€ process.test.js # startProcessAndWait, startProcessBackground โ”‚ โ”œโ”€โ”€ sessions.test.js # listSessions, getSessionOutput, cleanupSessions โ”‚ โ””โ”€โ”€ control.test.js # writeInput, stopProcess โ””โ”€โ”€ integration/ # Integration tests (~6s) โ””โ”€โ”€ mcp-server.test.js # End-to-end MCP server tests ``` ## ๐Ÿ“Š Test Coverage | MCP Function | Test File | Coverage | |-------------|-----------|----------| | `startProcessAndWait` | `unit/tools/process.test.js` | Execution, exit codes, timeouts | | `startProcessBackground` | `unit/tools/process.test.js` | Non-blocking, session creation | | `listSessions` | `unit/tools/sessions.test.js` | Empty list, active sessions, status | | `getSessionOutput` | `unit/tools/sessions.test.js` | Output retrieval, fromIndex | | `cleanupSessions` | `unit/tools/sessions.test.js` | Single/bulk cleanup | | `writeInput` | `unit/tools/control.test.js` | Input handling, unicode | | `stopProcess` | `unit/tools/control.test.js` | Termination, session preservation | | `spawnPtyProcess` | `unit/spawn-helper.test.js` | PTY spawning, env vars, cross-platform | | End-to-end | `integration/mcp-server.test.js` | MCP protocol, real workflows | ## ๐Ÿ’ก Common Workflows ```bash # Development workflow npm run test:watch # Auto-run tests on changes npm run test:unit # Fast feedback during coding npm run test:verbose # Debug failures # Before commit npm test # Run all tests # Specific tests npm run test:run file sessions # Test one file npm run test:run func cleanup # Test by pattern ``` ## ๐Ÿ” Debugging ```javascript // Run only specific test it.only('should return empty array', async () => { /* ... */ }); // Run only specific suite describe.only('listSessions', () => { /* ... */ }); ``` ```bash # Verbose output npm run test:verbose # Node debugger node --inspect-brk --test tests/unit/tools/sessions.test.js # Then open chrome://inspect ``` ## ๐Ÿ“ Writing Tests **Framework:** Node.js native test runner (`node:test`) - no external dependencies ```javascript import { describe, it, before, after } from 'node:test'; import assert from 'node:assert'; describe('My Feature', () => { before(async () => { /* setup */ }); after(() => { /* cleanup */ }); it('should do something', async () => { const result = await myFunction(); assert.strictEqual(result, 'expected'); }); }); ``` **Best practices:** - Use `strictEqual`, not `equal` - Always await promises - Clean up resources in `after()` hooks - Keep tests isolated and independent ## ๐Ÿ“ˆ CI/CD ```yaml # GitHub Actions name: Tests on: [push, pull_request] jobs: test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: node-version: '18' - run: npm install - run: npm test ``` ## ๐Ÿ“š Resources - [Node.js Test Runner](https://nodejs.org/api/test.html) - [MCP Protocol](https://modelcontextprotocol.io) - [node-pty](https://github.com/microsoft/node-pty) ## ๐Ÿงช Development Found a bug or have a feature request? Please report it on GitHub: **[Report an Issue](https://github.com/bgbruno/bg-server-mcp-shell/issues)** ## ๐Ÿ“„ License MIT ยฉ [Bruno Garret](https://bgbruno.com)