Skip to content

Commit 38879ad

Browse files
committed
test(cli): expand test coverage for constants/paths module
Add tests for: - getSocketAppDataPath - getSocketRegistryPath - getNmBunPath, getNmNpmPath, getNmNodeGypPath, getNmPnpmPath, getNmYarnPath - getSocketCachePath with XDG_CACHE_HOME
1 parent 040f9c9 commit 38879ad

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed

packages/cli/test/unit/constants/paths.test.mts

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,5 +214,103 @@ describe('paths constants', () => {
214214
const result = getSocketCachePath()
215215
expect(result).toContain('socket')
216216
})
217+
218+
it('respects XDG_CACHE_HOME when set', async () => {
219+
const originalXdg = process.env['XDG_CACHE_HOME']
220+
process.env['XDG_CACHE_HOME'] = '/custom/cache'
221+
222+
// Re-import to pick up new env value.
223+
const { getSocketCachePath: getPathFresh } = await import(
224+
'../../../src/constants/paths.mts'
225+
)
226+
const result = getPathFresh()
227+
228+
// Restore.
229+
if (originalXdg === undefined) {
230+
delete process.env['XDG_CACHE_HOME']
231+
} else {
232+
process.env['XDG_CACHE_HOME'] = originalXdg
233+
}
234+
235+
expect(result).toContain('socket')
236+
})
237+
})
238+
239+
describe('getSocketAppDataPath', () => {
240+
it('returns a string or undefined', async () => {
241+
const { getSocketAppDataPath } = await import(
242+
'../../../src/constants/paths.mts'
243+
)
244+
const result = getSocketAppDataPath()
245+
expect(result === undefined || typeof result === 'string').toBe(true)
246+
})
247+
248+
it('includes socket/settings in path when defined', async () => {
249+
const { getSocketAppDataPath } = await import(
250+
'../../../src/constants/paths.mts'
251+
)
252+
const result = getSocketAppDataPath()
253+
if (result !== undefined) {
254+
expect(result).toContain('socket')
255+
expect(result).toContain('settings')
256+
}
257+
})
258+
})
259+
260+
describe('getSocketRegistryPath', () => {
261+
it('returns a path containing registry', async () => {
262+
const { getSocketRegistryPath } = await import(
263+
'../../../src/constants/paths.mts'
264+
)
265+
try {
266+
const result = getSocketRegistryPath()
267+
expect(result).toContain('registry')
268+
} catch (e) {
269+
// Function may throw if app data path cannot be determined.
270+
expect((e as Error).message).toContain('Unable to determine')
271+
}
272+
})
273+
})
274+
275+
describe('getNmBunPath', () => {
276+
it('returns string or undefined', async () => {
277+
const { getNmBunPath } = await import('../../../src/constants/paths.mts')
278+
const result = getNmBunPath()
279+
expect(result === undefined || typeof result === 'string').toBe(true)
280+
})
281+
})
282+
283+
describe('getNmNpmPath', () => {
284+
it('returns a string', async () => {
285+
const { getNmNpmPath } = await import('../../../src/constants/paths.mts')
286+
const result = getNmNpmPath()
287+
expect(typeof result).toBe('string')
288+
})
289+
})
290+
291+
describe('getNmNodeGypPath', () => {
292+
it('returns string or undefined', async () => {
293+
const { getNmNodeGypPath } = await import(
294+
'../../../src/constants/paths.mts'
295+
)
296+
const result = getNmNodeGypPath()
297+
expect(result === undefined || typeof result === 'string').toBe(true)
298+
})
299+
})
300+
301+
describe('getNmPnpmPath', () => {
302+
it('returns string or undefined', async () => {
303+
const { getNmPnpmPath } = await import('../../../src/constants/paths.mts')
304+
const result = getNmPnpmPath()
305+
expect(result === undefined || typeof result === 'string').toBe(true)
306+
})
307+
})
308+
309+
describe('getNmYarnPath', () => {
310+
it('returns string or undefined', async () => {
311+
const { getNmYarnPath } = await import('../../../src/constants/paths.mts')
312+
const result = getNmYarnPath()
313+
expect(result === undefined || typeof result === 'string').toBe(true)
314+
})
217315
})
218316
})

0 commit comments

Comments
 (0)