Skip to content

Commit

Permalink
fix(loader): loadPlugin can be extended
Browse files Browse the repository at this point in the history
  • Loading branch information
popomore committed May 3, 2017
1 parent 89b4df9 commit 5aa9bee
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 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
33 changes: 33 additions & 0 deletions test/lib/core/loader/load_plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ const should = require('should');
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 @@ -297,4 +299,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);
});
});

0 comments on commit 5aa9bee

Please sign in to comment.