Comparing version 2.4.0 to 3.0.0
3.0.0 / 2017-02-13 | ||
================== | ||
* deps: upgrade egg (#29) | ||
* fix: bind messenger with app and agent (#28) | ||
* feat: [BREAKING_CHANGE] can get error from .ready() (#27) | ||
* test: remove unuse codes (#26) | ||
2.4.0 / 2017-02-08 | ||
@@ -3,0 +11,0 @@ ================== |
@@ -21,6 +21,5 @@ 'use strict'; | ||
const INIT_ONCE_LISTENER = Symbol('initOnceListener'); | ||
const MESSENGER = Symbol('messenger'); | ||
const MOCK_APP_METHOD = [ | ||
'ready', | ||
'_ready', | ||
'_readyCallbacks', | ||
'closed', | ||
@@ -44,15 +43,12 @@ 'close', | ||
ready.mixin(this); | ||
// listen once, otherwise will throw exception when emit error without listenr | ||
this.once('error', () => {}); | ||
co(this[INIT].bind(this)) | ||
.then(() => this.ready(true)) | ||
// TODO: implement ready(err) | ||
// condition for error event | ||
.catch(err => { | ||
if (!this[APP_INIT]) { | ||
this.emit('error', err); | ||
} else { | ||
// never run this line | ||
/* istanbul ignore next */ | ||
console.error(err.stack); | ||
} | ||
this.ready(err); | ||
}); | ||
@@ -72,3 +68,3 @@ } | ||
const Application = egg.Application; | ||
const Application = bindMessenger(egg.Application, agent); | ||
const app = this._app = new Application(this.options); | ||
@@ -80,2 +76,8 @@ debug('app instantiate'); | ||
yield app.ready(); | ||
const msg = { | ||
action: 'egg-ready', | ||
}; | ||
app.messenger._onMessage(msg); | ||
agent.messenger._onMessage(msg); | ||
debug('app ready'); | ||
@@ -212,1 +214,31 @@ } | ||
} | ||
function bindMessenger(Application, agent) { | ||
const agentMessenger = agent.messenger; | ||
return class MeesengerApplication extends Application { | ||
constructor(options) { | ||
super(options); | ||
const appMessenger = this.messenger; | ||
agentMessenger.send = new Proxy(agentMessenger.send, { | ||
apply(target, thisArg, [ action, data ]) { | ||
setImmediate(() => appMessenger._onMessage({ action, data })); | ||
}, | ||
}); | ||
} | ||
get messenger() { | ||
return this[MESSENGER]; | ||
} | ||
set messenger(m) { | ||
m.send = new Proxy(m.send, { | ||
apply(target, thisArg, [ action, data ]) { | ||
setImmediate(() => agentMessenger._onMessage({ action, data })); | ||
}, | ||
}); | ||
this[MESSENGER] = m; | ||
} | ||
get [Symbol.for('egg#eggPath')]() { return path.dirname(__dirname); } | ||
}; | ||
} |
@@ -19,2 +19,3 @@ 'use strict'; | ||
coverage: true, | ||
clean: true, | ||
}; | ||
@@ -21,0 +22,0 @@ options = Object.assign({}, defaults, options); |
{ | ||
"name": "egg-mock", | ||
"version": "2.4.0", | ||
"version": "3.0.0", | ||
"eggPlugin": { | ||
@@ -27,10 +27,10 @@ "name": "egg-mock" | ||
"coffee": "^3.3.0", | ||
"debug": "^2.6.0", | ||
"debug": "^2.6.1", | ||
"detect-port": "^1.1.0", | ||
"egg-utils": "^1.1.0", | ||
"get-ready": "^1.0.0", | ||
"get-ready": "^2.0.1", | ||
"is-type-of": "^1.0.0", | ||
"ko-sleep": "^1.0.2", | ||
"merge-descriptors": "^1.0.1", | ||
"mm": "^2.0.1", | ||
"mm": "^2.1.0", | ||
"rimraf": "^2.5.4" | ||
@@ -40,11 +40,10 @@ }, | ||
"autod": "^2.7.1", | ||
"egg": "^0.9.0", | ||
"egg": "^0.12.0", | ||
"egg-bin": "^2.0.2", | ||
"egg-ci": "^1.1.0", | ||
"eslint": "^3.14.0", | ||
"eslint": "^3.15.0", | ||
"eslint-config-egg": "^3.2.0", | ||
"ko-sleep": "^1.0.2", | ||
"pedding": "^1.1.0", | ||
"sdk-base": "^3.0.1", | ||
"supertest": "^2.0.1" | ||
"supertest": "^3.0.0" | ||
}, | ||
@@ -51,0 +50,0 @@ "ci": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
36158
9
891
+ Addedget-ready@2.0.1(transitive)
- Removedget-ready@1.0.0(transitive)
Updateddebug@^2.6.1
Updatedget-ready@^2.0.1
Updatedmm@^2.1.0