1- 'use strict' ;
2-
1+ /* global assert */
32/* eslint max-len: 0 */
3+ 'use strict' ;
44
5- const test = require ( 'tape ' ) ;
5+ const { test } = require ( './utils ' ) ;
66const { parseArgs } = require ( '../index.js' ) ;
77
8- test ( 'default must be a boolean when option type is boolean' , ( t ) => {
8+ test ( 'default must be a boolean when option type is boolean' , ( ) => {
99 const args = [ ] ;
1010 const options = { alpha : { type : 'boolean' , default : 'not a boolean' } } ;
11- t . throws ( ( ) => {
11+ assert . throws ( ( ) => {
1212 parseArgs ( { args, options } ) ;
13- } , / a l p h a \. d e f a u l t m u s t b e B o o l e a n /
13+ } , / o p t i o n s \. a l p h a \. d e f a u l t m u s t b e B o o l e a n /
1414 ) ;
15- t . end ( ) ;
1615} ) ;
1716
18- test ( 'default must be a boolean array when option type is boolean and multiple' , ( t ) => {
17+ test ( 'default must accept undefined value' , ( ) => {
18+ const args = [ ] ;
19+ const options = { alpha : { type : 'boolean' , default : undefined } } ;
20+ const result = parseArgs ( { args, options } ) ;
21+ const expected = {
22+ values : {
23+ __proto__ : null ,
24+ } ,
25+ positionals : [ ]
26+ } ;
27+ assert . deepStrictEqual ( result , expected ) ;
28+ } ) ;
29+
30+ test ( 'default must be a boolean array when option type is boolean and multiple' , ( ) => {
1931 const args = [ ] ;
2032 const options = { alpha : { type : 'boolean' , multiple : true , default : 'not an array' } } ;
21- t . throws ( ( ) => {
33+ assert . throws ( ( ) => {
2234 parseArgs ( { args, options } ) ;
23- } , / a l p h a \. d e f a u l t m u s t b e A r r a y /
35+ } , / o p t i o n s \. a l p h a \. d e f a u l t m u s t b e A r r a y /
2436 ) ;
25- t . end ( ) ;
2637} ) ;
2738
28- test ( 'default must be a boolean array when option type is string and multiple is true' , ( t ) => {
39+ test ( 'default must be a boolean array when option type is string and multiple is true' , ( ) => {
2940 const args = [ ] ;
3041 const options = { alpha : { type : 'boolean' , multiple : true , default : [ true , true , 42 ] } } ;
31- t . throws ( ( ) => {
42+ assert . throws ( ( ) => {
3243 parseArgs ( { args, options } ) ;
33- } , / a l p h a \. d e f a u l t \[ 2 \] m u s t b e B o o l e a n /
44+ } , / o p t i o n s \. a l p h a \. d e f a u l t \[ 2 \] m u s t b e B o o l e a n /
3445 ) ;
35- t . end ( ) ;
3646} ) ;
3747
38- test ( 'default must be a string when option type is string' , ( t ) => {
48+ test ( 'default must be a string when option type is string' , ( ) => {
3949 const args = [ ] ;
4050 const options = { alpha : { type : 'string' , default : true } } ;
41- t . throws ( ( ) => {
51+ assert . throws ( ( ) => {
4252 parseArgs ( { args, options } ) ;
43- } , / a l p h a \. d e f a u l t m u s t b e S t r i n g /
53+ } , / o p t i o n s \. a l p h a \. d e f a u l t m u s t b e S t r i n g /
4454 ) ;
45- t . end ( ) ;
4655} ) ;
4756
48- test ( 'default must be an array when option type is string and multiple is true' , ( t ) => {
57+ test ( 'default must be an array when option type is string and multiple is true' , ( ) => {
4958 const args = [ ] ;
5059 const options = { alpha : { type : 'string' , multiple : true , default : 'not an array' } } ;
51- t . throws ( ( ) => {
60+ assert . throws ( ( ) => {
5261 parseArgs ( { args, options } ) ;
53- } , / a l p h a \. d e f a u l t m u s t b e A r r a y /
62+ } , / o p t i o n s \. a l p h a \. d e f a u l t m u s t b e A r r a y /
5463 ) ;
55- t . end ( ) ;
5664} ) ;
5765
58- test ( 'default must be a string array when option type is string and multiple is true' , ( t ) => {
66+ test ( 'default must be a string array when option type is string and multiple is true' , ( ) => {
5967 const args = [ ] ;
6068 const options = { alpha : { type : 'string' , multiple : true , default : [ 'str' , 42 ] } } ;
61- t . throws ( ( ) => {
69+ assert . throws ( ( ) => {
6270 parseArgs ( { args, options } ) ;
63- } , / a l p h a \. d e f a u l t \[ 1 \] m u s t b e S t r i n g /
71+ } , / o p t i o n s \. a l p h a \. d e f a u l t \[ 1 \] m u s t b e S t r i n g /
6472 ) ;
65- t . end ( ) ;
6673} ) ;
6774
68- test ( 'default accepted input when multiple is true' , ( t ) => {
75+ test ( 'default accepted input when multiple is true' , ( ) => {
6976 const args = [ '--inputStringArr' , 'c' , '--inputStringArr' , 'd' , '--inputBoolArr' , '--inputBoolArr' ] ;
7077 const options = {
7178 inputStringArr : { type : 'string' , multiple : true , default : [ 'a' , 'b' ] } ,
@@ -84,11 +91,10 @@ test('default accepted input when multiple is true', (t) => {
8491 fullBoolArr : [ false , true , false ] } ,
8592 positionals : [ ] } ;
8693 const result = parseArgs ( { args, options } ) ;
87- t . deepEqual ( result , expected ) ;
88- t . end ( ) ;
94+ assert . deepStrictEqual ( result , expected ) ;
8995} ) ;
9096
91- test ( 'when default is set, the option must be added as result' , ( t ) => {
97+ test ( 'when default is set, the option must be added as result' , ( ) => {
9298 const args = [ ] ;
9399 const options = {
94100 a : { type : 'string' , default : 'HELLO' } ,
@@ -98,12 +104,10 @@ test('when default is set, the option must be added as result', (t) => {
98104 const expected = { values : { __proto__ : null , a : 'HELLO' , b : false , c : true } , positionals : [ ] } ;
99105
100106 const result = parseArgs ( { args, options } ) ;
101-
102- t . deepEqual ( result , expected ) ;
103- t . end ( ) ;
107+ assert . deepStrictEqual ( result , expected ) ;
104108} ) ;
105109
106- test ( 'when default is set, the args value takes precedence' , ( t ) => {
110+ test ( 'when default is set, the args value takes precedence' , ( ) => {
107111 const args = [ '--a' , 'WORLD' , '--b' , '-c' ] ;
108112 const options = {
109113 a : { type : 'string' , default : 'HELLO' } ,
@@ -113,12 +117,10 @@ test('when default is set, the args value takes precedence', (t) => {
113117 const expected = { values : { __proto__ : null , a : 'WORLD' , b : true , c : true } , positionals : [ ] } ;
114118
115119 const result = parseArgs ( { args, options } ) ;
116-
117- t . deepEqual ( result , expected ) ;
118- t . end ( ) ;
120+ assert . deepStrictEqual ( result , expected ) ;
119121} ) ;
120122
121- test ( 'tokens should not include the default options' , ( t ) => {
123+ test ( 'tokens should not include the default options' , ( ) => {
122124 const args = [ ] ;
123125 const options = {
124126 a : { type : 'string' , default : 'HELLO' } ,
@@ -129,11 +131,10 @@ test('tokens should not include the default options', (t) => {
129131 const expectedTokens = [ ] ;
130132
131133 const { tokens } = parseArgs ( { args, options, tokens : true } ) ;
132- t . deepEqual ( tokens , expectedTokens ) ;
133- t . end ( ) ;
134+ assert . deepStrictEqual ( tokens , expectedTokens ) ;
134135} ) ;
135136
136- test ( 'tokens:true should not include the default options after the args input' , ( t ) => {
137+ test ( 'tokens:true should not include the default options after the args input' , ( ) => {
137138 const args = [ '--z' , 'zero' , 'positional-item' ] ;
138139 const options = {
139140 z : { type : 'string' } ,
@@ -148,11 +149,10 @@ test('tokens:true should not include the default options after the args input',
148149 ] ;
149150
150151 const { tokens } = parseArgs ( { args, options, tokens : true , allowPositionals : true } ) ;
151- t . deepEqual ( tokens , expectedTokens ) ;
152- t . end ( ) ;
152+ assert . deepStrictEqual ( tokens , expectedTokens ) ;
153153} ) ;
154154
155- test ( 'proto as default value must be ignored' , ( t ) => {
155+ test ( 'proto as default value must be ignored' , ( ) => {
156156 const args = [ ] ;
157157 const options = Object . create ( null ) ;
158158
@@ -161,17 +161,14 @@ test('proto as default value must be ignored', (t) => {
161161
162162 const result = parseArgs ( { args, options, allowPositionals : true } ) ;
163163 const expected = { values : { __proto__ : null } , positionals : [ ] } ;
164- t . deepEqual ( result , expected ) ;
165- t . end ( ) ;
164+ assert . deepStrictEqual ( result , expected ) ;
166165} ) ;
167166
168167
169- test ( 'multiple as false should expect a String' , ( t ) => {
168+ test ( 'multiple as false should expect a String' , ( ) => {
170169 const args = [ ] ;
171170 const options = { alpha : { type : 'string' , multiple : false , default : [ 'array' ] } } ;
172- t . throws ( ( ) => {
171+ assert . throws ( ( ) => {
173172 parseArgs ( { args, options } ) ;
174- } , / a l p h a \. d e f a u l t m u s t b e S t r i n g /
175- ) ;
176- t . end ( ) ;
173+ } , / m u s t b e S t r i n g g o t a r r a y / ) ;
177174} ) ;
0 commit comments