File tree 3 files changed +8
-6
lines changed
3 files changed +8
-6
lines changed Original file line number Diff line number Diff line change @@ -729,8 +729,9 @@ declare module 'egg' {
729
729
* Run async function in the anonymous context scope
730
730
* @see Context#runInAnonymousContextScope
731
731
* @param {Function } scope - the first args is an anonymous ctx, scope should be async function
732
+ * @param {Request } req - if you want to mock request like querystring, you can pass an object to this function.
732
733
*/
733
- runInAnonymousContextScope ( scope : ( ctx : Context ) => Promise < void > ) : Promise < void > ;
734
+ runInAnonymousContextScope < R > ( scope : ( ctx : Context ) => Promise < R > , req ?: Request ) : Promise < R > ;
734
735
735
736
/**
736
737
* Get current execute ctx async local storage
Original file line number Diff line number Diff line change @@ -260,12 +260,13 @@ class Application extends EggApplication {
260
260
* Run async function in the anonymous context scope
261
261
* @see Context#runInAnonymousContextScope
262
262
* @param {Function } scope - the first args is an anonymous ctx, scope should be async function
263
+ * @param {Request } [req] - if you want to mock request like querystring, you can pass an object to this function.
263
264
*/
264
- async runInAnonymousContextScope ( scope ) {
265
- const ctx = this . createAnonymousContext ( ) ;
265
+ async runInAnonymousContextScope ( scope , req ) {
266
+ const ctx = this . createAnonymousContext ( req ) ;
266
267
if ( ! scope . name ) scope . _name = eggUtils . getCalleeFromStack ( true ) ;
267
- await this . ctxStorage . run ( ctx , async ( ) => {
268
- await scope ( ctx ) ;
268
+ return await this . ctxStorage . run ( ctx , async ( ) => {
269
+ return await scope ( ctx ) ;
269
270
} ) ;
270
271
}
271
272
Original file line number Diff line number Diff line change @@ -510,7 +510,7 @@ class EggApplication extends EggCore {
510
510
* Create an anonymous context, the context isn't request level, so the request is mocked.
511
511
* then you can use context level API like `ctx.service`
512
512
* @member {String} EggApplication#createAnonymousContext
513
- * @param {Request } req - if you want to mock request like querystring, you can pass an object to this function.
513
+ * @param {Request } [ req] - if you want to mock request like querystring, you can pass an object to this function.
514
514
* @return {Context } context
515
515
*/
516
516
createAnonymousContext ( req ) {
You can’t perform that action at this time.
0 commit comments