@@ -51,7 +51,7 @@ const winPaths = [
51
51
] ;
52
52
53
53
const winSpecialCaseParseTests = [
54
- [ '/foo/bar' , { root : '/' } ] ,
54
+ [ '/foo/bar' , { root : '/' , dir : '/foo' , base : 'bar' , ext : '' , name : 'bar' } ] ,
55
55
] ;
56
56
57
57
const winSpecialCaseFormatTests = [
@@ -98,21 +98,16 @@ const unixSpecialCaseFormatTests = [
98
98
[ { } , '' ]
99
99
] ;
100
100
101
- const expectedMessage = common . expectsError ( {
102
- code : 'ERR_INVALID_ARG_TYPE' ,
103
- type : TypeError
104
- } , 18 ) ;
105
-
106
101
const errors = [
107
- { method : 'parse' , input : [ null ] , message : expectedMessage } ,
108
- { method : 'parse' , input : [ { } ] , message : expectedMessage } ,
109
- { method : 'parse' , input : [ true ] , message : expectedMessage } ,
110
- { method : 'parse' , input : [ 1 ] , message : expectedMessage } ,
111
- { method : 'parse' , input : [ ] , message : expectedMessage } ,
112
- { method : 'format' , input : [ null ] , message : expectedMessage } ,
113
- { method : 'format' , input : [ '' ] , message : expectedMessage } ,
114
- { method : 'format' , input : [ true ] , message : expectedMessage } ,
115
- { method : 'format' , input : [ 1 ] , message : expectedMessage } ,
102
+ { method : 'parse' , input : [ null ] } ,
103
+ { method : 'parse' , input : [ { } ] } ,
104
+ { method : 'parse' , input : [ true ] } ,
105
+ { method : 'parse' , input : [ 1 ] } ,
106
+ { method : 'parse' , input : [ ] } ,
107
+ { method : 'format' , input : [ null ] } ,
108
+ { method : 'format' , input : [ '' ] } ,
109
+ { method : 'format' , input : [ true ] } ,
110
+ { method : 'format' , input : [ 1 ] } ,
116
111
] ;
117
112
118
113
checkParseFormat ( path . win32 , winPaths ) ;
@@ -153,10 +148,10 @@ const trailingTests = [
153
148
]
154
149
] ;
155
150
const failures = [ ] ;
156
- trailingTests . forEach ( function ( test ) {
151
+ trailingTests . forEach ( ( test ) => {
157
152
const parse = test [ 0 ] ;
158
153
const os = parse === path . win32 . parse ? 'win32' : 'posix' ;
159
- test [ 1 ] . forEach ( function ( test ) {
154
+ test [ 1 ] . forEach ( ( test ) => {
160
155
const actual = parse ( test [ 0 ] ) ;
161
156
const expected = test [ 1 ] ;
162
157
const message = `path.${ os } .parse(${ JSON . stringify ( test [ 0 ] ) } )\n expect=${
@@ -180,15 +175,18 @@ trailingTests.forEach(function(test) {
180
175
assert . strictEqual ( failures . length , 0 , failures . join ( '' ) ) ;
181
176
182
177
function checkErrors ( path ) {
183
- errors . forEach ( function ( errorCase ) {
178
+ errors . forEach ( ( { method , input } ) => {
184
179
assert . throws ( ( ) => {
185
- path [ errorCase . method ] . apply ( path , errorCase . input ) ;
186
- } , errorCase . message ) ;
180
+ path [ method ] . apply ( path , input ) ;
181
+ } , {
182
+ code : 'ERR_INVALID_ARG_TYPE' ,
183
+ name : 'TypeError'
184
+ } ) ;
187
185
} ) ;
188
186
}
189
187
190
188
function checkParseFormat ( path , paths ) {
191
- paths . forEach ( function ( [ element , root ] ) {
189
+ paths . forEach ( ( [ element , root ] ) => {
192
190
const output = path . parse ( element ) ;
193
191
assert . strictEqual ( typeof output . root , 'string' ) ;
194
192
assert . strictEqual ( typeof output . dir , 'string' ) ;
@@ -205,19 +203,14 @@ function checkParseFormat(path, paths) {
205
203
}
206
204
207
205
function checkSpecialCaseParseFormat ( path , testCases ) {
208
- testCases . forEach ( function ( testCase ) {
209
- const element = testCase [ 0 ] ;
210
- const expect = testCase [ 1 ] ;
211
- const output = path . parse ( element ) ;
212
- Object . keys ( expect ) . forEach ( function ( key ) {
213
- assert . strictEqual ( output [ key ] , expect [ key ] ) ;
214
- } ) ;
206
+ testCases . forEach ( ( [ element , expect ] ) => {
207
+ assert . deepStrictEqual ( path . parse ( element ) , expect ) ;
215
208
} ) ;
216
209
}
217
210
218
211
function checkFormat ( path , testCases ) {
219
- testCases . forEach ( function ( testCase ) {
220
- assert . strictEqual ( path . format ( testCase [ 0 ] ) , testCase [ 1 ] ) ;
212
+ testCases . forEach ( ( [ element , expect ] ) => {
213
+ assert . strictEqual ( path . format ( element ) , expect ) ;
221
214
} ) ;
222
215
223
216
[ null , undefined , 1 , true , false , 'string' ] . forEach ( ( pathObject ) => {
0 commit comments