-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.spec.ts
More file actions
63 lines (55 loc) · 1.62 KB
/
Copy pathtypes.spec.ts
File metadata and controls
63 lines (55 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import {
describe,
it,
expectTypeOf
} from 'vitest'
import { setArgs } from './argv.js'
import * as argue from './index.js'
describe('types', () => {
describe('expect', () => {
it('should infer union of expected args', () => {
setArgs('add')
expectTypeOf(argue.expect('add', argue.alias('install', 'i'))).toEqualTypeOf<'add' | 'install'>()
})
})
describe('option', () => {
it('should infer string option result', () => {
expectTypeOf(argue.option('input', String)('', () => '', {})).toEqualTypeOf<{
input: string
} | null>()
})
it('should infer number option result', () => {
expectTypeOf(argue.option(argue.alias('port', 'p'), Number)('', () => '', {})).toEqualTypeOf<{
port: number
} | null>()
})
it('should infer array option result', () => {
expectTypeOf(argue.option('plugins', Array)('', () => '', {})).toEqualTypeOf<{
plugins: string[]
} | null>()
})
it('should infer boolean option result', () => {
expectTypeOf(argue.option('debug', Boolean)('', () => '', {})).toEqualTypeOf<{
debug: boolean
} | null>()
})
})
describe('readOptions', () => {
it('should infer merged options result', () => {
setArgs()
expectTypeOf(
argue.readOptions(
argue.option('input', String),
argue.option(argue.alias('port', 'p'), Number),
argue.option('plugins', Array),
argue.option('debug', Boolean)
)
).toEqualTypeOf<{
input?: string
port?: number
plugins?: string[]
debug?: boolean
}>()
})
})
})