shadcn-vue/packages/cli/test/utils/updaters/update-files.test.ts
2024-11-22 15:03:41 +08:00

66 lines
1.4 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { resolveTargetDir } from '../../../src/utils/updaters/update-files'
describe('resolveTargetDir', () => {
it('should handle a home target without a src directory', () => {
const targetDir = resolveTargetDir(
{
isSrcDir: false,
},
{
resolvedPaths: {
cwd: '/foo/bar',
},
},
'~/.env',
)
expect(targetDir).toBe('/foo/bar/.env')
})
it('should handle a home target even with a src directory', () => {
const targetDir = resolveTargetDir(
{
isSrcDir: true,
},
{
resolvedPaths: {
cwd: '/foo/bar',
},
},
'~/.env',
)
expect(targetDir).toBe('/foo/bar/.env')
})
it('should handle a simple target', () => {
const targetDir = resolveTargetDir(
{
isSrcDir: false,
},
{
resolvedPaths: {
cwd: '/foo/bar',
},
},
'./components/ui/button.tsx',
)
expect(targetDir).toBe('/foo/bar/components/ui/button.tsx')
})
it('should handle a simple target with src directory', () => {
const targetDir = resolveTargetDir(
{
isSrcDir: true,
},
{
resolvedPaths: {
cwd: '/foo/bar',
},
},
'./components/ui/button.tsx',
)
expect(targetDir).toBe('/foo/bar/src/components/ui/button.tsx')
})
})