|
| 1 | +import { describe, it, expect } from 'vitest'; |
| 2 | + |
| 3 | +import environmentResource from '../environment.js'; |
| 4 | +import { createMockExecutor } from '../../../utils/command.js'; |
| 5 | + |
| 6 | +describe('environment resource', () => { |
| 7 | + describe('Export Field Validation', () => { |
| 8 | + it('should export correct uri', () => { |
| 9 | + expect(environmentResource.uri).toBe('xcodebuildmcp://environment'); |
| 10 | + }); |
| 11 | + |
| 12 | + it('should export correct description', () => { |
| 13 | + expect(environmentResource.description).toBe( |
| 14 | + 'Comprehensive development environment diagnostic information and configuration status', |
| 15 | + ); |
| 16 | + }); |
| 17 | + |
| 18 | + it('should export correct mimeType', () => { |
| 19 | + expect(environmentResource.mimeType).toBe('text/plain'); |
| 20 | + }); |
| 21 | + |
| 22 | + it('should export handler function', () => { |
| 23 | + expect(typeof environmentResource.handler).toBe('function'); |
| 24 | + }); |
| 25 | + }); |
| 26 | + |
| 27 | + describe('Handler Functionality', () => { |
| 28 | + it('should handle successful environment data retrieval', async () => { |
| 29 | + const mockExecutor = createMockExecutor({ |
| 30 | + success: true, |
| 31 | + output: 'Mock command output', |
| 32 | + }); |
| 33 | + |
| 34 | + const result = await environmentResource.handler( |
| 35 | + new URL('xcodebuildmcp://environment'), |
| 36 | + mockExecutor, |
| 37 | + ); |
| 38 | + |
| 39 | + expect(result.contents).toHaveLength(1); |
| 40 | + expect(result.contents[0].text).toContain('# XcodeBuildMCP Diagnostic Report'); |
| 41 | + expect(result.contents[0].text).toContain('## System Information'); |
| 42 | + expect(result.contents[0].text).toContain('## Node.js Information'); |
| 43 | + expect(result.contents[0].text).toContain('## Dependencies'); |
| 44 | + expect(result.contents[0].text).toContain('## Environment Variables'); |
| 45 | + expect(result.contents[0].text).toContain('## Feature Status'); |
| 46 | + }); |
| 47 | + |
| 48 | + it('should handle spawn errors by showing diagnostic info', async () => { |
| 49 | + const mockExecutor = createMockExecutor(new Error('spawn xcrun ENOENT')); |
| 50 | + |
| 51 | + const result = await environmentResource.handler( |
| 52 | + new URL('xcodebuildmcp://environment'), |
| 53 | + mockExecutor, |
| 54 | + ); |
| 55 | + |
| 56 | + expect(result.contents).toHaveLength(1); |
| 57 | + expect(result.contents[0].text).toContain('# XcodeBuildMCP Diagnostic Report'); |
| 58 | + expect(result.contents[0].text).toContain('Error: spawn xcrun ENOENT'); |
| 59 | + }); |
| 60 | + |
| 61 | + it('should include required diagnostic sections', async () => { |
| 62 | + const mockExecutor = createMockExecutor({ |
| 63 | + success: true, |
| 64 | + output: 'Mock output', |
| 65 | + }); |
| 66 | + |
| 67 | + const result = await environmentResource.handler( |
| 68 | + new URL('xcodebuildmcp://environment'), |
| 69 | + mockExecutor, |
| 70 | + ); |
| 71 | + |
| 72 | + expect(result.contents[0].text).toContain('## Troubleshooting Tips'); |
| 73 | + expect(result.contents[0].text).toContain('brew tap cameroncooke/axe'); |
| 74 | + expect(result.contents[0].text).toContain('INCREMENTAL_BUILDS_ENABLED=1'); |
| 75 | + expect(result.contents[0].text).toContain('discover_tools'); |
| 76 | + }); |
| 77 | + |
| 78 | + it('should provide feature status information', async () => { |
| 79 | + const mockExecutor = createMockExecutor({ |
| 80 | + success: true, |
| 81 | + output: 'Mock output', |
| 82 | + }); |
| 83 | + |
| 84 | + const result = await environmentResource.handler( |
| 85 | + new URL('xcodebuildmcp://environment'), |
| 86 | + mockExecutor, |
| 87 | + ); |
| 88 | + |
| 89 | + expect(result.contents[0].text).toContain('### UI Automation (axe)'); |
| 90 | + expect(result.contents[0].text).toContain('### Incremental Builds'); |
| 91 | + expect(result.contents[0].text).toContain('### Mise Integration'); |
| 92 | + expect(result.contents[0].text).toContain('## Tool Availability Summary'); |
| 93 | + }); |
| 94 | + |
| 95 | + it('should handle error conditions gracefully', async () => { |
| 96 | + const mockExecutor = createMockExecutor({ |
| 97 | + success: false, |
| 98 | + output: '', |
| 99 | + error: 'Command failed', |
| 100 | + }); |
| 101 | + |
| 102 | + const result = await environmentResource.handler( |
| 103 | + new URL('xcodebuildmcp://environment'), |
| 104 | + mockExecutor, |
| 105 | + ); |
| 106 | + |
| 107 | + expect(result.contents).toHaveLength(1); |
| 108 | + expect(result.contents[0].text).toContain('# XcodeBuildMCP Diagnostic Report'); |
| 109 | + }); |
| 110 | + }); |
| 111 | +}); |
0 commit comments