|
5 | 5 | */ |
6 | 6 |
|
7 | 7 | import { describe, it, expect, afterEach, vi } from 'vitest'; |
| 8 | +import * as path from 'node:path'; |
8 | 9 | import { |
9 | 10 | getTokenAtCursor, |
10 | 11 | escapeShellPath, |
@@ -382,15 +383,28 @@ describe('useShellCompletion utilities', () => { |
382 | 383 |
|
383 | 384 | describe('scanPathExecutables', () => { |
384 | 385 | it('should return an array of executables', async () => { |
385 | | - const results = await scanPathExecutables(); |
386 | | - expect(Array.isArray(results)).toBe(true); |
387 | | - // Very basic sanity check: common commands should be found |
388 | | - if (process.platform !== 'win32') { |
389 | | - expect(results).toContain('ls'); |
390 | | - } else { |
391 | | - expect(results).toContain('dir'); |
392 | | - expect(results).toContain('cls'); |
393 | | - expect(results).toContain('copy'); |
| 386 | + const isWin = process.platform === 'win32'; |
| 387 | + const exeName = isWin ? 'my-test-exe.exe' : 'my-test-exe'; |
| 388 | + const structure: FileSystemStructure = { |
| 389 | + [exeName]: '', |
| 390 | + }; |
| 391 | + const testTmpDir = await createTmpDir(structure); |
| 392 | + |
| 393 | + // Make it executable on non-Windows |
| 394 | + if (!isWin) { |
| 395 | + const fsPromises = await import('node:fs/promises'); |
| 396 | + await fsPromises.chmod(path.join(testTmpDir, exeName), 0o755); |
| 397 | + } |
| 398 | + |
| 399 | + vi.stubEnv('PATH', testTmpDir); |
| 400 | + |
| 401 | + try { |
| 402 | + const results = await scanPathExecutables(); |
| 403 | + expect(Array.isArray(results)).toBe(true); |
| 404 | + expect(results).toContain(isWin ? 'my-test-exe.exe' : 'my-test-exe'); |
| 405 | + } finally { |
| 406 | + await cleanupTmpDir(testTmpDir); |
| 407 | + vi.unstubAllEnvs(); |
394 | 408 | } |
395 | 409 | }); |
396 | 410 |
|
|
0 commit comments