@@ -1407,14 +1407,16 @@ t.test('ls', (t) => {
14071407 } )
14081408 } )
14091409
1410- t . test ( 'loading a tree containing workspaces' , ( t ) => {
1411- npm . prefix = t . testdir ( {
1410+ t . test ( 'loading a tree containing workspaces' , async ( t ) => {
1411+ npm . localPrefix = npm . prefix = t . testdir ( {
14121412 'package.json' : JSON . stringify ( {
1413- name : 'filter-by-child-of-missing-dep ' ,
1413+ name : 'workspaces-tree ' ,
14141414 version : '1.0.0' ,
14151415 workspaces : [
14161416 './a' ,
14171417 './b' ,
1418+ './d' ,
1419+ './group/*' ,
14181420 ] ,
14191421 } ) ,
14201422 node_modules : {
@@ -1426,13 +1428,29 @@ t.test('ls', (t) => {
14261428 version : '1.0.0' ,
14271429 } ) ,
14281430 } ,
1431+ d : t . fixture ( 'symlink' , '../d' ) ,
1432+ e : t . fixture ( 'symlink' , '../group/e' ) ,
1433+ f : t . fixture ( 'symlink' , '../group/f' ) ,
1434+ foo : {
1435+ 'package.json' : JSON . stringify ( {
1436+ name : 'foo' ,
1437+ version : '1.1.1' ,
1438+ dependencies : {
1439+ bar : '^1.0.0' ,
1440+ } ,
1441+ } ) ,
1442+ } ,
1443+ bar : {
1444+ 'package.json' : JSON . stringify ( { name : 'bar' , version : '1.0.0' } ) ,
1445+ } ,
14291446 } ,
14301447 a : {
14311448 'package.json' : JSON . stringify ( {
14321449 name : 'a' ,
14331450 version : '1.0.0' ,
14341451 dependencies : {
14351452 c : '^1.0.0' ,
1453+ d : '^1.0.0' ,
14361454 } ,
14371455 } ) ,
14381456 } ,
@@ -1442,18 +1460,104 @@ t.test('ls', (t) => {
14421460 version : '1.0.0' ,
14431461 } ) ,
14441462 } ,
1463+ d : {
1464+ 'package.json' : JSON . stringify ( {
1465+ name : 'd' ,
1466+ version : '1.0.0' ,
1467+ dependencies : {
1468+ foo : '^1.1.1' ,
1469+ } ,
1470+ } ) ,
1471+ } ,
1472+ group : {
1473+ e : {
1474+ 'package.json' : JSON . stringify ( {
1475+ name : 'e' ,
1476+ version : '1.0.0' ,
1477+ } ) ,
1478+ } ,
1479+ f : {
1480+ 'package.json' : JSON . stringify ( {
1481+ name : 'f' ,
1482+ version : '1.0.0' ,
1483+ } ) ,
1484+ } ,
1485+ } ,
14451486 } )
14461487
1447- ls . exec ( [ ] , ( err ) => {
1448- t . error ( err , 'should NOT have ELSPROBLEMS error code' )
1449- t . matchSnapshot ( redactCwd ( result ) , 'should list workspaces properly' )
1488+ await new Promise ( ( res , rej ) => {
1489+ config . all = false
1490+ config . depth = 0
1491+ npm . color = true
1492+ ls . exec ( [ ] , ( err ) => {
1493+ if ( err )
1494+ rej ( err )
1495+
1496+ t . matchSnapshot ( redactCwd ( result ) ,
1497+ 'should list workspaces properly with default configs' )
1498+ config . all = true
1499+ config . depth = Infinity
1500+ npm . color = false
1501+ res ( )
1502+ } )
1503+ } )
1504+
1505+ // --all
1506+ await new Promise ( ( res , rej ) => {
1507+ ls . exec ( [ ] , ( err ) => {
1508+ if ( err )
1509+ rej ( err )
1510+
1511+ t . matchSnapshot ( redactCwd ( result ) ,
1512+ 'should list --all workspaces properly' )
1513+ res ( )
1514+ } )
1515+ } )
1516+
1517+ // filter out a single workspace using args
1518+ await new Promise ( ( res , rej ) => {
1519+ ls . exec ( [ 'd' ] , ( err ) => {
1520+ if ( err )
1521+ rej ( err )
14501522
1451- // should also be able to filter out one of the workspaces
1452- ls . exec ( [ 'a' ] , ( err ) => {
1453- t . error ( err , 'should NOT have ELSPROBLEMS error code when filter' )
14541523 t . matchSnapshot ( redactCwd ( result ) , 'should filter single workspace' )
1524+ res ( )
1525+ } )
1526+ } )
1527+
1528+ // filter out a single workspace and its deps using workspaces filters
1529+ await new Promise ( ( res , rej ) => {
1530+ ls . execWorkspaces ( [ ] , [ 'a' ] , ( err ) => {
1531+ if ( err )
1532+ rej ( err )
1533+
1534+ t . matchSnapshot ( redactCwd ( result ) ,
1535+ 'should filter using workspace config' )
1536+ res ( )
1537+ } )
1538+ } )
1539+
1540+ // filter out a workspace by parent path
1541+ await new Promise ( ( res , rej ) => {
1542+ ls . execWorkspaces ( [ ] , [ './group' ] , ( err ) => {
1543+ if ( err )
1544+ rej ( err )
1545+
1546+ t . matchSnapshot ( redactCwd ( result ) ,
1547+ 'should filter by parent folder workspace config' )
1548+ res ( )
1549+ } )
1550+ } )
1551+
1552+ // filter by a dep within a workspaces sub tree
1553+ await new Promise ( ( res , rej ) => {
1554+ ls . execWorkspaces ( [ 'bar' ] , [ 'd' ] , ( err ) => {
1555+ if ( err )
1556+ rej ( err )
14551557
1456- t . end ( )
1558+ t . matchSnapshot ( redactCwd ( result ) ,
1559+ 'should print all tree and filter by dep within only the ws subtree' )
1560+ res ( )
14571561 } )
14581562 } )
14591563 } )
0 commit comments