@@ -7,6 +7,11 @@ var nodeModulesPaths = require('../lib/node-modules-paths');
77
88var verifyDirs = function verifyDirs ( t , start , dirs , moduleDirectories , paths ) {
99 var moduleDirs = [ ] . concat ( moduleDirectories || 'node_modules' ) ;
10+ if ( paths ) {
11+ for ( var k = 0 ; k < paths . length ; ++ k ) {
12+ moduleDirs . push ( path . basename ( paths [ k ] ) ) ;
13+ }
14+ }
1015
1116 var foundModuleDirs = { } ;
1217 var uniqueDirs = { } ;
@@ -20,7 +25,7 @@ var verifyDirs = function verifyDirs(t, start, dirs, moduleDirectories, paths) {
2025 }
2126 t . equal ( keys ( parsedDirs ) . length >= start . split ( path . sep ) . length , true , 'there are >= dirs than "start" has' ) ;
2227 var foundModuleDirNames = keys ( foundModuleDirs ) ;
23- t . deepEqual ( foundModuleDirNames , moduleDirs . concat ( paths || [ ] ) , 'all desired module dirs were found' ) ;
28+ t . deepEqual ( foundModuleDirNames , moduleDirs , 'all desired module dirs were found' ) ;
2429 t . equal ( keys ( uniqueDirs ) . length , dirs . length , 'all dirs provided were unique' ) ;
2530
2631 var counts = { } ;
@@ -49,7 +54,7 @@ test('node-modules-paths', function (t) {
4954 t . end ( ) ;
5055 } ) ;
5156
52- t . test ( 'with paths option' , function ( t ) {
57+ t . test ( 'with paths=array option' , function ( t ) {
5358 var start = path . join ( __dirname , 'resolver' ) ;
5459 var paths = [ 'a' , 'b' ] ;
5560 var dirs = nodeModulesPaths ( start , { paths : paths } ) ;
@@ -59,6 +64,16 @@ test('node-modules-paths', function (t) {
5964 t . end ( ) ;
6065 } ) ;
6166
67+ t . test ( 'with paths=function option' , function ( t ) {
68+ var paths = function paths ( absoluteStart , opts ) {
69+ return [ path . join ( absoluteStart , 'not node modules' , opts . request ) ] ;
70+ } ;
71+ var start = path . join ( __dirname , 'resolver' ) ;
72+ var dirs = nodeModulesPaths ( start , { paths : paths , request : 'pkg' } ) ;
73+ verifyDirs ( t , start , dirs , null , [ path . join ( start , 'not node modules' , 'pkg' ) ] ) ;
74+ t . end ( ) ;
75+ } ) ;
76+
6277 t . test ( 'with moduleDirectory option' , function ( t ) {
6378 var start = path . join ( __dirname , 'resolver' ) ;
6479 var moduleDirectory = 'not node modules' ;
0 commit comments