Skip to content

Commit 2bc9782

Browse files
committed
chore: tests migrated to memory environment
1 parent 1b4e6fc commit 2bc9782

12 files changed

+119
-522
lines changed

tests/integration-tests/cra.test.ts

Lines changed: 94 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { describe, expect, test } from 'vitest'
33
import { createApp } from '@tanstack/cta-engine'
44
import { finalizeAddOns, getFrameworkById } from '@tanstack/cta-core'
55

6+
import type { AddOn, Options } from '@tanstack/cta-core'
7+
68
import { register as registerReactCra } from '@tanstack/cta-templates-react-cra'
79
import { register as registerSolid } from '@tanstack/cta-templates-solid'
810

@@ -11,148 +13,155 @@ import { cleanupOutput, createTestEnvironment } from './test-utilities.js'
1113
registerReactCra()
1214
registerSolid()
1315

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+
1466
describe('React Templates', () => {
1567
test('code router in javascript on npm', async () => {
1668
const projectName = 'TEST'
17-
const { environment, output } = createTestEnvironment(projectName)
18-
const framework = getFrameworkById('react-cra')!
69+
const { environment, output, trimProjectRelativePath } =
70+
createTestEnvironment(projectName)
1971
await createApp(
2072
{
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)),
3274
},
3375
{
3476
silent: true,
3577
environment,
3678
},
3779
)
38-
cleanupOutput(output)
80+
cleanupOutput(output, trimProjectRelativePath)
3981
await expect(JSON.stringify(output, null, 2)).toMatchFileSnapshot(
4082
'./snapshots/cra/cr-js-npm.json',
4183
)
4284
})
4385

4486
test('code router in typescript on npm', async () => {
4587
const projectName = 'TEST'
46-
const { environment, output } = createTestEnvironment(projectName)
47-
const framework = getFrameworkById('react-cra')!
88+
const { environment, output, trimProjectRelativePath } =
89+
createTestEnvironment(projectName)
4890
await createApp(
4991
{
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)),
5993
typescript: true,
60-
variableValues: {},
6194
},
6295
{
6396
silent: true,
6497
environment,
6598
},
6699
)
67-
cleanupOutput(output)
100+
cleanupOutput(output, trimProjectRelativePath)
68101
await expect(JSON.stringify(output, null, 2)).toMatchFileSnapshot(
69102
'./snapshots/cra/cr-ts-npm.json',
70103
)
71104
})
72105

73106
test('file router on npm', async () => {
74107
const projectName = 'TEST'
75-
const { environment, output } = createTestEnvironment(projectName)
76-
const framework = getFrameworkById('react-cra')!
108+
const { environment, output, trimProjectRelativePath } =
109+
createTestEnvironment(projectName)
77110
await createApp(
78111
{
79-
addOns: false,
80-
framework,
81-
chosenAddOns: [],
82-
git: true,
112+
...(await createReactOptions(projectName)),
83113
mode: 'file-router',
84-
packageManager: 'npm',
85-
projectName,
86-
tailwind: false,
87-
toolchain: 'none',
88114
typescript: true,
89-
variableValues: {},
90115
},
91116
{
92117
silent: true,
93118
environment,
94119
},
95120
)
96-
cleanupOutput(output)
121+
cleanupOutput(output, trimProjectRelativePath)
97122
await expect(JSON.stringify(output, null, 2)).toMatchFileSnapshot(
98123
'./snapshots/cra/fr-ts-npm.json',
99124
)
100125
})
101126

102127
test('file router with tailwind on npm', async () => {
103128
const projectName = 'TEST'
104-
const { environment, output } = createTestEnvironment(projectName)
105-
const framework = getFrameworkById('react-cra')!
129+
const { environment, output, trimProjectRelativePath } =
130+
createTestEnvironment(projectName)
106131
await createApp(
107132
{
108-
addOns: false,
109-
framework,
110-
chosenAddOns: [],
111-
git: true,
133+
...(await createReactOptions(projectName)),
112134
mode: 'file-router',
113-
packageManager: 'npm',
114-
projectName,
115-
tailwind: true,
116-
toolchain: 'none',
117135
typescript: true,
118-
variableValues: {},
136+
tailwind: true,
119137
},
120138
{
121139
silent: true,
122140
environment,
123141
},
124142
)
125-
cleanupOutput(output)
143+
cleanupOutput(output, trimProjectRelativePath)
126144
await expect(JSON.stringify(output, null, 2)).toMatchFileSnapshot(
127145
'./snapshots/cra/fr-ts-tw-npm.json',
128146
)
129147
})
130148

