Skip to content

Commit 40beffc

Browse files
committed
test(coverage): cover findSocketYmlSync parse-error path
Adds test for the catch branch (lines 222-228) when socket.yml is present but parseSocketConfig throws on malformed YAML. The function returns ok:false with an "unable to parse" message instead of crashing. config.mts: 92.67% → 94.66% statements (76.13% → 80.68% branch).
1 parent 8b7b41b commit 40beffc

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

packages/cli/test/unit/utils/config.test.mts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,34 @@ describe('utils/config', () => {
207207
await safeDelete(tmpDir, { recursive: true })
208208
}
209209
})
210+
211+
it('returns parse error when socket.yml has invalid YAML (lines 222-228)', async () => {
212+
// Write a socket.yml with garbage YAML content that fails to parse.
213+
const tmpDir = path.resolve(
214+
mkdtempSync(path.join(os.tmpdir(), 'socket-test-')),
215+
)
216+
const socketYmlPath = path.join(tmpDir, 'socket.yml')
217+
const nestedDir = path.join(tmpDir, 'deep', 'nested')
218+
219+
try {
220+
safeMkdirSync(nestedDir, { recursive: true })
221+
// Garbage with conflicting YAML mapping types — parseSocketConfig
222+
// expects an object schema, this will throw.
223+
writeFileSync(
224+
socketYmlPath,
225+
'version: not-a-version\n invalid: ::: garbage\n!!!:\n -- bad',
226+
'utf8',
227+
)
228+
229+
const result = findSocketYmlSync(nestedDir)
230+
expect(result.ok).toBe(false)
231+
if (!result.ok) {
232+
expect(result.message).toContain('unable to parse')
233+
}
234+
} finally {
235+
await safeDelete(tmpDir, { recursive: true })
236+
}
237+
})
210238
})
211239

212240
describe('non-destructive config saving', () => {

0 commit comments

Comments
 (0)