|
| 1 | +import { mkdtempSync, promises as fs } from 'node:fs' |
| 2 | +import os from 'node:os' |
1 | 3 | import path from 'node:path' |
2 | 4 |
|
3 | | -import { beforeEach, describe, expect, it } from 'vitest' |
| 5 | +import { afterEach, beforeEach, describe, expect, it } from 'vitest' |
4 | 6 |
|
5 | 7 | import { |
6 | 8 | findSocketYmlSync, |
@@ -47,15 +49,39 @@ describe('utils/config', () => { |
47 | 49 | }) |
48 | 50 |
|
49 | 51 | describe('findSocketYmlSync', () => { |
50 | | - it('should handle when no socket.yml exists (regression test for .parsed access)', () => { |
| 52 | + it('should find socket.yml when walking up directory tree', () => { |
| 53 | + // This test verifies that findSocketYmlSync correctly walks up the directory |
| 54 | + // tree and finds socket.yml at the repository root. |
| 55 | + const result = findSocketYmlSync(path.join(fixtureBaseDir, 'nonexistent')) |
| 56 | + |
| 57 | + // The result should be ok and find the root socket.yml. |
| 58 | + expect(result.ok).toBe(true) |
| 59 | + expect(result.data).toBeDefined() |
| 60 | + expect(result.data?.parsed).toBeDefined() |
| 61 | + expect(result.data?.path).toContain('socket.yml') |
| 62 | + }) |
| 63 | + |
| 64 | + it('should handle when no socket.yml exists (regression test for .parsed access)', async () => { |
51 | 65 | // This test ensures we don't regress on the error: |
52 | 66 | // "Cannot read properties of undefined (reading 'parsed')" |
53 | 67 | // when socketYmlResult.data is undefined. |
54 | | - const result = findSocketYmlSync(path.join(fixtureBaseDir, 'nonexistent')) |
| 68 | + // |
| 69 | + // Create an isolated temporary directory outside the repository. |
| 70 | + // This ensures no parent directories contain socket.yml. |
| 71 | + const tmpDir = mkdtempSync(path.join(os.tmpdir(), 'socket-test-')) |
| 72 | + const isolatedDir = path.join(tmpDir, 'deep', 'nested', 'directory') |
| 73 | + await fs.mkdir(isolatedDir, { recursive: true }) |
55 | 74 |
|
56 | | - // The result should be ok but with undefined data. |
57 | | - expect(result.ok).toBe(true) |
58 | | - expect(result.data).toBe(undefined) |
| 75 | + try { |
| 76 | + const result = findSocketYmlSync(isolatedDir) |
| 77 | + |
| 78 | + // The result should be ok but with undefined data. |
| 79 | + expect(result.ok).toBe(true) |
| 80 | + expect(result.data).toBe(undefined) |
| 81 | + } finally { |
| 82 | + // Clean up the temporary directory. |
| 83 | + await fs.rm(tmpDir, { force: true, recursive: true }) |
| 84 | + } |
59 | 85 | }) |
60 | 86 | }) |
61 | 87 | }) |
0 commit comments