Open History to see the last commit
1import { describe, expect, it } from 'vitest'
2
3import { createMemoryEnvironment } from '../../src/environment.js'
4import { installShadcnComponents } from '../../src/integrations/shadcn.js'
5
6import type { Options } from '../../src/types.js'
7
8describe('shadcn', () => {
9 it('should skip if no components are selected', async () => {
10 const { environment, output } = createMemoryEnvironment()
11 environment.startRun()
12 await installShadcnComponents(environment, '/test', {
13 packageManager: 'pnpm',
14 chosenAddOns: [],
15 projectName: 'test',
16 typescript: true,
17 spinner: () => ({
18 start: () => {},
19 succeed: () => {},
20 fail: () => {},
21 }),
22 } as unknown as Options)
23 environment.finishRun()
24
25 expect(output.commands).toEqual([])
26 })
27
28 it('should add shadcn components for add-ons', async () => {
29 const { environment, output } = createMemoryEnvironment()
30 environment.startRun()
31 await installShadcnComponents(environment, '/test', {
32 packageManager: 'pnpm',
33 chosenAddOns: [
34 {
35 id: 'shadcn',
36 shadcnComponents: ['button'],
37 },
38 {
39 id: 'test-1',
40 shadcnComponents: ['button', 'card'],
41 },
42 ],
43 projectName: 'test',
44 typescript: true,
45 spinner: () => ({
46 start: () => {},
47 succeed: () => {},
48 fail: () => {},
49 }),
50 } as unknown as Options)
51 environment.finishRun()
52
53 expect(output.commands).toEqual([
54 {
55 command: 'pnpm',
56 args: [
57 'dlx',
58 'shadcn@latest',
59 'add',
60 '--silent',
61 '--yes',
62 'button',
63 'card',
64 ],
65 },
66 ])
67 })
68
69 it('should add shadcn components in the starter', async () => {
70 const { environment, output } = createMemoryEnvironment()
71 environment.startRun()
72 await installShadcnComponents(environment, '/test', {
73 packageManager: 'pnpm',
74 chosenAddOns: [
75 {
76 id: 'shadcn',
77 },
78 ],
79 projectName: 'test',
80 typescript: true,
81 starter: {
82 shadcnComponents: ['button', 'card'],
83 },
84 spinner: () => ({
85 start: () => {},
86 succeed: () => {},
87 fail: () => {},
88 }),
89 } as unknown as Options)
90 environment.finishRun()
91
92 expect(output.commands).toEqual([
93 {
94 command: 'pnpm',
95 args: [
96 'dlx',
97 'shadcn@latest',
98 'add',
99 '--silent',
100 '--yes',
101 'button',
102 'card',
103 ],
104 },
105 ])
106 })
107})