Skip to content

Commit

Permalink
fix: single mode will call app.agent.close (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
atian25 authored Sep 30, 2019
1 parent e43a0dd commit bd305d2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const MOCK_APP_METHOD = [
'ready',
'closed',
'close',
'agent',
'_agent',
'_app',
'on',
Expand Down Expand Up @@ -81,6 +80,12 @@ class MockApplication extends EventEmitter {

const Application = bindMessenger(egg.Application, agent);
const app = this._app = new Application(Object.assign({}, this.options));

// https://github.com/eggjs/egg/blob/8bb7c7e7d59d6aeca4b2ed1eb580368dcb731a4d/lib/egg.js#L125
// egg single mode mount this at start(), so egg-mock should impel it.
app.agent = agent;
agent.app = app;

// egg-mock plugin need to override egg context
Object.assign(app.context, context);
mockCustomLoader(app);
Expand Down Expand Up @@ -162,11 +167,6 @@ class MockApplication extends EventEmitter {
if (os.platform() === 'win32') yield sleep(1000);
});
}

get agent() {
return this._agent;
}

}

module.exports = function(options) {
Expand Down
1 change: 1 addition & 0 deletions test/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ describe('test/app.test.js', () => {
});
yield app.ready();
assert(app.agent === app._agent);
assert(app.agent.app === app._app);
});

it('should not use cache when app is closed', function* () {
Expand Down
1 change: 0 additions & 1 deletion test/app_proxy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ describe('test/app_proxy.test.js', () => {
'ready',
'closed',
'close',
'agent',
'_agent',
'_app',
'on',
Expand Down

0 comments on commit bd305d2

Please sign in to comment.