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

solid.test.ts

119 lines3.3 KB

1import { expect, test, beforeAll } from 'vitest'
2​
3import {
4 createApp,
5 createMemoryEnvironment,
6 finalizeAddOns,
7 getFrameworkById,
8} from '@tanstack/cta-engine'
9​
10import type { AddOn, Options } from '@tanstack/cta-engine'
11​
12import { cleanupOutput } from './test-utilities.js'
13​
14import { register as registerSolid } from '../src/index.js'
15​
16beforeAll(async () => {
17 registerSolid()
18})
19​
20async function createSolidOptions(
21 projectName: string,
22 addOns?: Array<string>,
23): Promise<Options> {
24 const framework = getFrameworkById('solid')!
25​
26 let chosenAddOns: Array<AddOn> = []
27 let mode = 'code-router'
28 if (addOns) {
29 mode = 'file-router'
30 chosenAddOns = await finalizeAddOns(framework, mode, addOns)
31 }
32​
33 return {
34 framework,
35 addOns: !!chosenAddOns.length,
36 chosenAddOns,
37 git: true,
38 mode,
39 packageManager: 'npm',
40 projectName,
41 targetDir: `/foo/bar/baz/${projectName}`,
42 tailwind: false,
43 typescript: false,
44 variableValues: {},
45 } as Options
47​
48test('code router in javascript on npm', async () => {
49 const projectName = 'TEST'
50 const { environment, output } = createMemoryEnvironment()
51 const options = {
52 ...(await createSolidOptions(projectName)),
53 }
54 await createApp(environment, options)
55 const cleanedOutput = cleanupOutput(options, output)
56 await expect(JSON.stringify(cleanedOutput, null, 2)).toMatchFileSnapshot(
57 './snapshots/solid/solid-cr-js-npm.json',
58 )
59})
60​
61test('code router in typescript on npm', async () => {
62 const projectName = 'TEST'
63 const { environment, output } = createMemoryEnvironment()
64 const options = {
65 ...(await createSolidOptions(projectName)),
66 typescript: true,
67 }
68 await createApp(environment, options)
69 const cleanedOutput = cleanupOutput(options, output)
70 await expect(JSON.stringify(cleanedOutput, null, 2)).toMatchFileSnapshot(
71 './snapshots/solid/solid-cr-ts-npm.json',
72 )
73})
74​
75test('file router on npm', async () => {
76 const projectName = 'TEST'
77 const { environment, output } = createMemoryEnvironment()
78 const options = {
79 ...(await createSolidOptions(projectName)),
80 mode: 'file-router',
81 typescript: true,
82 }
83 await createApp(environment, options)
84 const cleanedOutput = cleanupOutput(options, output)
85 await expect(JSON.stringify(cleanedOutput, null, 2)).toMatchFileSnapshot(
86 './snapshots/solid/solid-fr-ts-npm.json',
87 )
88})
89​
90test('file router with tailwind on npm', async () => {
91 const projectName = 'TEST'
92 const { environment, output } = createMemoryEnvironment()
93 const options = {
94 ...(await createSolidOptions(projectName)),
95 mode: 'file-router',
96 typescript: true,
97 tailwind: true,
98 }
99 await createApp(environment, options)
100 const cleanedOutput = cleanupOutput(options, output)
101 await expect(JSON.stringify(cleanedOutput, null, 2)).toMatchFileSnapshot(
102 './snapshots/solid/solid-fr-ts-tw-npm.json',
103 )
104})
105​
106test('file router with add-on start on npm', async () => {
107 const projectName = 'TEST'
108 const { environment, output } = createMemoryEnvironment()
109 const options = {
110 ...(await createSolidOptions(projectName, ['start'])),
111 tailwind: true,
112 typescript: true,
113 }
114 await createApp(environment, options)
115 const cleanedOutput = cleanupOutput(options, output)
116 await expect(JSON.stringify(cleanedOutput, null, 2)).toMatchFileSnapshot(
117 './snapshots/solid/solid-cr-ts-start-npm.json',
118 )
119})