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

utils.test.ts

48 lines1.3 KB

1import { describe, expect, it } from 'vitest'
2​
3import {
4 formatCommand,
5 handleSpecialURL,
6 jsSafeName,
7 sortObject,
8} from '../src/utils.js'
9​
10describe('formatCommand', () => {
11 it('should format a command', () => {
12 expect(formatCommand({ command: 'echo', args: ['test'] })).toEqual(
13 'echo test',
14 )
15 })
16})
17​
18describe('jsSafeName', () => {
19 it('should convert a string to a safe JS name', () => {
20 expect(jsSafeName('test.foo')).toEqual('TestFoo')
21 })
22})
23​
24describe('sortObject', () => {
25 it('should sort an object', () => {
26 expect(sortObject({ b: 'b', a: 'a' })).toEqual({ a: 'a', b: 'b' })
27 })
28})
29​
30describe('handleSpecialURL', () => {
31 it('should handle special URLs', () => {
32 expect(
33 handleSpecialURL(
34 'https://github.com/TanStack/create-tsrouter-app/blob/main/examples/react-cra/registry.json',
35 ),
36 ).toEqual(
37 'https://raw.githubusercontent.com/TanStack/create-tsrouter-app/refs/heads/main/examples/react-cra/registry.json',
38 )
39​
40 expect(
41 handleSpecialURL(
42 'https://github.com/TanStack/create-tsrouter-app/tree/alpha/packages/cta-cli/tsconfig.json',
43 ),
44 ).toEqual(
45 'https://raw.githubusercontent.com/TanStack/create-tsrouter-app/refs/heads/alpha/packages/cta-cli/tsconfig.json',
46 )
47 })
48})