Skip to content

Commit 04e42f3

Browse files
committed
test: use clientBuilder test
1 parent 78af03e commit 04e42f3

File tree

5 files changed

+52
-40
lines changed

5 files changed

+52
-40
lines changed

.eslintrc

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
2,
1515
{ "SwitchCase": 1 }
1616
],
17+
"require-jsdoc": "off",
1718
"no-loop-func": "off",
1819
"no-underscore-dangle": "off",
1920
"consistent-return": "off",

lib/base.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,11 @@ class WebpackBaseBuilder extends Config {
103103
sourcePlugins[plugin.name.name] = plugin;
104104
}
105105
} else if (this.isWebpackApplyPlugin(plugin)) { // only apply method plugin
106-
const label = this.utils.getPluginLabel(plugin);
107-
sourcePlugins[label] = { name: plugin };
106+
const md5Label = this.utils.getPluginLabel(plugin);
107+
sourcePlugins[md5Label] = { name: plugin };
108108
} else if (Object.keys(plugin).length === 1) {
109-
const label = Object.keys(plugin)[0];
110-
sourcePlugins[label] = plugin[label];
109+
const keyLabel = Object.keys(plugin)[0];
110+
sourcePlugins[keyLabel] = plugin[keyLabel];
111111
}
112112
}
113113
});
@@ -144,7 +144,6 @@ class WebpackBaseBuilder extends Config {
144144
target[name] = configPlugin;
145145
}
146146
});
147-
148147
return target;
149148
}
150149

@@ -418,7 +417,7 @@ class WebpackBaseBuilder extends Config {
418417
} else if (this.utils.isObject(configInfo.name)) { // plugin object
419418
plugin = configInfo.name;
420419
pluginName = plugin.constructor && plugin.constructor.name || label;
421-
} else if (this.utils.isObject(configInfo) && this.utils.isFunction(configInfo.apply)) {
420+
} else if (this.isWebpackApplyPlugin(configInfo)) {
422421
plugin = configInfo;
423422
pluginName = label;
424423
} else if (this.utils.isString(configInfo.name) || this.utils.isFunction(configInfo.name)) {

test/client.test.js

+29-16
Original file line numberDiff line numberDiff line change
@@ -580,30 +580,30 @@ describe('client.test.js', () => {
580580
devtool: 'source-map',
581581
loaders: {
582582
css: {
583-
options:{
584-
sourceMap: false,
583+
options: {
584+
sourceMap: false
585585
}
586586
},
587-
scss: {
588-
options:{
589-
sourceMap: false,
587+
scss: {
588+
options: {
589+
sourceMap: false
590590
}
591591
},
592-
sass: {
593-
options:{
594-
sourceMap: false,
592+
sass: {
593+
options: {
594+
sourceMap: false
595595
}
596596
},
597-
less: {
598-
options:{
599-
sourceMap: false,
597+
less: {
598+
options: {
599+
sourceMap: false
600600
}
601601
},
602-
stylus: {
603-
options:{
604-
sourceMap: false,
602+
stylus: {
603+
options: {
604+
sourceMap: false
605605
}
606-
},
606+
}
607607
}
608608
});
609609
const webpackConfig = builder.create();
@@ -615,7 +615,7 @@ describe('client.test.js', () => {
615615
expect(cssLoader.use[1].options.sourceMap).to.be.false;
616616
expect(sassLoader.use[1].options.sourceMap).to.be.false;
617617
expect(sassLoader.use[3].options.sourceMap).to.be.false;
618-
618+
619619
expect(scssLoader.use[1].options.sourceMap).to.be.false;
620620
expect(scssLoader.use[3].options.sourceMap).to.be.false;
621621

@@ -625,5 +625,18 @@ describe('client.test.js', () => {
625625
expect(stylusLoader.use[1].options.sourceMap).to.be.false;
626626
expect(stylusLoader.use[3].options.sourceMap).to.be.false;
627627
});
628+
629+
it('should merge plugin array params test', () => {
630+
const builder = createBuilder({
631+
plugins: {
632+
copy: [{ from: 'asset', to: 'public' }]
633+
}
634+
});
635+
const webpackConfig = builder.create();
636+
const plugins = webpackConfig.plugins;
637+
const copy = getPluginByLabel('copy', plugins);
638+
expect(!!copy).to.be.true;
639+
});
640+
628641
});
629642
});

test/plugin.test.js

+17-17
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const path = require('path').posix;
88
const utils = require('../utils/utils');
99

1010
// http://chaijs.com/api/bdd/
11-
function createBuilder(config) {
11+
const createBuilder = config => {
1212
const builder = new WebpackBaseBuilder(config);
1313
if (config && config.type) {
1414
builder.type = config.type;
@@ -19,13 +19,13 @@ function createBuilder(config) {
1919
include: path.join(__dirname, '../test')
2020
});
2121
return builder;
22-
}
22+
};
2323

24-
function getPluginByLabel(label, plugins) {
24+
const getPluginByLabel = (label, plugins) => {
2525
return plugins.find(plugin => {
2626
return plugin.__lable__ === label || plugin.__plugin__ === label;
2727
});
28-
}
28+
};
2929

3030
describe('plugin.test.js', () => {
3131
before(() => {});
@@ -186,19 +186,19 @@ describe('plugin.test.js', () => {
186186
expect(!!copy).to.be.true;
187187
});
188188

189-
// it('should merge array plugin test', () => {
190-
// const plugin = new CopyWebpackPlugin([{ from: 'asset', to: 'public' }]);
191-
// const builder = createBuilder({
192-
// plugins: [
193-
// plugin
194-
// ]
195-
// });
196-
// const webpackConfig = builder.create();
197-
// const plugins = webpackConfig.plugins;
198-
// const lable = utils.getPluginLabel(plugin);
199-
// const copy = getPluginByLabel(lable, plugins);
200-
// expect(!!copy).to.be.true;
201-
// });
189+
it('should merge array plugin test', () => {
190+
const plugin = new CopyWebpackPlugin([{ from: 'asset', to: 'public' }]);
191+
const builder = createBuilder({
192+
plugins: [
193+
plugin
194+
]
195+
});
196+
const webpackConfig = builder.create();
197+
const plugins = webpackConfig.plugins;
198+
const lable = utils.getPluginLabel(plugin);
199+
const copy = getPluginByLabel(lable, plugins);
200+
expect(!!copy).to.be.true;
201+
});
202202

203203
it('should add webpack plugin test', () => {
204204
const builder = createBuilder({});

utils/utils.js

-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ utils.getCustomEntry = (config, type) => {
113113
}
114114
} else if (entry instanceof RegExp) {
115115
const dirEntry = utils.walkFile(entry, configEntry.exclude, extMatch, config.baseDir);
116-
console.log('...entry', dirEntry);
117116
Object.assign(entries, utils.createEntry(config, entryLoader, dirEntry, false));
118117
} else if (utils.isObject(entry)) {
119118
Object.assign(entries, utils.createEntry(config, entryLoader, entry, true));

0 commit comments

Comments
 (0)