feat: complete utils test
This commit is contained in:
parent
afcdbf99a3
commit
ef452dfea6
|
|
@ -85,75 +85,76 @@ test('init config-full', async () => {
|
||||||
mockWriteFile.mockRestore()
|
mockWriteFile.mockRestore()
|
||||||
})
|
})
|
||||||
|
|
||||||
// test('init config-partial', async () => {
|
test('init config-partial', async () => {
|
||||||
// vi.spyOn(getPackageManger, 'getPackageManager').mockResolvedValue('npm')
|
vi.spyOn(getPackageManger, 'getPackageManager').mockResolvedValue('npm')
|
||||||
// vi.spyOn(registry, 'getRegistryBaseColor').mockResolvedValue({
|
vi.spyOn(registry, 'getRegistryBaseColor').mockResolvedValue({
|
||||||
// inlineColors: {},
|
inlineColors: {},
|
||||||
// cssVars: {},
|
cssVars: {},
|
||||||
// inlineColorsTemplate:
|
inlineColorsTemplate:
|
||||||
// '@tailwind base;\n@tailwind components;\n@tailwind utilities;\n',
|
'@tailwind base;\n@tailwind components;\n@tailwind utilities;\n',
|
||||||
// cssVarsTemplate:
|
cssVarsTemplate:
|
||||||
// '@tailwind base;\n@tailwind components;\n@tailwind utilities;\n',
|
'@tailwind base;\n@tailwind components;\n@tailwind utilities;\n',
|
||||||
// })
|
})
|
||||||
// const mockMkdir = vi.spyOn(fs.promises, 'mkdir').mockResolvedValue(undefined)
|
const mockMkdir = vi.spyOn(fs.promises, 'mkdir').mockResolvedValue(undefined)
|
||||||
// const mockWriteFile = vi.spyOn(fs.promises, 'writeFile').mockResolvedValue()
|
const mockWriteFile = vi.spyOn(fs.promises, 'writeFile').mockResolvedValue()
|
||||||
|
|
||||||
// const targetDir = path.resolve(__dirname, '../fixtures/config-partial')
|
const targetDir = path.resolve(__dirname, '../fixtures/config-partial')
|
||||||
// const config = await getConfig(targetDir)
|
const config = await getConfig(targetDir)
|
||||||
|
|
||||||
// await runInit(targetDir, config!)
|
await runInit(targetDir, config!)
|
||||||
|
|
||||||
// expect(mockMkdir).toHaveBeenNthCalledWith(
|
expect(mockMkdir).toHaveBeenNthCalledWith(
|
||||||
// 1,
|
1,
|
||||||
// expect.stringMatching(/src\/assets\/css$/),
|
expect.stringMatching(/src\/assets\/css$/),
|
||||||
// expect.anything(),
|
expect.anything(),
|
||||||
// )
|
)
|
||||||
// expect(mockMkdir).toHaveBeenNthCalledWith(
|
expect(mockMkdir).toHaveBeenNthCalledWith(
|
||||||
// 2,
|
2,
|
||||||
// expect.stringMatching(/lib$/),
|
expect.stringMatching(/lib$/),
|
||||||
// expect.anything(),
|
expect.anything(),
|
||||||
// )
|
)
|
||||||
// expect(mockMkdir).toHaveBeenNthCalledWith(
|
expect(mockMkdir).toHaveBeenNthCalledWith(
|
||||||
// 3,
|
3,
|
||||||
// expect.stringMatching(/components$/),
|
expect.stringMatching(/components$/),
|
||||||
// expect.anything(),
|
expect.anything(),
|
||||||
// )
|
)
|
||||||
// expect(mockWriteFile).toHaveBeenNthCalledWith(
|
expect(mockWriteFile).toHaveBeenNthCalledWith(
|
||||||
// 1,
|
1,
|
||||||
// expect.stringMatching(/tailwind.config.ts$/),
|
expect.stringMatching(/tailwind.config.ts$/),
|
||||||
// expect.stringContaining('/** @type {import(\'tailwindcss\').Config} */'),
|
expect.stringContaining('/** @type {import(\'tailwindcss\').Config} */'),
|
||||||
// 'utf8',
|
'utf8',
|
||||||
// )
|
)
|
||||||
// expect(mockWriteFile).toHaveBeenNthCalledWith(
|
expect(mockWriteFile).toHaveBeenNthCalledWith(
|
||||||
// 2,
|
2,
|
||||||
// expect.stringMatching(/src\/assets\/css\/tailwind.css$/),
|
expect.stringMatching(/src\/assets\/css\/tailwind.css$/),
|
||||||
// expect.stringContaining('@tailwind base'),
|
expect.stringContaining('@tailwind base'),
|
||||||
// 'utf8',
|
'utf8',
|
||||||
// )
|
)
|
||||||
// expect(mockWriteFile).toHaveBeenNthCalledWith(
|
expect(mockWriteFile).toHaveBeenNthCalledWith(
|
||||||
// 3,
|
3,
|
||||||
// expect.stringMatching(/utils.ts$/),
|
expect.stringMatching(/utils.ts$/),
|
||||||
// expect.stringContaining('import { type ClassValue, clsx } from "clsx"'),
|
// eslint-disable-next-line @typescript-eslint/quotes
|
||||||
// 'utf8',
|
expect.stringContaining("import { type ClassValue, clsx } from 'clsx'"),
|
||||||
// )
|
'utf8',
|
||||||
// expect(execa).toHaveBeenCalledWith(
|
)
|
||||||
// 'npm',
|
expect(execa).toHaveBeenCalledWith(
|
||||||
// [
|
'npm',
|
||||||
// 'install',
|
[
|
||||||
// 'tailwindcss-animate',
|
'install',
|
||||||
// 'class-variance-authority',
|
'tailwindcss-animate',
|
||||||
// 'clsx',
|
'class-variance-authority',
|
||||||
// 'tailwind-merge',
|
'clsx',
|
||||||
// 'lucide-react',
|
'tailwind-merge',
|
||||||
// ],
|
'lucide-vue-next',
|
||||||
// {
|
],
|
||||||
// cwd: targetDir,
|
{
|
||||||
// },
|
cwd: targetDir,
|
||||||
// )
|
},
|
||||||
|
)
|
||||||
|
|
||||||
// mockMkdir.mockRestore()
|
mockMkdir.mockRestore()
|
||||||
// mockWriteFile.mockRestore()
|
mockWriteFile.mockRestore()
|
||||||
// })
|
})
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
vi.resetAllMocks()
|
vi.resetAllMocks()
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
{
|
{
|
||||||
"style": "default",
|
"style": "default",
|
||||||
"tsx": false,
|
|
||||||
"tailwind": {
|
"tailwind": {
|
||||||
"config": "./tailwind.config.js",
|
"config": "./tailwind.config.js",
|
||||||
"css": "./src/assets/css/tailwind.css",
|
"css": "./src/assets/css/tailwind.css",
|
||||||
|
|
@ -10,5 +9,6 @@
|
||||||
"aliases": {
|
"aliases": {
|
||||||
"utils": "@/lib/utils",
|
"utils": "@/lib/utils",
|
||||||
"components": "@/components"
|
"components": "@/components"
|
||||||
}
|
},
|
||||||
|
"typescript": false
|
||||||
}
|
}
|
||||||
|
|
@ -120,37 +120,39 @@ test('get config', async () => {
|
||||||
typescript: true,
|
typescript: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
// expect(
|
expect(
|
||||||
// await getConfig(path.resolve(__dirname, '../fixtures/config-jsx')),
|
await getConfig(path.resolve(__dirname, '../fixtures/config-js')),
|
||||||
// ).toEqual({
|
).toEqual({
|
||||||
// style: 'default',
|
style: 'default',
|
||||||
// tailwind: {
|
tailwind: {
|
||||||
// config: './tailwind.config.js',
|
config: './tailwind.config.js',
|
||||||
// css: './src/assets/css/tailwind.css',
|
css: './src/assets/css/tailwind.css',
|
||||||
// baseColor: 'neutral',
|
baseColor: 'neutral',
|
||||||
// cssVariables: false,
|
cssVariables: false,
|
||||||
// },
|
},
|
||||||
// aliases: {
|
typescript: false,
|
||||||
// components: '@/components',
|
aliases: {
|
||||||
// utils: '@/lib/utils',
|
components: '@/components',
|
||||||
// },
|
utils: '@/lib/utils',
|
||||||
// resolvedPaths: {
|
},
|
||||||
// tailwindConfig: path.resolve(
|
framework: 'Vite',
|
||||||
// __dirname,
|
resolvedPaths: {
|
||||||
// '../fixtures/config-jsx',
|
tailwindConfig: path.resolve(
|
||||||
// 'tailwind.config.js',
|
__dirname,
|
||||||
// ),
|
'../fixtures/config-js',
|
||||||
// tailwindCss: path.resolve(
|
'tailwind.config.js',
|
||||||
// __dirname,
|
),
|
||||||
// '../fixtures/config-jsx',
|
tailwindCss: path.resolve(
|
||||||
// './src/assets/css/tailwind.css',
|
__dirname,
|
||||||
// ),
|
'../fixtures/config-js',
|
||||||
// components: path.resolve(
|
'./src/assets/css/tailwind.css',
|
||||||
// __dirname,
|
),
|
||||||
// '../fixtures/config-jsx',
|
components: path.resolve(
|
||||||
// './components',
|
__dirname,
|
||||||
// ),
|
'../fixtures/config-js',
|
||||||
// utils: path.resolve(__dirname, '../fixtures/config-jsx', './lib/utils'),
|
'./components',
|
||||||
// },
|
),
|
||||||
// })
|
utils: path.resolve(__dirname, '../fixtures/config-js', './lib/utils'),
|
||||||
|
},
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -6,36 +6,60 @@ test('resolve tree', async () => {
|
||||||
const index = [
|
const index = [
|
||||||
{
|
{
|
||||||
name: 'button',
|
name: 'button',
|
||||||
dependencies: ['@radix-ui/react-slot'],
|
dependencies: ['radix-vue'],
|
||||||
type: 'components:ui',
|
type: 'components:ui',
|
||||||
files: ['button.tsx'],
|
files: [
|
||||||
|
'button/Button.vue',
|
||||||
|
'button/index.ts',
|
||||||
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'dialog',
|
name: 'dialog',
|
||||||
dependencies: ['@radix-ui/react-dialog'],
|
dependencies: ['radix-vue'],
|
||||||
registryDependencies: ['button'],
|
registryDependencies: ['button'],
|
||||||
type: 'components:ui',
|
type: 'components:ui',
|
||||||
files: ['dialog.tsx'],
|
files: ['dialog/Dialog.vue',
|
||||||
|
'dialog/DialogContent.vue',
|
||||||
|
'dialog/DialogDescription.vue',
|
||||||
|
'dialog/DialogFooter.vue',
|
||||||
|
'dialog/DialogHeader.vue',
|
||||||
|
'dialog/DialogTitle.vue',
|
||||||
|
'dialog/DialogTrigger.vue',
|
||||||
|
'dialog/index.ts',
|
||||||
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'input',
|
name: 'input',
|
||||||
registryDependencies: ['button'],
|
registryDependencies: ['button'],
|
||||||
type: 'components:ui',
|
type: 'components:ui',
|
||||||
files: ['input.tsx'],
|
files: [
|
||||||
|
'input/Input.vue',
|
||||||
|
'input/index.ts',
|
||||||
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'alert-dialog',
|
name: 'alert-dialog',
|
||||||
dependencies: ['@radix-ui/react-alert-dialog'],
|
dependencies: ['radix-vue'],
|
||||||
registryDependencies: ['button', 'dialog'],
|
registryDependencies: ['button', 'dialog'],
|
||||||
type: 'components:ui',
|
type: 'components:ui',
|
||||||
files: ['alert-dialog.tsx'],
|
files: ['alert-dialog/AlertDialog.vue',
|
||||||
},
|
'alert-dialog/AlertDialogAction.vue',
|
||||||
{
|
'alert-dialog/AlertDialogCancel.vue',
|
||||||
name: 'example-card',
|
'alert-dialog/AlertDialogContent.vue',
|
||||||
type: 'components:component',
|
'alert-dialog/AlertDialogDescription.vue',
|
||||||
files: ['example-card.tsx'],
|
'alert-dialog/AlertDialogFooter.vue',
|
||||||
registryDependencies: ['button', 'dialog', 'input'],
|
'alert-dialog/AlertDialogHeader.vue',
|
||||||
|
'alert-dialog/AlertDialogTitle.vue',
|
||||||
|
'alert-dialog/AlertDialogTrigger.vue',
|
||||||
|
'alert-dialog/index.ts',
|
||||||
|
],
|
||||||
},
|
},
|
||||||
|
// {
|
||||||
|
// name: 'example-card',
|
||||||
|
// type: 'components:component',
|
||||||
|
// files: ['example-card.tsx'],
|
||||||
|
// registryDependencies: ['button', 'dialog', 'input'],
|
||||||
|
// },
|
||||||
]
|
]
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
|
|
@ -52,11 +76,11 @@ test('resolve tree', async () => {
|
||||||
.sort(),
|
.sort(),
|
||||||
).toEqual(['alert-dialog', 'button', 'dialog'])
|
).toEqual(['alert-dialog', 'button', 'dialog'])
|
||||||
|
|
||||||
expect(
|
// expect(
|
||||||
(await resolveTree(index, ['example-card']))
|
// (await resolveTree(index, ['example-card']))
|
||||||
.map(entry => entry.name)
|
// .map(entry => entry.name)
|
||||||
.sort(),
|
// .sort(),
|
||||||
).toEqual(['button', 'dialog', 'example-card', 'input'])
|
// ).toEqual(['button', 'dialog', 'example-card', 'input'])
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
(await resolveTree(index, ['foo'])).map(entry => entry.name).sort(),
|
(await resolveTree(index, ['foo'])).map(entry => entry.name).sort(),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user