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

pull-flags.test.ts

41 lines1.1 KB

1import { describe, expect, it, vi } from 'vitest'
2​
3import { parsePullFlags } from './index.ts'
4​
5describe('parsePullFlags', () => {
6 it('applies defaults', () => {
7 expect(parsePullFlags({})).toEqual({
8 outDir: 'src/modelschemas',
9 types: true,
10 optionalStyle: undefined,
11 })
12 })
13​
14 it('honours --out, --no-types, --optional', () => {
15 expect(
16 parsePullFlags({
17 out: 'generated/schemas',
18 'no-types': true,
19 optional: 'undefined',
20 }),
21 ).toEqual({
22 outDir: 'generated/schemas',
23 types: false,
24 optionalStyle: 'undefined',
25 })
26 })
27​
28 it('rejects an invalid --optional value', () => {
29 const exit = vi
30 .spyOn(process, 'exit')
31 .mockImplementation((() => undefined) as never)
32 const error = vi.spyOn(console, 'error').mockImplementation(() => undefined)
33 parsePullFlags({ optional: 'maybe' })
34 expect(error).toHaveBeenCalledWith(
35 expect.stringContaining("invalid --optional 'maybe'"),
36 )
37 expect(exit).toHaveBeenCalledWith(1)
38 exit.mockRestore()
39 error.mockRestore()
40 })
41})