@@ -67,7 +67,15 @@ function stopServers(callback, index) {
6767}
6868
6969function cleanup ( callback ) {
70- fs . rmdirSync ( badDir ) ;
70+ if ( fs . existsSync ( path . join ( badDir , 'deeply' , 'nested' ) ) ) {
71+ fs . rmdirSync ( path . join ( badDir , 'deeply' , 'nested' ) ) ;
72+ }
73+ if ( fs . existsSync ( path . join ( badDir , 'deeply' ) ) ) {
74+ fs . rmdirSync ( path . join ( badDir , 'deeply' ) ) ;
75+ }
76+ if ( fs . existsSync ( badDir ) ) {
77+ fs . rmdirSync ( badDir ) ;
78+ }
7179 stopServers ( callback , 0 ) ;
7280}
7381
@@ -81,7 +89,7 @@ vows.describe('portfinder').addBatch({
8189 } , this . callback ) ;
8290 } . bind ( this ) ) ;
8391 } ,
84- "the getPort () method" : {
92+ "the getSocket () method" : {
8593 topic : function ( ) {
8694 portfinder . getSocket ( {
8795 path : path . join ( socketDir , 'test.sock' )
@@ -98,7 +106,7 @@ vows.describe('portfinder').addBatch({
98106 "When using portfinder module" : {
99107 "with no existing servers" : {
100108 "the getSocket() method" : {
101- "with a directory that doesnt exist" : {
109+ "with a directory that doesn't exist" : {
102110 topic : function ( ) {
103111 fs . rmdir ( badDir , function ( ) {
104112 portfinder . getSocket ( {
@@ -111,6 +119,24 @@ vows.describe('portfinder').addBatch({
111119 assert . equal ( socket , path . join ( badDir , 'test.sock' ) ) ;
112120 }
113121 } ,
122+ "with a nested directory that doesn't exist" : {
123+ topic : function ( ) {
124+ var that = this ;
125+ fs . rmdir ( path . join ( badDir , 'deeply' , 'nested' ) , function ( ) {
126+ fs . rmdir ( path . join ( badDir , 'deeply' ) , function ( ) {
127+ fs . rmdir ( badDir , function ( ) {
128+ portfinder . getSocket ( {
129+ path : path . join ( badDir , 'deeply' , 'nested' , 'test.sock' )
130+ } , that . callback ) ;
131+ } ) ;
132+ } ) ;
133+ } ) ;
134+ } ,
135+ "should respond with the first free socket (test.sock)" : function ( err , socket ) {
136+ assert . isTrue ( ! err ) ;
137+ assert . equal ( socket , path . join ( badDir , 'deeply' , 'nested' , 'test.sock' ) ) ;
138+ }
139+ } ,
114140 "with a directory that exists" : {
115141 topic : function ( ) {
116142 portfinder . getSocket ( {
0 commit comments