Open History to see the last commit
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 { register as registerReactCra } from '../src/index.js'
13
14import { cleanupOutput } from './test-utilities.js'
15
16beforeAll(async () => {
17 await registerReactCra()
18})
19
20async function createReactOptions(
21 addOns: Array<string> = [],
22 projectName: string = 'TEST',
23) {
24 const framework = getFrameworkById('react-cra')!
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
46}
47
48test('code router in javascript on npm', async () => {
49 const { environment, output } = createMemoryEnvironment()
50 const options = await createReactOptions()
51 await createApp(environment, options)
52 const cleanedOutput = cleanupOutput(options, output)
53 await expect(JSON.stringify(cleanedOutput, null, 2)).toMatchFileSnapshot(
54 './snapshots/react-cra/cr-js-npm.json',
55 )
56})
57
58test('code router with form add-on on npm', async () => {
59 const { environment, output } = createMemoryEnvironment()
60 const options = await createReactOptions(['form'])
61 await createApp(environment, options)
62 const cleanedOutput = cleanupOutput(options, output)
63 await expect(JSON.stringify(cleanedOutput, null, 2)).toMatchFileSnapshot(
64 './snapshots/react-cra/cr-js-form-npm.json',
65 )
66})
67
68test('code router in typescript on npm', async () => {
69 const { environment, output } = createMemoryEnvironment()
70 const options = {
71 ...(await createReactOptions()),
72 typescript: true,
73 }
74 await createApp(environment, options)
75 const cleanedOutput = cleanupOutput(options, output)
76 await expect(JSON.stringify(cleanedOutput, null, 2)).toMatchFileSnapshot(
77 './snapshots/react-cra/cr-ts-npm.json',
78 )
79})
80
81test('file router on npm', async () => {
82 const { environment, output } = createMemoryEnvironment()
83 const options = {
84 ...(await createReactOptions()),
85 mode: 'file-router',
86 typescript: true,
87 } as Options
88 await createApp(environment, options)
89 const cleanedOutput = cleanupOutput(options, output)
90 await expect(JSON.stringify(cleanedOutput, null, 2)).toMatchFileSnapshot(
91 './snapshots/react-cra/fr-ts-npm.json',
92 )
93})
94
95test('file router on npm with biome', async () => {
96 const { environment, output } = createMemoryEnvironment()
97 const options = {
98 ...(await createReactOptions(['biome'])),
99 mode: 'file-router',
100 typescript: true,
101 } as Options
102 await createApp(environment, options)
103 const cleanedOutput = cleanupOutput(options, output)
104 await expect(JSON.stringify(cleanedOutput, null, 2)).toMatchFileSnapshot(
105 './snapshots/react-cra/fr-ts-biome-npm.json',
106 )
107})
108
109test('file router with tailwind on npm', async () => {
110 const { environment, output } = createMemoryEnvironment()
111 const options = {
112 ...(await createReactOptions()),
113 mode: 'file-router',
114 typescript: true,
115 tailwind: true,
116 } as Options
117 await createApp(environment, options)
118 const cleanedOutput = cleanupOutput(options, output)
119 await expect(JSON.stringify(cleanedOutput, null, 2)).toMatchFileSnapshot(
120 './snapshots/react-cra/fr-ts-tw-npm.json',
121 )
122})
123
124test('file router with add-on start on npm', async () => {
125 const { environment, output } = createMemoryEnvironment()
126 const options = {
127 ...(await createReactOptions(['start'])),
128 tailwind: true,
129 typescript: true,
130 } as Options
131 await createApp(environment, options)
132 const cleanedOutput = cleanupOutput(options, output)
133 await expect(JSON.stringify(cleanedOutput, null, 2)).toMatchFileSnapshot(
134 './snapshots/react-cra/cr-ts-start-npm.json',
135 )
136})
137
138test('file router with add-on start on npm', async () => {
139 const { environment, output } = createMemoryEnvironment()
140 const options = {
141 ...(await createReactOptions(['start', 'tanstack-query'])),
142 tailwind: true,
143 typescript: true,
144 } as Options
145 await createApp(environment, options)
146 const cleanedOutput = cleanupOutput(options, output)
147 await expect(JSON.stringify(cleanedOutput, null, 2)).toMatchFileSnapshot(
148 './snapshots/react-cra/cr-ts-start-tanstack-query-npm.json',
149 )
150})