diff --git a/lib/loader/agent_worker_loader.js b/lib/loader/agent_worker_loader.js index 5340567d85..1789a38232 100644 --- a/lib/loader/agent_worker_loader.js +++ b/lib/loader/agent_worker_loader.js @@ -12,7 +12,7 @@ class AgentWorkerLoader extends EggLoader { * loadPlugin first, then loadConfig */ loadConfig() { - super.loadPlugin(); + this.loadPlugin(); super.loadConfig(); } diff --git a/lib/loader/app_worker_loader.js b/lib/loader/app_worker_loader.js index ef92b7f00a..caa64e3e4b 100644 --- a/lib/loader/app_worker_loader.js +++ b/lib/loader/app_worker_loader.js @@ -13,7 +13,7 @@ class AppWorkerLoader extends EggLoader { * @since 1.0.0 */ loadConfig() { - super.loadPlugin(); + this.loadPlugin(); super.loadConfig(); } diff --git a/test/lib/core/loader/load_plugin.test.js b/test/lib/core/loader/load_plugin.test.js index fd8187b398..42f33f70e4 100644 --- a/test/lib/core/loader/load_plugin.test.js +++ b/test/lib/core/loader/load_plugin.test.js @@ -1,10 +1,11 @@ 'use strict'; -const assert = require('assert'); const path = require('path'); const fs = require('fs'); const mm = require('egg-mock'); +const assert = require('assert'); const AppWorkerLoader = require('../../../../').AppWorkerLoader; +const AgentWorkerLoader = require('../../../../').AgentWorkerLoader; const utils = require('../../../utils'); const EGG_BASE = path.join(__dirname, '../../../../'); @@ -301,4 +302,35 @@ describe('test/lib/core/loader/load_plugin.test.js', () => { from: path.join(baseDir, 'config/plugin.js'), }); }); + + it('should customize loadPlugin', () => { + const baseDir = utils.getFilepath('apps/loader-plugin'); + class CustomAppLoader extends AppWorkerLoader { + loadPlugin() { + this.hasAppLoadPlugin = true; + super.loadPlugin(); + } + } + const appLoader = new CustomAppLoader({ + baseDir, + app, + logger, + }); + appLoader.loadConfig(); + assert(appLoader.hasAppLoadPlugin === true); + + class CustomAgentLoader extends AgentWorkerLoader { + loadPlugin() { + this.hasAgentLoadPlugin = true; + super.loadPlugin(); + } + } + const agentLoader = new CustomAgentLoader({ + baseDir, + app, + logger, + }); + agentLoader.loadConfig(); + assert(agentLoader.hasAgentLoadPlugin === true); + }); }); diff --git a/test/lib/core/logger.test.js b/test/lib/core/logger.test.js index 1cee08fd24..162240cc57 100644 --- a/test/lib/core/logger.test.js +++ b/test/lib/core/logger.test.js @@ -183,7 +183,7 @@ describe('test/lib/core/logger.test.js', () => { app.loggers.errorLogger.error(new Error('errorLogger error')); app.loggers.customLogger.error(new Error('customLogger error')); - yield sleep(10); + yield sleep(1000); const content = fs.readFileSync(path.join(app.baseDir, 'logs/logger/common-error.log'), 'utf8'); assert(content.includes('nodejs.Error: logger error'));