File tree Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -454,9 +454,14 @@ class Git extends EventEmitter {
454
454
* closes the server instance
455
455
* @method close
456
456
* @memberof Git
457
+ * @param {Promise } - will resolve or reject when the server closes or fails to close.
457
458
*/
458
- close ( ) {
459
- this . server . close ( ) ;
459
+ close ( callback ) {
460
+ return new Promise ( ( resolve , reject ) => {
461
+ this . server . close ( ( err ) => {
462
+ err ? reject ( err ) : resolve ( ) ;
463
+ } ) ;
464
+ } ) ;
460
465
}
461
466
}
462
467
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ const async = require('async');
10
10
const GitServer = require ( '../' ) ;
11
11
12
12
test ( 'git' , ( t ) => {
13
- t . plan ( 8 ) ;
13
+ t . plan ( 9 ) ;
14
14
15
15
t . test ( 'create, push to, and clone a repo' , ( t ) => {
16
16
var lastCommit ;
@@ -623,6 +623,20 @@ test('git', (t) => {
623
623
} ) ;
624
624
} ) ;
625
625
626
+ t . test ( 'should return promise that resolves when server is closed if no callback specified' , ( t ) => {
627
+ const repoDir = `/tmp/${ Math . floor ( Math . random ( ) * ( 1 << 30 ) ) . toString ( 16 ) } ` ;
628
+
629
+ fs . mkdirSync ( repoDir , 0700 ) ;
630
+
631
+ const repos = new GitServer ( repoDir ) ;
632
+ const port = Math . floor ( Math . random ( ) * ( ( 1 << 16 ) - 1e4 ) ) + 1e4 ;
633
+ repos . listen ( port , ( ) => {
634
+ repos . close ( ) . then ( ( ) => {
635
+ t . end ( ) ;
636
+ } ) ;
637
+ } ) ;
638
+ } ) ;
639
+
626
640
t . test ( 'should be able to protect certain routes' , ( t ) => {
627
641
const repoDir = `/tmp/${ Math . floor ( Math . random ( ) * ( 1 << 30 ) ) . toString ( 16 ) } ` ;
628
642
const srcDir = `/tmp/${ Math . floor ( Math . random ( ) * ( 1 << 30 ) ) . toString ( 16 ) } ` ;
You can’t perform that action at this time.
0 commit comments