Skip to content

Commit

Permalink
fix: handleRequest method should return a promise (#3820)
Browse files Browse the repository at this point in the history
  • Loading branch information
browsnet authored and atian25 committed Jul 17, 2019
1 parent 29a2f2f commit 489f52b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ class Application extends EggApplication {

handleRequest(ctx, fnMiddleware) {
this.emit('request', ctx);
super.handleRequest(ctx, fnMiddleware);
onFinished(ctx.res, () => this.emit('response', ctx));
return super.handleRequest(ctx, fnMiddleware);
}

/**
Expand Down
18 changes: 18 additions & 0 deletions test/app/extend/application.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,22 @@ describe('test/app/extend/application.test.js', () => {
);
});
});

describe('app.handleRequest(ctx, fnMiddleware)', () => {
let app;
before(() => {
app = utils.app('apps/demo');
return app.ready();
});
after(() => app.close());

it('should wait for middleware resolution', async () => {
const ctx = app.createAnonymousContext();
await app.handleRequest(ctx, async ctx => {
await sleep(100);
ctx.body = 'middleware resolution';
});
assert(ctx.body === 'middleware resolution');
});
});
});

0 comments on commit 489f52b

Please sign in to comment.