@@ -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,66 @@ 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 ( err ) {
1647
+ if ( err ) res . statusCode = 500
1648
+ } )
1649
+ } )
1650
+
1651
+ request ( server )
1652
+ . get ( '/' )
1653
+ . expect ( shouldSetCookie ( 'connect.sid' ) )
1654
+ . expect ( 200 , function ( err , res ) {
1655
+ if ( err ) return done ( err )
1656
+ request ( server )
1657
+ . get ( '/' )
1658
+ . set ( 'Cookie' , cookie ( res ) )
1659
+ . expect ( shouldSetCookie ( 'connect.sid' ) )
1660
+ . expect ( shouldSetCookieToDifferentSessionId ( sid ( res ) ) )
1661
+ . expect ( 200 , 'false' , done )
1662
+ } )
1663
+ } )
1664
+
1665
+ it ( 'should not return Promise with callback' , function ( done ) {
1666
+ var server = createServer ( null , function ( req , res ) {
1667
+ var id = req . session . id
1668
+ var ret = req . session . regenerate ( function ( err ) {
1669
+ if ( err ) res . statusCode = 500
1670
+ res . statusCode = ( ret === undefined ) ? 200 : 500
1671
+ res . end ( String ( req . session . id === id ) )
1672
+ } )
1673
+ } )
1674
+
1675
+ request ( server )
1676
+ . get ( '/' )
1677
+ . expect ( shouldSetCookie ( 'connect.sid' ) )
1678
+ . expect ( 200 , function ( err , res ) {
1679
+ if ( err ) return done ( err )
1680
+ request ( server )
1681
+ . get ( '/' )
1682
+ . set ( 'Cookie' , cookie ( res ) )
1683
+ . expect ( shouldSetCookie ( 'connect.sid' ) )
1684
+ . expect ( shouldSetCookieToDifferentSessionId ( sid ( res ) ) )
1685
+ . expect ( 200 , 'false' , done )
1686
+ } )
1687
+ } )
1688
+ } )
1629
1689
} )
1630
1690
1631
1691
describe ( '.reload()' , function ( ) {
0 commit comments