Skip to content

Commit 214c9b6

Browse files
committed
reintroduce test that checks socket continues to work as expected on projects with a socket.yml file
1 parent 3dcacf8 commit 214c9b6

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

src/utils/config.test.mts

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import { mkdtempSync, promises as fs } from 'node:fs'
2+
import os from 'node:os'
13
import path from 'node:path'
24

3-
import { beforeEach, describe, expect, it } from 'vitest'
5+
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
46

57
import {
68
findSocketYmlSync,
@@ -47,15 +49,39 @@ describe('utils/config', () => {
4749
})
4850

4951
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 () => {
5165
// This test ensures we don't regress on the error:
5266
// "Cannot read properties of undefined (reading 'parsed')"
5367
// 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 })
5574

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+
}
5985
})
6086
})
6187
})

0 commit comments

Comments
 (0)