@@ -10,7 +10,7 @@ test('constructor', () => {
1010 expect ( massarg ( opts ) ) . toBeInstanceOf ( MassargCommand )
1111} )
1212
13- describe ( 'command' , ( ) => {
13+ describe ( 'sub command' , ( ) => {
1414 test ( 'add' , ( ) => {
1515 const command = massarg ( opts )
1616 expect ( command . command ) . toBeInstanceOf ( Function )
@@ -36,149 +36,6 @@ describe('command', () => {
3636 } )
3737} )
3838
39- describe ( 'option' , ( ) => {
40- test ( 'add' , ( ) => {
41- const command = massarg ( opts )
42- expect ( command . option ) . toBeInstanceOf ( Function )
43- expect (
44- command . option ( { name : 'test2' , description : 'test2' , aliases : [ ] , defaultValue : '' } ) ,
45- ) . toBeInstanceOf ( MassargCommand )
46- } )
47- test ( 'validate' , ( ) => {
48- expect ( ( ) =>
49- massarg ( opts ) . option ( {
50- name : 'test2' ,
51- description : 123 as any ,
52- aliases : [ ] ,
53- defaultValue : '' ,
54- } ) ,
55- ) . toThrow ( 'Expected string, received number' )
56- } )
57- test ( 'add duplicate' , ( ) => {
58- expect ( ( ) =>
59- massarg ( opts )
60- . option ( {
61- name : 'test2' ,
62- description : 'test2' ,
63- aliases : [ ] ,
64- defaultValue : '' ,
65- } )
66- . option ( {
67- name : 'test2' ,
68- description : 'test2' ,
69- aliases : [ ] ,
70- defaultValue : '' ,
71- } ) ,
72- ) . toThrow ( 'Option "test2" already exists' )
73- } )
74- test ( 'add 2 defaults' , ( ) => {
75- expect ( ( ) =>
76- massarg ( opts )
77- . option ( {
78- name : 'test' ,
79- description : 'test2' ,
80- aliases : [ ] ,
81- isDefault : true ,
82- } )
83- . option ( {
84- name : 'test2' ,
85- description : 'test2' ,
86- aliases : [ ] ,
87- isDefault : true ,
88- } ) ,
89- ) . toThrow (
90- 'Option "test2" cannot be set as default because option "test" is already set as default' ,
91- )
92- } )
93- } )
94-
95- describe ( 'flag' , ( ) => {
96- test ( 'add' , ( ) => {
97- const command = massarg ( opts )
98- expect ( command . flag ) . toBeInstanceOf ( Function )
99- expect ( command . flag ( { name : 'test2' , description : 'test2' , aliases : [ ] } ) ) . toBeInstanceOf (
100- MassargCommand ,
101- )
102- } )
103- test ( 'add duplicate' , ( ) => {
104- expect ( ( ) =>
105- massarg ( opts )
106- . flag ( { name : 'test2' , description : 'test2' , aliases : [ ] } )
107- . flag ( { name : 'test2' , description : 'test2' , aliases : [ ] } ) ,
108- ) . toThrow ( 'Flag "test2" already exists' )
109- } )
110- test ( 'validate' , ( ) => {
111- expect ( ( ) =>
112- massarg ( opts ) . flag ( {
113- name : 'test2' ,
114- description : 123 as any ,
115- aliases : [ ] ,
116- } ) ,
117- ) . toThrow ( 'Expected string, received number' )
118- } )
119- } )
120-
121- describe ( 'example' , ( ) => {
122- test ( 'example' , ( ) => {
123- const command = massarg ( opts )
124- expect ( command . example ) . toBeInstanceOf ( Function )
125- expect ( command . example ( { description : 'test' , input : '' , output : '' } ) ) . toBeInstanceOf (
126- MassargCommand ,
127- )
128- } )
129- } )
130-
131- describe ( 'help' , ( ) => {
132- test ( 'default value' , ( ) => {
133- const command = massarg ( opts )
134- expect ( command . helpConfig ) . toEqual ( defaultHelpConfig )
135- } )
136-
137- test ( 'init' , ( ) => {
138- const command = massarg ( opts ) . help ( {
139- bindOption : true ,
140- optionOptions : {
141- namePrefix : '__' ,
142- } ,
143- } )
144- expect ( command . help ) . toBeInstanceOf ( Function )
145- expect ( command . helpConfig ) . toHaveProperty ( 'bindOption' , true )
146- expect ( command . helpConfig ) . toHaveProperty ( 'optionOptions.namePrefix' , '__' )
147- expect ( command . helpConfig ) . toHaveProperty ( 'optionOptions.aliasPrefix' , '-' )
148- expect ( command . helpConfig ) . toHaveProperty ( 'optionOptions.nameStyle.color' , 'yellow' )
149- } )
150-
151- test ( 'binds command' , ( ) => {
152- const command = massarg ( opts ) . help ( {
153- bindCommand : true ,
154- } )
155- expect ( command . help ) . toBeInstanceOf ( Function )
156- expect ( command . helpConfig ) . toHaveProperty ( 'bindCommand' , true )
157- expect ( command . commands . find ( ( o ) => o . name === 'help' ) ) . toBeTruthy ( )
158- } )
159-
160- test ( 'binds option' , ( ) => {
161- const command = massarg ( opts ) . help ( {
162- bindOption : true ,
163- } )
164- expect ( command . help ) . toBeInstanceOf ( Function )
165- expect ( command . helpConfig ) . toHaveProperty ( 'bindOption' , true )
166- expect ( command . options . find ( ( o ) => o . name === 'help' ) ) . toBeTruthy ( )
167- } )
168-
169- test ( 'help string' , ( ) => {
170- const command = massarg ( opts )
171- expect ( command . helpString ( ) ) . toContain ( `Usage:` )
172- } )
173-
174- test ( 'print help' , ( ) => {
175- const log = jest . spyOn ( console , 'log' ) . mockImplementation ( ( ) => { } )
176- const command = massarg ( opts )
177- command . printHelp ( )
178- expect ( log ) . toHaveBeenCalled ( )
179- } )
180- } )
181-
18239describe ( 'getArgs' , ( ) => {
18340 test ( 'basic' , ( ) => {
18441 expect ( massarg ( opts ) . getArgs ( [ ] ) ) . toEqual ( { } )
0 commit comments