@@ -81,6 +81,7 @@ let result = ''
81
81
// note this _flatOptions representations is for tests-only and does not
82
82
// represent exactly the properties found in the actual flatOptions obj
83
83
const _flatOptions = {
84
+ all : true ,
84
85
color : false ,
85
86
dev : false ,
86
87
depth : Infinity ,
@@ -270,7 +271,31 @@ test('ls', (t) => {
270
271
} )
271
272
} )
272
273
274
+ t . test ( 'default --depth value should be 0' , ( t ) => {
275
+ _flatOptions . all = false
276
+ _flatOptions . depth = undefined
277
+ prefix = t . testdir ( {
278
+ 'package.json' : JSON . stringify ( {
279
+ name : 'test-npm-ls' ,
280
+ version : '1.0.0' ,
281
+ dependencies : {
282
+ foo : '^1.0.0' ,
283
+ lorem : '^1.0.0'
284
+ }
285
+ } ) ,
286
+ ...simpleNmFixture
287
+ } )
288
+ ls ( [ ] , ( err ) => {
289
+ t . ifError ( err , 'npm ls' )
290
+ t . matchSnapshot ( redactCwd ( result ) , 'should output tree containing only top-level dependencies' )
291
+ _flatOptions . all = true
292
+ _flatOptions . depth = Infinity
293
+ t . end ( )
294
+ } )
295
+ } )
296
+
273
297
t . test ( '--depth=0' , ( t ) => {
298
+ _flatOptions . all = false
274
299
_flatOptions . depth = 0
275
300
prefix = t . testdir ( {
276
301
'package.json' : JSON . stringify ( {
@@ -286,12 +311,14 @@ test('ls', (t) => {
286
311
ls ( [ ] , ( err ) => {
287
312
t . ifError ( err , 'npm ls' )
288
313
t . matchSnapshot ( redactCwd ( result ) , 'should output tree containing only top-level dependencies' )
314
+ _flatOptions . all = true
289
315
_flatOptions . depth = Infinity
290
316
t . end ( )
291
317
} )
292
318
} )
293
319
294
320
t . test ( '--depth=1' , ( t ) => {
321
+ _flatOptions . all = false
295
322
_flatOptions . depth = 1
296
323
prefix = t . testdir ( {
297
324
'package.json' : JSON . stringify ( {
@@ -345,13 +372,13 @@ test('ls', (t) => {
345
372
ls ( [ ] , ( err ) => {
346
373
t . ifError ( err , 'npm ls' )
347
374
t . matchSnapshot ( redactCwd ( result ) , 'should output tree containing top-level deps and their deps only' )
375
+ _flatOptions . all = true
348
376
_flatOptions . depth = Infinity
349
377
t . end ( )
350
378
} )
351
379
} )
352
380
353
381
t . test ( 'missing/invalid/extraneous' , ( t ) => {
354
- _flatOptions . depth = 1
355
382
prefix = t . testdir ( {
356
383
'package.json' : JSON . stringify ( {
357
384
name : 'test-npm-ls' ,
@@ -373,7 +400,6 @@ test('ls', (t) => {
373
400
'should log missing/invalid/extraneous errors'
374
401
)
375
402
t . matchSnapshot ( redactCwd ( result ) , 'should output tree containing missing, invalid, extraneous labels' )
376
- _flatOptions . depth = Infinity
377
403
t . end ( )
378
404
} )
379
405
} )
@@ -584,6 +610,7 @@ test('ls', (t) => {
584
610
} )
585
611
586
612
t . test ( '--long --depth=0' , ( t ) => {
613
+ _flatOptions . all = false
587
614
_flatOptions . depth = 0
588
615
_flatOptions . long = true
589
616
prefix = t . testdir ( {
@@ -608,6 +635,7 @@ test('ls', (t) => {
608
635
} )
609
636
ls ( [ ] , ( ) => {
610
637
t . matchSnapshot ( redactCwd ( result ) , 'should output tree containing top-level deps with descriptions' )
638
+ _flatOptions . all = true
611
639
_flatOptions . depth = Infinity
612
640
_flatOptions . long = false
613
641
t . end ( )
@@ -1040,7 +1068,7 @@ test('ls --parseable', (t) => {
1040
1068
} )
1041
1069
ls ( [ 'notadep' ] , ( err ) => {
1042
1070
t . ifError ( err , 'npm ls' )
1043
- t . matchSnapshot ( redactCwd ( result ) , 'should output tree containing no dependencies info' )
1071
+ t . matchSnapshot ( redactCwd ( result ) , 'should output parseable output containing no dependencies info' )
1044
1072
t . equal (
1045
1073
process . exitCode ,
1046
1074
1 ,
@@ -1051,7 +1079,31 @@ test('ls --parseable', (t) => {
1051
1079
} )
1052
1080
} )
1053
1081
1082
+ t . test ( 'default --depth value should be 0' , ( t ) => {
1083
+ _flatOptions . all = false
1084
+ _flatOptions . depth = undefined
1085
+ prefix = t . testdir ( {
1086
+ 'package.json' : JSON . stringify ( {
1087
+ name : 'test-npm-ls' ,
1088
+ version : '1.0.0' ,
1089
+ dependencies : {
1090
+ foo : '^1.0.0' ,
1091
+ lorem : '^1.0.0'
1092
+ }
1093
+ } ) ,
1094
+ ...simpleNmFixture
1095
+ } )
1096
+ ls ( [ ] , ( err ) => {
1097
+ t . ifError ( err , 'npm ls' )
1098
+ t . matchSnapshot ( redactCwd ( result ) , 'should output parseable output containing only top-level dependencies' )
1099
+ _flatOptions . all = true
1100
+ _flatOptions . depth = Infinity
1101
+ t . end ( )
1102
+ } )
1103
+ } )
1104
+
1054
1105
t . test ( '--depth=0' , ( t ) => {
1106
+ _flatOptions . all = false
1055
1107
_flatOptions . depth = 0
1056
1108
prefix = t . testdir ( {
1057
1109
'package.json' : JSON . stringify ( {
@@ -1067,12 +1119,14 @@ test('ls --parseable', (t) => {
1067
1119
ls ( [ ] , ( err ) => {
1068
1120
t . ifError ( err , 'npm ls' )
1069
1121
t . matchSnapshot ( redactCwd ( result ) , 'should output tree containing only top-level dependencies' )
1122
+ _flatOptions . all = true
1070
1123
_flatOptions . depth = Infinity
1071
1124
t . end ( )
1072
1125
} )
1073
1126
} )
1074
1127
1075
1128
t . test ( '--depth=1' , ( t ) => {
1129
+ _flatOptions . all = false
1076
1130
_flatOptions . depth = 1
1077
1131
prefix = t . testdir ( {
1078
1132
'package.json' : JSON . stringify ( {
@@ -1088,6 +1142,7 @@ test('ls --parseable', (t) => {
1088
1142
ls ( [ ] , ( err ) => {
1089
1143
t . ifError ( err , 'npm ls' )
1090
1144
t . matchSnapshot ( redactCwd ( result ) , 'should output parseable containing top-level deps and their deps only' )
1145
+ _flatOptions . all = true
1091
1146
_flatOptions . depth = Infinity
1092
1147
t . end ( )
1093
1148
} )
@@ -1377,6 +1432,7 @@ test('ls --parseable', (t) => {
1377
1432
} )
1378
1433
1379
1434
t . test ( '--long --depth=0' , ( t ) => {
1435
+ _flatOptions . all = false
1380
1436
_flatOptions . depth = 0
1381
1437
_flatOptions . long = true
1382
1438
prefix = t . testdir ( {
@@ -1401,6 +1457,7 @@ test('ls --parseable', (t) => {
1401
1457
} )
1402
1458
ls ( [ ] , ( ) => {
1403
1459
t . matchSnapshot ( redactCwd ( result ) , 'should output tree containing top-level deps with descriptions' )
1460
+ _flatOptions . all = true
1404
1461
_flatOptions . depth = Infinity
1405
1462
_flatOptions . long = false
1406
1463
t . end ( )
@@ -1923,7 +1980,46 @@ test('ls --json', (t) => {
1923
1980
} )
1924
1981
} )
1925
1982
1983
+ t . test ( 'default --depth value should now be 0' , ( t ) => {
1984
+ _flatOptions . all = false
1985
+ _flatOptions . depth = undefined
1986
+ prefix = t . testdir ( {
1987
+ 'package.json' : JSON . stringify ( {
1988
+ name : 'test-npm-ls' ,
1989
+ version : '1.0.0' ,
1990
+ dependencies : {
1991
+ foo : '^1.0.0' ,
1992
+ lorem : '^1.0.0'
1993
+ }
1994
+ } ) ,
1995
+ ...simpleNmFixture
1996
+ } )
1997
+ ls ( [ ] , ( err ) => {
1998
+ t . ifError ( err , 'npm ls' )
1999
+ t . deepEqual (
2000
+ jsonParse ( result ) ,
2001
+ {
2002
+ name : 'test-npm-ls' ,
2003
+ version : '1.0.0' ,
2004
+ 'dependencies' : {
2005
+ 'foo' : {
2006
+ 'version' : '1.0.0'
2007
+ } ,
2008
+ 'lorem' : {
2009
+ 'version' : '1.0.0'
2010
+ }
2011
+ }
2012
+ } ,
2013
+ 'should output json containing only top-level dependencies'
2014
+ )
2015
+ _flatOptions . all = true
2016
+ _flatOptions . depth = Infinity
2017
+ t . end ( )
2018
+ } )
2019
+ } )
2020
+
1926
2021
t . test ( '--depth=0' , ( t ) => {
2022
+ _flatOptions . all = false
1927
2023
_flatOptions . depth = 0
1928
2024
prefix = t . testdir ( {
1929
2025
'package.json' : JSON . stringify ( {
@@ -1954,12 +2050,14 @@ test('ls --json', (t) => {
1954
2050
} ,
1955
2051
'should output json containing only top-level dependencies'
1956
2052
)
2053
+ _flatOptions . all = true
1957
2054
_flatOptions . depth = Infinity
1958
2055
t . end ( )
1959
2056
} )
1960
2057
} )
1961
2058
1962
2059
t . test ( '--depth=1' , ( t ) => {
2060
+ _flatOptions . all = false
1963
2061
_flatOptions . depth = 1
1964
2062
prefix = t . testdir ( {
1965
2063
'package.json' : JSON . stringify ( {
@@ -1995,13 +2093,13 @@ test('ls --json', (t) => {
1995
2093
} ,
1996
2094
'should output json containing top-level deps and their deps only'
1997
2095
)
2096
+ _flatOptions . all = true
1998
2097
_flatOptions . depth = Infinity
1999
2098
t . end ( )
2000
2099
} )
2001
2100
} )
2002
2101
2003
2102
t . test ( 'missing/invalid/extraneous' , ( t ) => {
2004
- _flatOptions . depth = 1
2005
2103
prefix = t . testdir ( {
2006
2104
'package.json' : JSON . stringify ( {
2007
2105
name : 'test-npm-ls' ,
@@ -2056,7 +2154,6 @@ test('ls --json', (t) => {
2056
2154
} ,
2057
2155
'should output json containing top-level deps and their deps only'
2058
2156
)
2059
- _flatOptions . depth = Infinity
2060
2157
t . end ( )
2061
2158
} )
2062
2159
} )
@@ -2555,6 +2652,7 @@ test('ls --json', (t) => {
2555
2652
} )
2556
2653
2557
2654
t . test ( '--long --depth=0' , ( t ) => {
2655
+ _flatOptions . all = false
2558
2656
_flatOptions . depth = 0
2559
2657
_flatOptions . long = true
2560
2658
prefix = t . testdir ( {
@@ -2649,6 +2747,7 @@ test('ls --json', (t) => {
2649
2747
} ,
2650
2748
'should output json containing top-level deps in long format'
2651
2749
)
2750
+ _flatOptions . all = true
2652
2751
_flatOptions . depth = Infinity
2653
2752
_flatOptions . long = false
2654
2753
t . end ( )
0 commit comments