-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathconfig.test.mts
More file actions
97 lines (85 loc) · 2.92 KB
/
config.test.mts
File metadata and controls
97 lines (85 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import {
promises as fs,
mkdtempSync,
readFileSync,
rmSync,
writeFileSync,
} from 'node:fs'
import os from 'node:os'
import path from 'node:path'
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
import {
findSocketYmlSync,
getConfigValue,
overrideCachedConfig,
resetConfigForTesting,
updateConfigValue,
} from './config.mts'
import { testPath } from '../../test/utils.mts'
import type { LocalConfig } from './config.mts'
const fixtureBaseDir = path.join(testPath, 'fixtures/utils/config')
describe('utils/config', () => {
describe('updateConfigValue', () => {
beforeEach(() => {
overrideCachedConfig({})
})
it('should return object for applying a change', () => {
expect(
updateConfigValue('defaultOrg', 'fake_test_org'),
).toMatchInlineSnapshot(`
{
"data": "Change applied but not persisted; current config is overridden through env var or flag",
"message": "Config key 'defaultOrg' was updated",
"ok": true,
}
`)
})
it('should warn for invalid key', () => {
expect(
updateConfigValue(
// @ts-ignore
'nawthiswontwork',
'fake_test_org',
),
).toMatchInlineSnapshot(`
{
"data": undefined,
"message": "Invalid config key: nawthiswontwork",
"ok": false,
}
`)
})
})
describe('findSocketYmlSync', () => {
it('should find socket.yml when walking up directory tree', () => {
// This test verifies that findSocketYmlSync correctly walks up the directory
// tree and finds socket.yml at the repository root.
const result = findSocketYmlSync(path.join(fixtureBaseDir, 'nonexistent'))
// The result should be ok and find the root socket.yml.
expect(result.ok).toBe(true)
expect(result.data).toBeDefined()
expect(result.data?.parsed).toBeDefined()
expect(result.data?.path).toContain('socket.yml')
})
it('should handle when no socket.yml exists (regression test for .parsed access)', async () => {
// This test ensures we don't regress on the error:
// "Cannot read properties of undefined (reading 'parsed')"
// when socketYmlResult.data is undefined.
//
// Create an isolated temporary directory outside the repository.
// This ensures no parent directories contain socket.yml.
const tmpDir = mkdtempSync(path.join(os.tmpdir(), 'socket-test-'))
const isolatedDir = path.join(tmpDir, 'deep', 'nested', 'directory')
await fs.mkdir(isolatedDir, { recursive: true })
try {
const result = findSocketYmlSync(isolatedDir)
// The result should be ok but with undefined data.
expect(result.ok).toBe(true)
expect(result.data).toBe(undefined)
} finally {
// Clean up the temporary directory.
rmSync(tmpDir, { force: true, recursive: true })
}
})
})
})