Skip to content

Commit

Permalink
fix: make sure app ready on parallel mode (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed Jan 30, 2023
1 parent 373a057 commit 83c600e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
7 changes: 5 additions & 2 deletions 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;
Expand All @@ -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);
Expand Down Expand Up @@ -47,6 +47,9 @@ exports.getApp = async suite => {
if (getAppCallback) {
return getAppCallback(suite);
}
if (app) {
await app.ready();
}
return app;
};

Expand Down
4 changes: 3 additions & 1 deletion lib/inject_context.js
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion lib/parallel/agent.js
Expand Up @@ -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 = {
Expand Down

0 comments on commit 83c600e

Please sign in to comment.