@@ -3,6 +3,8 @@ import { describe, expect, test } from 'vitest'
3
3
import { createApp } from '@tanstack/cta-engine'
4
4
import { finalizeAddOns , getFrameworkById } from '@tanstack/cta-core'
5
5
6
+ import type { AddOn , Options } from '@tanstack/cta-core'
7
+
6
8
import { register as registerReactCra } from '@tanstack/cta-templates-react-cra'
7
9
import { register as registerSolid } from '@tanstack/cta-templates-solid'
8
10
@@ -11,148 +13,155 @@ import { cleanupOutput, createTestEnvironment } from './test-utilities.js'
11
13
registerReactCra ( )
12
14
registerSolid ( )
13
15
16
+ async function createReactOptions ( projectName : string , addOns ?: Array < string > ) {
17
+ const framework = getFrameworkById ( 'react-cra' ) !
18
+
19
+ let chosenAddOns : Array < AddOn > = [ ]
20
+ let mode = 'code-router'
21
+ if ( addOns ) {
22
+ mode = 'file-router'
23
+ chosenAddOns = await finalizeAddOns ( framework , mode , addOns )
24
+ }
25
+
26
+ return {
27
+ framework,
28
+ addOns : ! ! chosenAddOns . length ,
29
+ chosenAddOns,
30
+ git : true ,
31
+ mode,
32
+ packageManager : 'npm' ,
33
+ projectName,
34
+ tailwind : false ,
35
+ toolchain : 'none' ,
36
+ typescript : false ,
37
+ variableValues : { } ,
38
+ } as Options
39
+ }
40
+
41
+ async function createSolidOptions ( projectName : string , addOns ?: Array < string > ) {
42
+ const framework = getFrameworkById ( 'solid' ) !
43
+
44
+ let chosenAddOns : Array < AddOn > = [ ]
45
+ let mode = 'code-router'
46
+ if ( addOns ) {
47
+ mode = 'file-router'
48
+ chosenAddOns = await finalizeAddOns ( framework , mode , addOns )
49
+ }
50
+
51
+ return {
52
+ framework,
53
+ addOns : ! ! chosenAddOns . length ,
54
+ chosenAddOns,
55
+ git : true ,
56
+ mode,
57
+ packageManager : 'npm' ,
58
+ projectName,
59
+ tailwind : false ,
60
+ toolchain : 'none' ,
61
+ typescript : false ,
62
+ variableValues : { } ,
63
+ } as Options
64
+ }
65
+
14
66
describe ( 'React Templates' , ( ) => {
15
67
test ( 'code router in javascript on npm' , async ( ) => {
16
68
const projectName = 'TEST'
17
- const { environment, output } = createTestEnvironment ( projectName )
18
- const framework = getFrameworkById ( 'react-cra' ) !
69
+ const { environment, output, trimProjectRelativePath } =
70
+ createTestEnvironment ( projectName )
19
71
await createApp (
20
72
{
21
- addOns : false ,
22
- framework,
23
- chosenAddOns : [ ] ,
24
- git : true ,
25
- mode : 'code-router' ,
26
- packageManager : 'npm' ,
27
- projectName,
28
- tailwind : false ,
29
- toolchain : 'none' ,
30
- typescript : false ,
31
- variableValues : { } ,
73
+ ...( await createReactOptions ( projectName ) ) ,
32
74
} ,
33
75
{
34
76
silent : true ,
35
77
environment,
36
78
} ,
37
79
)
38
- cleanupOutput ( output )
80
+ cleanupOutput ( output , trimProjectRelativePath )
39
81
await expect ( JSON . stringify ( output , null , 2 ) ) . toMatchFileSnapshot (
40
82
'./snapshots/cra/cr-js-npm.json' ,
41
83
)
42
84
} )
43
85
44
86
test ( 'code router in typescript on npm' , async ( ) => {
45
87
const projectName = 'TEST'
46
- const { environment, output } = createTestEnvironment ( projectName )
47
- const framework = getFrameworkById ( 'react-cra' ) !
88
+ const { environment, output, trimProjectRelativePath } =
89
+ createTestEnvironment ( projectName )
48
90
await createApp (
49
91
{
50
- addOns : false ,
51
- framework,
52
- chosenAddOns : [ ] ,
53
- git : true ,
54
- mode : 'code-router' ,
55
- packageManager : 'npm' ,
56
- projectName,
57
- tailwind : false ,
58
- toolchain : 'none' ,
92
+ ...( await createReactOptions ( projectName ) ) ,
59
93
typescript : true ,
60
- variableValues : { } ,
61
94
} ,
62
95
{
63
96
silent : true ,
64
97
environment,
65
98
} ,
66
99
)
67
- cleanupOutput ( output )
100
+ cleanupOutput ( output , trimProjectRelativePath )
68
101
await expect ( JSON . stringify ( output , null , 2 ) ) . toMatchFileSnapshot (
69
102
'./snapshots/cra/cr-ts-npm.json' ,
70
103
)
71
104
} )
72
105
73
106
test ( 'file router on npm' , async ( ) => {
74
107
const projectName = 'TEST'
75
- const { environment, output } = createTestEnvironment ( projectName )
76
- const framework = getFrameworkById ( 'react-cra' ) !
108
+ const { environment, output, trimProjectRelativePath } =
109
+ createTestEnvironment ( projectName )
77
110
await createApp (
78
111
{
79
- addOns : false ,
80
- framework,
81
- chosenAddOns : [ ] ,
82
- git : true ,
112
+ ...( await createReactOptions ( projectName ) ) ,
83
113
mode : 'file-router' ,
84
- packageManager : 'npm' ,
85
- projectName,
86
- tailwind : false ,
87
- toolchain : 'none' ,
88
114
typescript : true ,
89
- variableValues : { } ,
90
115
} ,
91
116
{
92
117
silent : true ,
93
118
environment,
94
119
} ,
95
120
)
96
- cleanupOutput ( output )
121
+ cleanupOutput ( output , trimProjectRelativePath )
97
122
await expect ( JSON . stringify ( output , null , 2 ) ) . toMatchFileSnapshot (
98
123
'./snapshots/cra/fr-ts-npm.json' ,
99
124
)
100
125
} )
101
126
102
127
test ( 'file router with tailwind on npm' , async ( ) => {
103
128
const projectName = 'TEST'
104
- const { environment, output } = createTestEnvironment ( projectName )
105
- const framework = getFrameworkById ( 'react-cra' ) !
129
+ const { environment, output, trimProjectRelativePath } =
130
+ createTestEnvironment ( projectName )
106
131
await createApp (
107
132
{
108
- addOns : false ,
109
- framework,
110
- chosenAddOns : [ ] ,
111
- git : true ,
133
+ ...( await createReactOptions ( projectName ) ) ,
112
134
mode : 'file-router' ,
113
- packageManager : 'npm' ,
114
- projectName,
115
- tailwind : true ,
116
- toolchain : 'none' ,
117
135
typescript : true ,
118
- variableValues : { } ,
136
+ tailwind : true ,
119
137
} ,
120
138
{
121
139
silent : true ,
122
140
environment,
123
141
} ,
124
142
)
125
- cleanupOutput ( output )
143
+ cleanupOutput ( output , trimProjectRelativePath )
126
144
await expect ( JSON . stringify ( output , null , 2 ) ) . toMatchFileSnapshot (
127
145
'./snapshots/cra/fr-ts-tw-npm.json' ,
128
146
)
129
147
} )
130
148
131
149
test ( 'file router with add-on start on npm' , async ( ) => {
132
150
const projectName = 'TEST'
133
- const framework = getFrameworkById ( 'react-cra' ) !
134
- const template = 'file-router'
135
- const { environment, output } = createTestEnvironment ( projectName )
151
+ const { environment, output, trimProjectRelativePath } =
152
+ createTestEnvironment ( projectName )
136
153
await createApp (
137
154
{
138
- addOns : true ,
139
- framework,
140
- chosenAddOns : await finalizeAddOns ( framework , template , [ 'start' ] ) ,
141
- git : true ,
142
- mode : template ,
143
- packageManager : 'npm' ,
144
- projectName,
155
+ ...( await createReactOptions ( projectName , [ 'start' ] ) ) ,
145
156
tailwind : true ,
146
- toolchain : 'none' ,
147
157
typescript : true ,
148
- variableValues : { } ,
149
158
} ,
150
159
{
151
160
silent : true ,
152
161
environment,
153
162
} ,
154
163
)
155
- cleanupOutput ( output )
164
+ cleanupOutput ( output , trimProjectRelativePath )
156
165
await expect ( JSON . stringify ( output , null , 2 ) ) . toMatchFileSnapshot (
157
166
'./snapshots/cra/cr-ts-start-npm.json' ,
158
167
)
@@ -162,145 +171,102 @@ describe('React Templates', () => {
162
171
describe ( 'Solid Templates' , ( ) => {
163
172
test ( 'code router in javascript on npm' , async ( ) => {
164
173
const projectName = 'TEST'
165
- const { environment, output } = createTestEnvironment ( projectName )
166
- const framework = getFrameworkById ( 'solid' ) !
174
+ const { environment, output, trimProjectRelativePath } =
175
+ createTestEnvironment ( projectName )
167
176
await createApp (
168
177
{
169
- addOns : false ,
170
- framework,
171
- chosenAddOns : [ ] ,
172
- git : true ,
173
- mode : 'code-router' ,
174
- packageManager : 'npm' ,
175
- projectName,
176
- tailwind : false ,
177
- toolchain : 'none' ,
178
- typescript : false ,
179
- variableValues : { } ,
178
+ ...( await createSolidOptions ( projectName ) ) ,
180
179
} ,
181
180
{
182
181
silent : true ,
183
182
environment,
184
183
} ,
185
184
)
186
- cleanupOutput ( output )
185
+ cleanupOutput ( output , trimProjectRelativePath )
187
186
await expect ( JSON . stringify ( output , null , 2 ) ) . toMatchFileSnapshot (
188
187
'./snapshots/cra/solid-cr-js-npm.json' ,
189
188
)
190
189
} )
191
190
192
191
test ( 'code router in typescript on npm' , async ( ) => {
193
192
const projectName = 'TEST'
194
- const { environment, output } = createTestEnvironment ( projectName )
195
- const framework = getFrameworkById ( 'solid' ) !
193
+ const { environment, output, trimProjectRelativePath } =
194
+ createTestEnvironment ( projectName )
196
195
await createApp (
197
196
{
198
- addOns : false ,
199
- framework,
200
- chosenAddOns : [ ] ,
201
- git : true ,
202
- mode : 'code-router' ,
203
- packageManager : 'npm' ,
204
- projectName,
205
- tailwind : false ,
206
- toolchain : 'none' ,
197
+ ...( await createSolidOptions ( projectName ) ) ,
207
198
typescript : true ,
208
- variableValues : { } ,
209
199
} ,
210
200
{
211
201
silent : true ,
212
202
environment,
213
203
} ,
214
204
)
215
- cleanupOutput ( output )
205
+ cleanupOutput ( output , trimProjectRelativePath )
216
206
await expect ( JSON . stringify ( output , null , 2 ) ) . toMatchFileSnapshot (
217
207
'./snapshots/cra/solid-cr-ts-npm.json' ,
218
208
)
219
209
} )
220
210
221
211
test ( 'file router on npm' , async ( ) => {
222
212
const projectName = 'TEST'
223
- const { environment, output } = createTestEnvironment ( projectName )
224
- const framework = getFrameworkById ( 'solid' ) !
213
+ const { environment, output, trimProjectRelativePath } =
214
+ createTestEnvironment ( projectName )
225
215
await createApp (
226
216
{
227
- addOns : false ,
228
- framework,
229
- chosenAddOns : [ ] ,
230
- git : true ,
217
+ ...( await createSolidOptions ( projectName ) ) ,
231
218
mode : 'file-router' ,
232
- packageManager : 'npm' ,
233
- projectName,
234
- tailwind : false ,
235
- toolchain : 'none' ,
236
219
typescript : true ,
237
- variableValues : { } ,
238
220
} ,
239
221
{
240
222
silent : true ,
241
223
environment,
242
224
} ,
243
225
)
244
- cleanupOutput ( output )
226
+ cleanupOutput ( output , trimProjectRelativePath )
245
227
await expect ( JSON . stringify ( output , null , 2 ) ) . toMatchFileSnapshot (
246
228
'./snapshots/cra/solid-fr-ts-npm.json' ,
247
229
)
248
230
} )
249
231
250
232
test ( 'file router with tailwind on npm' , async ( ) => {
251
233
const projectName = 'TEST'
252
- const { environment, output } = createTestEnvironment ( projectName )
253
- const framework = getFrameworkById ( 'solid' ) !
234
+ const { environment, output, trimProjectRelativePath } =
235
+ createTestEnvironment ( projectName )
254
236
await createApp (
255
237
{
256
- addOns : false ,
257
- framework,
258
- chosenAddOns : [ ] ,
259
- git : true ,
238
+ ...( await createSolidOptions ( projectName ) ) ,
260
239
mode : 'file-router' ,
261
- packageManager : 'npm' ,
262
- projectName,
263
- tailwind : true ,
264
- toolchain : 'none' ,
265
240
typescript : true ,
266
- variableValues : { } ,
241
+ tailwind : true ,
267
242
} ,
268
243
{
269
244
silent : true ,
270
245
environment,
271
246
} ,
272
247
)
273
- cleanupOutput ( output )
248
+ cleanupOutput ( output , trimProjectRelativePath )
274
249
await expect ( JSON . stringify ( output , null , 2 ) ) . toMatchFileSnapshot (
275
250
'./snapshots/cra/solid-fr-ts-tw-npm.json' ,
276
251
)
277
252
} )
278
253
279
254
test ( 'file router with add-on start on npm' , async ( ) => {
280
255
const projectName = 'TEST'
281
- const framework = getFrameworkById ( 'solid' ) !
282
- const template = 'file-router'
283
- const { environment, output } = createTestEnvironment ( projectName )
256
+ const { environment, output, trimProjectRelativePath } =
257
+ createTestEnvironment ( projectName )
284
258
await createApp (
285
259
{
286
- addOns : true ,
287
- framework,
288
- chosenAddOns : await finalizeAddOns ( framework , template , [ 'start' ] ) ,
289
- git : true ,
290
- mode : template ,
291
- packageManager : 'npm' ,
292
- projectName,
260
+ ...( await createSolidOptions ( projectName , [ 'start' ] ) ) ,
293
261
tailwind : true ,
294
- toolchain : 'none' ,
295
262
typescript : true ,
296
- variableValues : { } ,
297
263
} ,
298
264
{
299
265
silent : true ,
300
266
environment,
301
267
} ,
302
268
)
303
- cleanupOutput ( output )
269
+ cleanupOutput ( output , trimProjectRelativePath )
304
270
await expect ( JSON . stringify ( output , null , 2 ) ) . toMatchFileSnapshot (
305
271
'./snapshots/cra/solid-cr-ts-start-npm.json' ,
306
272
)
0 commit comments