131149
test('file router with add-on start on npm', async () => {
132150
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)
136153
await createApp(
137154
{
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'])),
145156
tailwind: true,
146-
toolchain: 'none',
147157
typescript: true,
148-
variableValues: {},
149158
},
150159
{
151160
silent: true,
152161
environment,
153162
},
154163
)
155-
cleanupOutput(output)
164+
cleanupOutput(output, trimProjectRelativePath)
156165
await expect(JSON.stringify(output, null, 2)).toMatchFileSnapshot(
157166
'./snapshots/cra/cr-ts-start-npm.json',
158167
)
@@ -162,145 +171,102 @@ describe('React Templates', () => {
162171
describe('Solid Templates', () => {
163172
test('code router in javascript on npm', async () => {
164173
const projectName = 'TEST'
165-
const { environment, output } = createTestEnvironment(projectName)
166-
const framework = getFrameworkById('solid')!
174+
const { environment, output, trimProjectRelativePath } =
175+
createTestEnvironment(projectName)
167176
await createApp(
168177
{
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)),
180179
},
181180
{
182181
silent: true,
183182
environment,
184183
},
185184
)
186-
cleanupOutput(output)
185+
cleanupOutput(output, trimProjectRelativePath)
187186
await expect(JSON.stringify(output, null, 2)).toMatchFileSnapshot(
188187
'./snapshots/cra/solid-cr-js-npm.json',
189188
)
190189
})
191190

192191
test('code router in typescript on npm', async () => {
193192
const projectName = 'TEST'
194-
const { environment, output } = createTestEnvironment(projectName)
195-
const framework = getFrameworkById('solid')!
193+
const { environment, output, trimProjectRelativePath } =
194+
createTestEnvironment(projectName)
196195
await createApp(
197196
{
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)),
207198
typescript: true,
208-
variableValues: {},
209199
},
210200
{
211201
silent: true,
212202
environment,
213203
},
214204
)
215-
cleanupOutput(output)
205+
cleanupOutput(output, trimProjectRelativePath)
216206
await expect(JSON.stringify(output, null, 2)).toMatchFileSnapshot(
217207
'./snapshots/cra/solid-cr-ts-npm.json',
218208
)
219209
})
220210

221211
test('file router on npm', async () => {
222212
const projectName = 'TEST'
223-
const { environment, output } = createTestEnvironment(projectName)
224-
const framework = getFrameworkById('solid')!
213+
const { environment, output, trimProjectRelativePath } =
214+
createTestEnvironment(projectName)
225215
await createApp(
226216
{
227-
addOns: false,
228-
framework,
229-
chosenAddOns: [],
230-
git: true,
217+
...(await createSolidOptions(projectName)),
231218
mode: 'file-router',
232-
packageManager: 'npm',
233-
projectName,
234-
tailwind: false,
235-
toolchain: 'none',
236219
typescript: true,
237-
variableValues: {},
238220
},
239221
{
240222
silent: true,
241223
environment,
242224
},
243225
)
244-
cleanupOutput(output)
226+
cleanupOutput(output, trimProjectRelativePath)
245227
await expect(JSON.stringify(output, null, 2)).toMatchFileSnapshot(
246228
'./snapshots/cra/solid-fr-ts-npm.json',
247229
)
248230
})
249231

250232
test('file router with tailwind on npm', async () => {
251233
const projectName = 'TEST'
252-
const { environment, output } = createTestEnvironment(projectName)
253-
const framework = getFrameworkById('solid')!
234+
const { environment, output, trimProjectRelativePath } =
235+
createTestEnvironment(projectName)
254236
await createApp(
255237
{
256-
addOns: false,
257-
framework,
258-
chosenAddOns: [],
259-
git: true,
238+
...(await createSolidOptions(projectName)),
260239
mode: 'file-router',
261-
packageManager: 'npm',
262-
projectName,
263-
tailwind: true,
264-
toolchain: 'none',
265240
typescript: true,
266-
variableValues: {},
241+
tailwind: true,
267242
},
268243
{
269244
silent: true,
270245
environment,
271246
},
272247
)
273-
cleanupOutput(output)
248+
cleanupOutput(output, trimProjectRelativePath)
274249
await expect(JSON.stringify(output, null, 2)).toMatchFileSnapshot(
275250
'./snapshots/cra/solid-fr-ts-tw-npm.json',
276251
)
277252
})
278253

279254
test('file router with add-on start on npm', async () => {
280255
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)
284258
await createApp(
285259
{
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'])),
293261
tailwind: true,
294-
toolchain: 'none',
295262
typescript: true,
296-
variableValues: {},
297263
},
298264
{
299265
silent: true,
300266
environment,
301267
},
302268
)
303-
cleanupOutput(output)
269+
cleanupOutput(output, trimProjectRelativePath)
304270
await expect(JSON.stringify(output, null, 2)).toMatchFileSnapshot(
305271
'./snapshots/cra/solid-cr-ts-start-npm.json',
306272
)

0 commit comments

Comments
 (0)