@@ -7,6 +7,11 @@ var nodeModulesPaths = require('../lib/node-modules-paths');
7
7
8
8
var verifyDirs = function verifyDirs ( t , start , dirs , moduleDirectories , paths ) {
9
9
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
+ }
10
15
11
16
var foundModuleDirs = { } ;
12
17
var uniqueDirs = { } ;
@@ -20,7 +25,7 @@ var verifyDirs = function verifyDirs(t, start, dirs, moduleDirectories, paths) {
20
25
}
21
26
t . equal ( keys ( parsedDirs ) . length >= start . split ( path . sep ) . length , true , 'there are >= dirs than "start" has' ) ;
22
27
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' ) ;
24
29
t . equal ( keys ( uniqueDirs ) . length , dirs . length , 'all dirs provided were unique' ) ;
25
30
26
31
var counts = { } ;
@@ -49,7 +54,7 @@ test('node-modules-paths', function (t) {
49
54
t . end ( ) ;
50
55
} ) ;
51
56
52
- t . test ( 'with paths option' , function ( t ) {
57
+ t . test ( 'with paths=array option' , function ( t ) {
53
58
var start = path . join ( __dirname , 'resolver' ) ;
54
59
var paths = [ 'a' , 'b' ] ;
55
60
var dirs = nodeModulesPaths ( start , { paths : paths } ) ;
@@ -59,6 +64,19 @@ test('node-modules-paths', function (t) {
59
64
t . end ( ) ;
60
65
} ) ;
61
66
67
+ t . test ( 'with paths=function option' , function ( t ) {
68
+ var paths = function paths ( request , absoluteStart , opts ) {
69
+ return [ path . join ( absoluteStart , 'not node modules' , request ) ] ;
70
+ } ;
71
+
72
+ var start = path . join ( __dirname , 'resolver' ) ;
73
+ var dirs = nodeModulesPaths ( start , { paths : paths } , 'pkg' ) ;
74
+
75
+ verifyDirs ( t , start , dirs , null , [ path . join ( start , 'not node modules' , 'pkg' ) ] ) ;
76
+
77
+ t . end ( ) ;
78
+ } ) ;
79
+
62
80
t . test ( 'with moduleDirectory option' , function ( t ) {
63
81
var start = path . join ( __dirname , 'resolver' ) ;
64
82
var moduleDirectory = 'not node modules' ;
0 commit comments