Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(loader): loadPlugin can be extended #836

Merged
merged 4 commits into from
May 4, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});
});