Skip to content

Commit

Permalink
fix(loader): loadPlugin can be extended (#836)
Browse files Browse the repository at this point in the history
  • Loading branch information
popomore authored May 4, 2017
1 parent 1a027ad commit 1358766
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/loader/agent_worker_loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class AgentWorkerLoader extends EggLoader {
* loadPlugin first, then loadConfig
*/
loadConfig() {
super.loadPlugin();
this.loadPlugin();
super.loadConfig();
}

Expand Down
2 changes: 1 addition & 1 deletion lib/loader/app_worker_loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class AppWorkerLoader extends EggLoader {
* @since 1.0.0
*/
loadConfig() {
super.loadPlugin();
this.loadPlugin();
super.loadConfig();
}

Expand Down
34 changes: 33 additions & 1 deletion test/lib/core/loader/load_plugin.test.js
Original file line number Diff line number Diff line change
@@ -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, '../../../../');
Expand Down Expand Up @@ -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);
});
});
2 changes: 1 addition & 1 deletion test/lib/core/logger.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down

0 comments on commit 1358766

Please sign in to comment.