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