Skip to content

Commit 9819760

Browse files
committed
chore: re-add tests
1 parent e4b1109 commit 9819760

15 files changed

+207
-17
lines changed

packages/cta-engine/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"scripts": {
99
"build": "tsc",
1010
"dev": "tsc --watch",
11-
"test": "eslint ./src"
11+
"test": "eslint ./src && vitest run",
12+
"test:watch": "vitest"
1213
},
1314
"repository": {
1415
"type": "git",

packages/cta-engine/src/package-manager.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export function getPackageManagerScriptCommand(
3232
case 'yarn':
3333
return { command: 'yarn', args: ['run', ...args] }
3434
case 'pnpm':
35-
return { command: 'pnpm', args: ['run', ...args] }
35+
return { command: 'pnpm', args: [...args] }
3636
case 'bun':
3737
return { command: 'bunx', args: ['--bun', 'run', ...args] }
3838
case 'deno':

packages/cta-engine/src/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ export function formatCommand({
2323
command: string
2424
args: Array<string>
2525
}) {
26-
return `${command} ${args.join(' ')}`
26+
return `${command} ${args.join(' ')}`.trim()
2727
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { describe, expect, it } from 'vitest'
2+
3+
import { relativePath } from '../src/file-helpers.js'
4+
5+
describe('relativePath', () => {
6+
it('relative path with the same directory', () => {
7+
expect(relativePath('src/utils.ts', 'src/index.ts')).toBe('./index.ts')
8+
})
9+
it('relative from a subdirectory', () => {
10+
expect(relativePath('src/something/utils.ts', 'src/index.ts')).toBe(
11+
'../index.ts',
12+
)
13+
})
14+
it('relative to a subdirectory', () => {
15+
expect(relativePath('src/utils.ts', 'src/something/index.ts')).toBe(
16+
'./something/index.ts',
17+
)
18+
})
19+
it('same deep directory', () => {
20+
expect(
21+
relativePath('src/foo/bar/baz/utils.ts', 'src/foo/bar/baz/index.ts'),
22+
).toBe('./index.ts')
23+
})
24+
it('up several levels and down several levels', () => {
25+
expect(relativePath('src/bar/baz/utils.ts', 'src/foo/bar/index.ts')).toBe(
26+
'../../foo/bar/index.ts',
27+
)
28+
})
29+
it('relative path with a different directory', () => {
30+
expect(
31+
relativePath(
32+
'./src/routes/__root.tsx.ejs',
33+
'src/integrations/tanstack-query/layout.tsx',
34+
),
35+
).toBe('../integrations/tanstack-query/layout.tsx')
36+
})
37+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
import { describe, expect, it } from 'vitest'
2+
3+
import {
4+
getPackageManagerExecuteCommand,
5+
getPackageManagerInstallCommand,
6+
getPackageManagerScriptCommand,
7+
} from '../src/package-manager.js'
8+
import { formatCommand } from '../src/utils.js'
9+
10+
describe('getPackageManagerScriptCommand', () => {
11+
it('yarn', () => {
12+
expect(formatCommand(getPackageManagerScriptCommand('yarn', ['dev']))).toBe(
13+
'yarn run dev',
14+
)
15+
})
16+
it('pnpm', () => {
17+
expect(formatCommand(getPackageManagerScriptCommand('pnpm', ['dev']))).toBe(
18+
'pnpm dev',
19+
)
20+
})
21+
it('bun', () => {
22+
expect(formatCommand(getPackageManagerScriptCommand('bun', ['dev']))).toBe(
23+
'bunx --bun run dev',
24+
)
25+
})
26+
it('deno', () => {
27+
expect(formatCommand(getPackageManagerScriptCommand('deno', ['dev']))).toBe(
28+
'deno task dev',
29+
)
30+
})
31+
it('npm', () => {
32+
expect(formatCommand(getPackageManagerScriptCommand('npm', ['dev']))).toBe(
33+
'npm run dev',
34+
)
35+
})
36+
})
37+
38+
describe('getPackageManagerExecuteCommand', () => {
39+
it('yarn', () => {
40+
expect(
41+
formatCommand(
42+
getPackageManagerExecuteCommand('yarn', 'shadcn', ['add', 'button']),
43+
),
44+
).toBe('yarn dlx shadcn add button')
45+
})
46+
it('pnpm', () => {
47+
expect(
48+
formatCommand(
49+
getPackageManagerExecuteCommand('pnpm', 'shadcn', ['add', 'button']),
50+
),
51+
).toBe('pnpx shadcn add button')
52+
})
53+
it('bun', () => {
54+
expect(
55+
formatCommand(
56+
getPackageManagerExecuteCommand('bun', 'shadcn', ['add', 'button']),
57+
),
58+
).toBe('bunx --bun shadcn add button')
59+
})
60+
it('deno', () => {
61+
expect(
62+
formatCommand(
63+
getPackageManagerExecuteCommand('deno', 'shadcn', ['add', 'button']),
64+
),
65+
).toBe('deno run npm:shadcn add button')
66+
})
67+
it('npm', () => {
68+
expect(
69+
formatCommand(
70+
getPackageManagerExecuteCommand('npm', 'shadcn', ['add', 'button']),
71+
),
72+
).toBe('npx shadcn add button')
73+
})
74+
})
75+
76+
describe('getPackageManagerInstallCommand', () => {
77+
it('yarn install', () => {
78+
expect(formatCommand(getPackageManagerInstallCommand('yarn'))).toBe(
79+
'yarn install',
80+
)
81+
})
82+
it('pnpm install', () => {
83+
expect(formatCommand(getPackageManagerInstallCommand('pnpm'))).toBe(
84+
'pnpm install',
85+
)
86+
})
87+
it('bun install', () => {
88+
expect(formatCommand(getPackageManagerInstallCommand('bun'))).toBe(
89+
'bun install',
90+
)
91+
})
92+
it('deno install', () => {
93+
expect(formatCommand(getPackageManagerInstallCommand('deno'))).toBe(
94+
'deno install',
95+
)
96+
})
97+
it('npm install', () => {
98+
expect(formatCommand(getPackageManagerInstallCommand('npm'))).toBe(
99+
'npm install',
100+
)
101+
})
102+
103+
it('yarn install radix-ui', () => {
104+
expect(
105+
formatCommand(getPackageManagerInstallCommand('yarn', 'radix-ui')),
106+
).toBe('yarn add radix-ui')
107+
})
108+
it('pnpm install radix-ui', () => {
109+
expect(
110+
formatCommand(getPackageManagerInstallCommand('pnpm', 'radix-ui')),
111+
).toBe('pnpm add radix-ui')
112+
})
113+
it('bun install radix-ui', () => {
114+
expect(
115+
formatCommand(getPackageManagerInstallCommand('bun', 'radix-ui')),
116+
).toBe('bun install radix-ui')
117+
})
118+
it('deno install radix-ui', () => {
119+
expect(
120+
formatCommand(getPackageManagerInstallCommand('deno', 'radix-ui')),
121+
).toBe('deno install radix-ui')
122+
})
123+
it('npm install radix-ui', () => {
124+
expect(
125+
formatCommand(getPackageManagerInstallCommand('npm', 'radix-ui')),
126+
).toBe('npm install radix-ui')
127+
})
128+
129+
it('yarn install vitest in dev mode', () => {
130+
expect(
131+
formatCommand(getPackageManagerInstallCommand('yarn', 'vitest', true)),
132+
).toBe('yarn add vitest --dev')
133+
})
134+
it('pnpm install vitest in dev mode', () => {
135+
expect(
136+
formatCommand(getPackageManagerInstallCommand('pnpm', 'vitest', true)),
137+
).toBe('pnpm add vitest --dev')
138+
})
139+
it('bun install vitest in dev mode', () => {
140+
expect(
141+
formatCommand(getPackageManagerInstallCommand('bun', 'vitest', true)),
142+
).toBe('bun install vitest -D')
143+
})
144+
it('deno install vitest in dev mode', () => {
145+
expect(
146+
formatCommand(getPackageManagerInstallCommand('deno', 'vitest', true)),
147+
).toBe('deno install vitest -D')
148+
})
149+
it('npm install vitest in dev mode', () => {
150+
expect(
151+
formatCommand(getPackageManagerInstallCommand('npm', 'vitest', true)),
152+
).toBe('npm install vitest -D')
153+
})
154+
})

templates/solid/project/base/src/routes/__root.tsx.ejs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import <%= integration.jsName %> from "<%= relativePath(integration.path) %>";
55
<% if (addOnEnabled['solid-ui']) { %>
66
import "@fontsource/inter"
77
<% } %>
8-
<% if (addOns.length) { %>import Header from '../components/Header'
8+
<% if (addOns.length || integrations.length || routes.length) { %>import Header from '../components/Header'
99
<% } %>
1010
<% for(const addOn of addOns) {
1111
for(const init of addOn.main?.initialize || []) { %>
@@ -22,7 +22,7 @@ function RootComponent() {
2222
<% for(const integration of integrations.filter(i => i.type === 'provider')) { %>
2323
<<%= integration.jsName %>>
2424
<% } %>
25-
<% if (addOns.length) { %>
25+
<% if (addOns.length || integrations.length || routes.length) { %>
2626
<Header />
2727
<% } %>
2828
<Outlet />

templates/solid/project/base/src/routes/index.tsx.ejs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<% if (codeRouter) { ignoreFile() } %>import * as Solid from 'solid-js'
22
import { createFileRoute } from '@tanstack/solid-router'
3-
<% if (addOns.length || integrations.length || routes.length) { %>
4-
import Header from '../components/Header'<% } %>
3+
54
import logo from '../logo.svg'
65

76
export const Route = createFileRoute('/')({
@@ -10,8 +9,7 @@ export const Route = createFileRoute('/')({
109

1110
function IndexComponent() {
1211
return (
13-
<div class="text-center"><% if (addOns.length || integrations.length || routes.length) { %>
14-
<Header /><% } %>
12+
<div class="text-center">
1513
<header class="min-h-screen flex flex-col items-center justify-center bg-[#282c34] text-white text-[calc(10px+2vmin)]">
1614
<img
1715
src={logo}

tests/integration-tests/snapshots/react-cra/cr-js-form-npm.json

+1-1
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)