@@ -11,7 +11,7 @@ const inspect = Symbol.for('nodejs.util.inspect.custom');
1111function App ( options : CreateSessionOptions = { } ) {
1212 const app = new Koa ( ) ;
1313 app . keys = [ 'a' , 'b' ] ;
14- options . store = store ;
14+ options . store = options . store ?? store ;
1515 app . use ( session ( options , app ) ) ;
1616 return app ;
1717}
@@ -21,14 +21,15 @@ describe('Koa Session External Store', () => {
2121
2222 describe ( 'when the session contains a ;' , ( ) => {
2323 it ( 'should still work' , async ( ) => {
24- const app = App ( ) ;
24+ const options : CreateSessionOptions = { store } ;
25+ const app = App ( options ) ;
2526
2627 app . use ( async ( ctx : Koa . Context ) => {
2728 if ( ctx . method === 'POST' ) {
28- ctx . session ! . string = ';' ;
29+ ctx . session . string = ';' ;
2930 ctx . status = 204 ;
3031 } else {
31- ctx . body = ctx . session ! . string ;
32+ ctx . body = ctx . session . string ;
3233 }
3334 } ) ;
3435
@@ -43,6 +44,37 @@ describe('Koa Session External Store', () => {
4344 . set ( 'Cookie' , cookie . join ( ';' ) )
4445 . expect ( ';' ) ;
4546 } ) ;
47+
48+ it ( 'should disable store on options' , async ( ) => {
49+ const options : CreateSessionOptions = { store } ;
50+ const app = App ( options ) ;
51+
52+ app . use ( async ( ctx : Koa . Context ) => {
53+ if ( ctx . method === 'POST' ) {
54+ ctx . session . string = ';' ;
55+ ctx . status = 204 ;
56+ } else {
57+ ctx . body = ctx . session . string ?? 'new session create' ;
58+ }
59+ } ) ;
60+
61+ const server = app . callback ( ) ;
62+ const res = await request ( server )
63+ . post ( '/' )
64+ . expect ( 204 ) ;
65+
66+ const cookie = res . get ( 'Set-Cookie' ) ! ;
67+ await request ( server )
68+ . get ( '/' )
69+ . set ( 'Cookie' , cookie . join ( ';' ) )
70+ . expect ( ';' ) ;
71+
72+ options . store = undefined ;
73+ await request ( server )
74+ . get ( '/' )
75+ . set ( 'Cookie' , cookie . join ( ';' ) )
76+ . expect ( 'new session create' ) ;
77+ } ) ;
4678 } ) ;
4779
4880 describe ( 'new session' , ( ) => {
0 commit comments