@@ -1542,3 +1542,48 @@ t.test('invalid single hyphen warnings', async t => {
15421542 [ 'warn' , '-ws is not a valid single-hyphen cli flag and will be removed in the future' ] ,
15431543 ] , 'Warns about single hyphen configs' )
15441544} )
1545+
1546+ t . test ( 'positional arg warnings' , async t => {
1547+ const path = t . testdir ( )
1548+ const logs = [ ]
1549+ const logHandler = ( ...args ) => logs . push ( args )
1550+ process . on ( 'log' , logHandler )
1551+ t . teardown ( ( ) => process . off ( 'log' , logHandler ) )
1552+ const config = new Config ( {
1553+ npmPath : `${ path } /npm` ,
1554+ env : { } ,
1555+ argv : [ process . execPath , __filename , '--something' , 'extra' ] ,
1556+ cwd : path ,
1557+ shorthands,
1558+ definitions,
1559+ nerfDarts,
1560+ } )
1561+ await config . load ( )
1562+ const filtered = logs . filter ( l => l [ 0 ] === 'warn' )
1563+ t . match ( filtered , [
1564+ [ 'warn' , '"extra" is being parsed as a normal command line argument.' ] ,
1565+ [ 'warn' , 'Unknown cli config "--something". This will stop working in the next major version of npm.' ] ,
1566+ ] , 'Warns about positional cli arg' )
1567+ } )
1568+
1569+ t . test ( 'abbreviation expansion warnings' , async t => {
1570+ const path = t . testdir ( )
1571+ const logs = [ ]
1572+ const logHandler = ( ...args ) => logs . push ( args )
1573+ process . on ( 'log' , logHandler )
1574+ t . teardown ( ( ) => process . off ( 'log' , logHandler ) )
1575+ const config = new Config ( {
1576+ npmPath : `${ path } /npm` ,
1577+ env : { } ,
1578+ argv : [ process . execPath , __filename , '--bef' , '2020-01-01' ] ,
1579+ cwd : path ,
1580+ shorthands,
1581+ definitions,
1582+ nerfDarts,
1583+ } )
1584+ await config . load ( )
1585+ const filtered = logs . filter ( l => l [ 0 ] === 'warn' )
1586+ t . match ( filtered , [
1587+ [ 'warn' , 'Expanding --bef to --before. This will stop working in the next major version of npm' ] ,
1588+ ] , 'Warns about expanded abbreviations' )
1589+ } )
0 commit comments