@@ -44,16 +44,17 @@ describe('Class: Router - Middleware', () => {
44
44
const app = new Router ( ) ;
45
45
const executionOrder : string [ ] = [ ] ;
46
46
47
- app . use ( async ( _params , _reqCtx , next ) => {
47
+ app . use ( async ( { next } ) => {
48
48
executionOrder . push ( 'global-middleware' ) ;
49
49
await next ( ) ;
50
50
} ) ;
51
51
52
52
const middleware : Middleware [ ] = middlewareNames . map (
53
- ( name ) => async ( _params , _reqCtx , next ) => {
54
- executionOrder . push ( name ) ;
55
- await next ( ) ;
56
- }
53
+ ( name ) =>
54
+ async ( { next } ) => {
55
+ executionOrder . push ( name ) ;
56
+ await next ( ) ;
57
+ }
57
58
) ;
58
59
59
60
app . get ( path as Path , middleware , async ( ) => {
@@ -137,7 +138,7 @@ describe('Class: Router - Middleware', () => {
137
138
let middlewareParams : Record < string , string > | undefined ;
138
139
let middlewareOptions : RequestContext | undefined ;
139
140
140
- app . use ( async ( params , reqCtx , next ) => {
141
+ app . use ( async ( { params, reqCtx, next } ) => {
141
142
middlewareParams = params ;
142
143
middlewareOptions = reqCtx ;
143
144
await next ( ) ;
@@ -153,15 +154,15 @@ describe('Class: Router - Middleware', () => {
153
154
expect ( middlewareParams ) . toEqual ( { id : '123' } ) ;
154
155
expect ( middlewareOptions ?. event ) . toBe ( testEvent ) ;
155
156
expect ( middlewareOptions ?. context ) . toBe ( context ) ;
156
- expect ( middlewareOptions ?. request ) . toBeInstanceOf ( Request ) ;
157
+ expect ( middlewareOptions ?. req ) . toBeInstanceOf ( Request ) ;
157
158
} ) ;
158
159
159
160
it ( 'returns error response when next() is called multiple times' , async ( ) => {
160
161
// Prepare
161
162
vi . stubEnv ( 'POWERTOOLS_DEV' , 'true' ) ;
162
163
const app = new Router ( ) ;
163
164
164
- app . use ( async ( _params , _reqCtx , next ) => {
165
+ app . use ( async ( { next } ) => {
165
166
await next ( ) ;
166
167
await next ( ) ;
167
168
} ) ;
@@ -185,11 +186,11 @@ describe('Class: Router - Middleware', () => {
185
186
vi . stubEnv ( 'POWERTOOLS_DEV' , 'true' ) ;
186
187
const app = new Router ( ) ;
187
188
188
- app . use ( async ( _params , _reqCtx , next ) => {
189
+ app . use ( async ( { next } ) => {
189
190
await next ( ) ;
190
191
} ) ;
191
192
192
- app . use ( async ( _params , _reqCtx , next ) => {
193
+ app . use ( async ( { next } ) => {
193
194
next ( ) ;
194
195
} ) ;
195
196
@@ -241,7 +242,7 @@ describe('Class: Router - Middleware', () => {
241
242
const app = new Router ( ) ;
242
243
const executionOrder : string [ ] = [ ] ;
243
244
244
- app . use ( async ( _params , _reqCtx , next ) => {
245
+ app . use ( async ( { next } ) => {
245
246
executionOrder . push ( 'middleware1-start' ) ;
246
247
await next ( ) ;
247
248
executionOrder . push ( 'middleware1-end' ) ;
@@ -362,7 +363,7 @@ describe('Class: Router - Middleware', () => {
362
363
// Prepare
363
364
const app = new Router ( ) ;
364
365
365
- app . use ( async ( _params , reqCtx , next ) => {
366
+ app . use ( async ( { reqCtx, next } ) => {
366
367
await next ( ) ;
367
368
reqCtx . res . headers . set ( 'x-custom-header' , 'middleware-value' ) ;
368
369
reqCtx . res . headers . set ( 'x-request-id' , '12345' ) ;
@@ -393,7 +394,7 @@ describe('Class: Router - Middleware', () => {
393
394
// Prepare
394
395
const app = new Router ( ) ;
395
396
396
- app . use ( async ( _params , reqCtx , next ) => {
397
+ app . use ( async ( { reqCtx, next } ) => {
397
398
await next ( ) ;
398
399
const originalBody = await reqCtx . res . text ( ) ;
399
400
reqCtx . res = new Response ( `Modified: ${ originalBody } ` , {
@@ -422,7 +423,7 @@ describe('Class: Router - Middleware', () => {
422
423
// Prepare
423
424
const app = new Router ( ) ;
424
425
425
- app . use ( async ( _params , reqCtx , next ) => {
426
+ app . use ( async ( { reqCtx, next } ) => {
426
427
reqCtx . res . headers . set ( 'x-before-handler' , 'middleware-value' ) ;
427
428
await next ( ) ;
428
429
} ) ;
@@ -451,7 +452,7 @@ describe('Class: Router - Middleware', () => {
451
452
// Prepare
452
453
const app = new Router ( ) ;
453
454
454
- app . use ( async ( _params , reqCtx , next ) => {
455
+ app . use ( async ( { reqCtx, next } ) => {
455
456
reqCtx . res . headers . set ( 'x-before-handler' , 'middleware-value' ) ;
456
457
await next ( ) ;
457
458
} ) ;
@@ -478,12 +479,12 @@ describe('Class: Router - Middleware', () => {
478
479
// Prepare
479
480
const app = new Router ( ) ;
480
481
481
- app . use ( async ( _params , reqCtx , next ) => {
482
+ app . use ( async ( { reqCtx, next } ) => {
482
483
reqCtx . res . headers . set ( 'x-test-header' , 'before-next' ) ;
483
484
await next ( ) ;
484
485
} ) ;
485
486
486
- app . use ( async ( _params , reqCtx , next ) => {
487
+ app . use ( async ( { reqCtx, next } ) => {
487
488
await next ( ) ;
488
489
reqCtx . res . headers . set ( 'x-test-header' , 'after-next' ) ;
489
490
} ) ;
@@ -531,7 +532,7 @@ describe('Class: Router - Middleware', () => {
531
532
const app = new Router ( ) ;
532
533
const executionOrder : string [ ] = [ ] ;
533
534
534
- app . use ( async ( _params , _reqCtx , next ) => {
535
+ app . use ( async ( { next } ) => {
535
536
executionOrder . push ( 'middleware-start' ) ;
536
537
await next ( ) ;
537
538
executionOrder . push ( 'middleware-end' ) ;
0 commit comments