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

intent.test.ts

64 lines2.0 KB

1import { describe, expect, it } from 'vitest'
2import { createMemoryEnvironment } from '../../src/environment.js'
3import { setupIntent } from '../../src/integrations/intent.js'
4import type { Options } from '../../src/types.js'
5​
6const options: Options = {
7 projectName: 'test',
8 targetDir: '/test',
9 framework: {
10 id: 'test',
11 name: 'Test',
12 description: '',
13 version: '1.0.0',
14 basePackageJSON: {},
15 optionalPackages: {},
16 supportedModes: {},
17 getFiles: async () => [],
18 getFileContents: async () => '',
19 getDeletedFiles: async () => [],
20 getAddOns: () => [],
21 },
22 mode: 'file-router',
23 packageManager: 'pnpm',
24 typescript: true,
25 tailwind: false,
26 git: false,
27 intent: true,
28 install: true,
29 chosenAddOns: [],
30 addOnOptions: {},
32​
33describe('intent', () => {
34 it('skips when disabled', async () => {
35 const { environment, output } = createMemoryEnvironment()
36 environment.startRun()
37 await setupIntent(environment, '/test', { ...options, intent: false })
38 environment.finishRun()
39 expect(output.commands).toEqual([])
40 })
41 it('runs install when dependencies are installed', async () => {
42 const { environment, output } = createMemoryEnvironment()
43 environment.startRun()
44 await setupIntent(environment, '/test', options)
45 environment.finishRun()
46 expect(output.commands).toEqual([
47 { command: 'pnpm', args: ['dlx', '@tanstack/intent', 'install'] },
48 ])
49 })
50 it('skips the command and reports no configured step without dependencies', async () => {
51 const { environment, output } = createMemoryEnvironment()
52 const messages: Array<string> = []
53 environment.finishStep = (_id, message) => {
54 messages.push(message)
55 }
56 environment.startRun()
57 await setupIntent(environment, '/test', { ...options, install: false })
58 environment.finishRun()
59 expect(output.commands).toEqual([])
60 expect(messages).toEqual([
61 'TanStack Intent setup skipped: dependencies not installed',
62 ])
63 })
64})