dify/cli/src/sys/index.test.ts
Yunlu Wen c0ee821d45
refactor: use absolute path for inter dir importing (#36822)
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
2026-06-01 01:32:16 +00:00

38 lines
1.0 KiB
TypeScript

import { homedir } from 'node:os'
import { join } from 'node:path'
import { describe, expect, it } from 'vitest'
import { resolvePlatform, SUBDIR } from './index'
describe('resolvePlatform', () => {
it('id matches process.platform', () => {
expect(resolvePlatform().id()).toBe(process.platform)
})
it('configDir ends with the difyctl subdir', () => {
const p = resolvePlatform()
if (p.id() === 'win32') {
expect(p.configDir()).toMatch(/difyctl$/)
}
else {
expect(p.configDir()).toBe(join(homedir(), '.config', SUBDIR))
}
})
it('cacheDir ends with the difyctl subdir', () => {
const p = resolvePlatform()
if (p.id() === 'win32') {
expect(p.cacheDir()).toMatch(/difyctl$/)
}
else if (p.id() === 'darwin') {
expect(p.cacheDir()).toBe(join(homedir(), 'Library', 'Caches', SUBDIR))
}
else {
expect(p.cacheDir()).toBe(join(homedir(), '.cache', SUBDIR))
}
})
it('atomicReplace is a function', () => {
expect(resolvePlatform().atomicReplace).toBeTypeOf('function')
})
})