@@ -1603,7 +1603,7 @@ describe('session()', function(){
1603
1603
} )
1604
1604
} )
1605
1605
1606
- describe ( '.regenerate()' , function ( ) {
1606
+ describe ( '.regenerate()' , function ( ) {
1607
1607
it ( 'should destroy/replace the previous session' , function ( done ) {
1608
1608
var server = createServer ( null , function ( req , res ) {
1609
1609
var id = req . session . id
@@ -1626,6 +1626,83 @@ describe('session()', function(){
1626
1626
. expect ( 200 , 'false' , done )
1627
1627
} ) ;
1628
1628
} )
1629
+
1630
+ describe ( 'with global Promise' , function ( ) {
1631
+ beforeEach ( function ( ) {
1632
+ global . Promise = Promise
1633
+ } )
1634
+
1635
+ afterEach ( function ( ) {
1636
+ global . Promise = undefined
1637
+ } )
1638
+
1639
+ it ( 'should return Promise without callback' , function ( done ) {
1640
+ var server = createServer ( null , function ( req , res ) {
1641
+ var id = req . session . id
1642
+ req . session . regenerate ( )
1643
+ . then ( function ( ) {
1644
+ res . end ( String ( req . session . id === id ) )
1645
+ } )
1646
+ . catch ( function ( ) {
1647
+ res . statusCode = 500
1648
+ } )
1649
+ } )
1650
+
1651
+ request ( server )
1652
+ . get ( '/' )
1653
+ . expect ( 200 , 'false' , done )
1654
+ } )
1655
+
1656
+ it ( 'should not return Promise with callback' , function ( done ) {
1657
+ var server = createServer ( null , function ( req , res ) {
1658
+ var id = req . session . id
1659
+ var ret = req . session . regenerate ( function ( err ) {
1660
+ res . statusCode = ( ! err && ret === undefined ) ? 200 : 500
1661
+ res . end ( String ( req . session . id === id ) )
1662
+ } )
1663
+ } )
1664
+
1665
+ request ( server )
1666
+ . get ( '/' )
1667
+ . expect ( 200 , 'false' , done )
1668
+ } )
1669
+ } )
1670
+
1671
+ describe ( 'without global Promise' , function ( ) {
1672
+ beforeEach ( function ( ) {
1673
+ global . Promise = undefined
1674
+ } )
1675
+
1676
+ afterEach ( function ( ) {
1677
+ global . Promise = Promise
1678
+ } )
1679
+
1680
+ it ( 'should error without callback' , function ( done ) {
1681
+ var server = createServer ( null , function ( req , res ) {
1682
+ req . session . regenerate ( )
1683
+ res . end ( )
1684
+ } )
1685
+
1686
+ request ( server )
1687
+ . get ( '/' )
1688
+ . expect ( 500 , 'must use callback without promises' , done )
1689
+ } )
1690
+
1691
+ it ( 'should not return Promise with callback' , function ( done ) {
1692
+ var server = createServer ( null , function ( req , res ) {
1693
+ var id = req . session . id
1694
+ var ret = req . session . regenerate ( function ( err ) {
1695
+ res . statusCode = ( ! err && ret === undefined ) ? 200 : 500
1696
+ res . end ( String ( req . session . id === id ) )
1697
+ } )
1698
+ } )
1699
+
1700
+ request ( server )
1701
+ . get ( '/' )
1702
+ . expect ( shouldSetCookie ( 'connect.sid' ) )
1703
+ . expect ( 200 , 'false' , done )
1704
+ } )
1705
+ } )
1629
1706
} )
1630
1707
1631
1708
describe ( '.reload()' , function ( ) {
@@ -2371,7 +2448,12 @@ function createRequestListener(opts, fn) {
2371
2448
return
2372
2449
}
2373
2450
2374
- respond ( req , res )
2451
+ try {
2452
+ respond ( req , res )
2453
+ } catch ( e ) {
2454
+ res . statusCode = 500
2455
+ res . end ( e . message )
2456
+ }
2375
2457
} )
2376
2458
}
2377
2459
}
0 commit comments