diff --git a/lib/app_handler.js b/lib/app_handler.js index 96cb09b..7a7218f 100644 --- a/lib/app_handler.js +++ b/lib/app_handler.js @@ -1,4 +1,4 @@ -const debug = require('util').debuglog('egg-mock:bootstrap'); +const debug = require('util').debuglog('egg-mock:bootstrap:app_handler'); const mockParallelApp = require('./parallel/app'); const { setupAgent } = require('./agent_handler'); const mock = require('../index').default; @@ -8,10 +8,10 @@ let app; exports.setupApp = () => { if (app) { + debug('return exists app'); return app; } - const options = getEggOptions(); debug('env.ENABLE_MOCHA_PARALLEL: %s, process.env.AUTO_AGENT: %s', process.env.ENABLE_MOCHA_PARALLEL, process.env.AUTO_AGENT); @@ -47,6 +47,9 @@ exports.getApp = async suite => { if (getAppCallback) { return getAppCallback(suite); } + if (app) { + await app.ready(); + } return app; }; diff --git a/lib/inject_context.js b/lib/inject_context.js index 45e8686..2972bb5 100644 --- a/lib/inject_context.js +++ b/lib/inject_context.js @@ -18,8 +18,9 @@ function injectContext(mocha) { // Inject ctx for before/after. Runner.prototype.runSuite = async function(suite, fn) { - debug('run suite: %s %b', suite.title, !!(suite.ctx && suite[EGG_CONTEXT])); + debug('run suite: %j %s', suite.title, !!(suite.ctx && suite[EGG_CONTEXT])); const app = await appHandler.getApp(suite); + debug('get app: %s', !!app); const self = this; if (!app) { return runSuite.call(self, suite, fn); @@ -47,6 +48,7 @@ function injectContext(mocha) { // Inject ctx for beforeEach/it/afterEach. // And ctx with before/after is not same as beforeEach/it/afterEach. Runner.prototype.runTests = async function(suite, fn) { + debug('run tests: %j %s', suite.title); const app = await appHandler.getApp(suite); const self = this; if (!app) { diff --git a/lib/parallel/agent.js b/lib/parallel/agent.js index 8c2eafb..4b9a069 100644 --- a/lib/parallel/agent.js +++ b/lib/parallel/agent.js @@ -58,7 +58,6 @@ class MockAgent extends Base { this[APP_INIT] = true; debug('this[APP_INIT] = true'); this[BIND_EVENT](); - debug('http server instantiate'); await agent.ready(); const msg = {