@@ -3,6 +3,7 @@ const expect = require('chai').expect;
33const WebpackTool = require ( 'webpack-tool' ) ;
44const webpack = WebpackTool . webpack ;
55const merge = WebpackTool . merge ;
6+ const utils = require ( '../utils/utils' ) ;
67const WebpackBaseBuilder = require ( '../lib/base' ) ;
78const WebpackClientBuilder = require ( '../lib/client' ) ;
89const path = require ( 'path' ) . posix ;
@@ -35,7 +36,14 @@ function getLoaderByName(name, rules) {
3536 } ) ;
3637 } ) ;
3738}
38-
39+ function getLoadersByName ( name , rules ) {
40+ const loaderName = `${ name } -loader` ;
41+ return rules . filter ( rule => {
42+ return rule . use . some ( loader => {
43+ return loaderName === loader || ( typeof loader === 'object' && loader . loader === loaderName ) ;
44+ } ) ;
45+ } ) ;
46+ }
3947function getLoaderByTest ( test , rules ) {
4048 return rules . find ( rule => {
4149 return rule . test . toString ( ) === test . toString ( ) ;
@@ -81,6 +89,7 @@ describe('loader.test.js', () => {
8189
8290 it ( 'should loader merge options test' , ( ) => {
8391 const config = {
92+ cache : false ,
8493 loaders : {
8594 eslint : {
8695 options : {
@@ -262,6 +271,7 @@ describe('loader.test.js', () => {
262271 expect ( vuehtml . use [ 0 ] . loader ) . to . equal ( 'vue-html-loader' ) ;
263272 expect ( vuehtml . use [ 0 ] . options . test ) . to . true ;
264273 } ) ;
274+
265275
266276 describe ( '#webpack feature loader test' , ( ) => {
267277 it ( 'should postcss-loader default config' , ( ) => {
@@ -305,4 +315,61 @@ describe('loader.test.js', () => {
305315 expect ( postcssLoader . options . sourceMap ) . to . be . false ;
306316 } ) ;
307317 } ) ;
318+
319+ describe ( '#webpack feature url loader test' , ( ) => {
320+ it ( 'should url-loader default config' , ( ) => {
321+ const builder = createBuilder ( ) ;
322+ const webpackConfig = builder . create ( ) ;
323+ const urlLoaders = getLoadersByName ( 'url' , webpackConfig . module . rules ) ;
324+ expect ( urlLoaders . length ) . to . equal ( 3 ) ;
325+ } ) ;
326+ it ( 'should url-loader default config' , ( ) => {
327+ const builder = createBuilder ( {
328+ loaders :{
329+ urlmedia :false ,
330+ urlfont : false ,
331+ urlimage : {
332+ options :{
333+ limit : 10000
334+ }
335+ }
336+ }
337+ } ) ;
338+ const webpackConfig = builder . create ( ) ;
339+ const urlLoader = getLoaderByName ( 'url' , webpackConfig . module . rules ) ;
340+ expect ( urlLoader . use [ 0 ] . options . limit ) . to . equal ( 10000 ) ;
341+ } ) ;
342+ } ) ;
343+ describe ( '#webpack babel loader test' , ( ) => {
344+ it ( 'should babel-loader default config' , ( ) => {
345+ const cacheDirectory = utils . getCacheLoaderInfoPath ( 'babel-loader' , 'dev' ) ;
346+ const builder = createBuilder ( ) ;
347+ const webpackConfig = builder . create ( ) ;
348+ const babelLoader = getLoaderByName ( 'babel' , webpackConfig . module . rules ) ;
349+ expect ( babelLoader . use . length ) . to . equal ( 1 ) ;
350+ expect ( babelLoader . use [ 0 ] . options . cacheDirectory ) . to . equal ( cacheDirectory ) ;
351+ } ) ;
352+ } ) ;
353+ describe ( '#webpack config cache test' , ( ) => {
354+ it ( 'should config cache false config' , ( ) => {
355+ const cacheDirectory = utils . getCacheLoaderInfoPath ( 'babel-loader' , 'dev' ) ;
356+ const builder = createBuilder ( {
357+ cache : false
358+ } ) ;
359+ const webpackConfig = builder . create ( ) ;
360+ const babelLoader = getLoaderByName ( 'babel' , webpackConfig . module . rules ) ;
361+ expect ( babelLoader . use . length ) . to . equal ( 1 ) ;
362+ expect ( babelLoader . use [ 0 ] . options . cacheDirectory ) . to . be . undefined
363+ } ) ;
364+ it ( 'should config cache undefined config' , ( ) => {
365+ const cacheDirectory = utils . getCacheLoaderInfoPath ( 'babel-loader' , 'dev' ) ;
366+ const builder = createBuilder ( {
367+ cache : undefined
368+ } ) ;
369+ const webpackConfig = builder . create ( ) ;
370+ const babelLoader = getLoaderByName ( 'babel' , webpackConfig . module . rules ) ;
371+ expect ( babelLoader . use . length ) . to . equal ( 1 ) ;
372+ expect ( babelLoader . use [ 0 ] . options . cacheDirectory ) . to . equal ( cacheDirectory ) ;
373+ } ) ;
374+ } ) ;
308375} ) ;
0 commit comments