Skip to content
Source
Sign inSign up
TanStack/cli
Open History to see the last commit

shadcn.test.ts

91 lines2.4 KB

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: 'pnpx',
56 args: ['shadcn@latest', 'add', '--silent', '--yes', 'button', 'card'],
57 },
58 ])
59 })
60​
61 it('should add shadcn components in the starter', async () => {
62 const { environment, output } = createMemoryEnvironment()
63 environment.startRun()
64 await installShadcnComponents(environment, '/test', {
65 packageManager: 'pnpm',
66 chosenAddOns: [
67 {
68 id: 'shadcn',
69 },
70 ],
71 projectName: 'test',
72 typescript: true,
73 starter: {
74 shadcnComponents: ['button', 'card'],
75 },
76 spinner: () => ({
77 start: () => {},
78 succeed: () => {},
79 fail: () => {},
80 }),
81 } as unknown as Options)
82 environment.finishRun()
83​
84 expect(output.commands).toEqual([
85 {
86 command: 'pnpx',
87 args: ['shadcn@latest', 'add', '--silent', '--yes', 'button', 'card'],
88 },
89 ])
90 })
91})