@@ -39,7 +39,7 @@ function genId (file) {
3939 return hash ( path . join ( 'test' , 'fixtures' , file ) )
4040}
4141
42- function bundle ( options , cb ) {
42+ function bundle ( options , cb , wontThrowError ) {
4343 const vueOptions = options . vue
4444 delete options . vue
4545 const config = Object . assign ( { } , globalConfig , options )
@@ -54,41 +54,41 @@ function bundle (options, cb) {
5454 const webpackCompiler = webpack ( config )
5555 webpackCompiler . outputFileSystem = mfs
5656 webpackCompiler . run ( ( err , stats ) => {
57- expect ( err ) . to . be . null
58- if ( stats . compilation . errors . length ) {
59- stats . compilation . errors . forEach ( ( err ) => {
60- console . error ( err . message )
61- } )
62- }
63- if ( stats . compilation . errors ) {
64- stats . compilation . errors . forEach ( err => {
65- console . error ( err . message )
66- } )
57+ const errors = stats . compilation . errors
58+ if ( ! wontThrowError ) {
59+ expect ( err ) . to . be . null
60+ if ( errors && errors . length ) {
61+ errors . forEach ( error => {
62+ console . error ( error . message )
63+ } )
64+ }
65+ expect ( errors ) . to . be . empty
6766 }
68- expect ( stats . compilation . errors ) . to . be . empty
69- cb ( mfs . readFileSync ( '/test.build.js' ) . toString ( ) , stats . compilation . warnings )
67+ cb ( mfs . readFileSync ( '/test.build.js' ) . toString ( ) , stats , err )
7068 } )
7169}
7270
73- function test ( options , assert ) {
74- bundle ( options , ( code , warnings ) => {
71+ function test ( options , assert , wontThrowError ) {
72+ bundle ( options , ( code , stats , err ) => {
7573 jsdom . env ( {
7674 html : '<!DOCTYPE html><html><head></head><body></body></html>' ,
7775 src : [ code ] ,
78- done : ( err , window ) => {
79- if ( err ) {
80- console . log ( err [ 0 ] . data . error . stack )
81- expect ( err ) . to . be . null
76+ done : ( errors , window ) => {
77+ if ( errors ) {
78+ console . log ( errors [ 0 ] . data . error . stack )
79+ if ( ! wontThrowError ) {
80+ expect ( errors ) . to . be . null
81+ }
8282 }
8383 const module = interopDefault ( window . vueModule )
8484 const instance = { }
8585 if ( module && module . beforeCreate ) {
8686 module . beforeCreate . forEach ( hook => hook . call ( instance ) )
8787 }
88- assert ( window , module , window . vueModule , instance )
88+ assert ( window , module , window . vueModule , instance , errors , { stats , err } )
8989 }
9090 } )
91- } )
91+ } , wontThrowError )
9292}
9393
9494function mockRender ( options , data = { } ) {
@@ -511,7 +511,23 @@ describe('vue-loader', () => {
511511 } )
512512 } )
513513
514- it ( 'postcss options' , done => {
514+ it ( 'load postcss config file with js syntax error' , done => {
515+ fs . writeFileSync ( '.postcssrc.js' , 'module.exports = { hello }' )
516+ test ( {
517+ entry : './test/fixtures/basic.vue'
518+ } , ( window , module , vueModule , instance , jsdomErr , webpackInfo ) => {
519+ const { stats : { compilation : { warnings, errors } } , err } = webpackInfo
520+ expect ( jsdomErr ) . to . be . null
521+ expect ( err ) . to . be . null
522+ expect ( warnings ) . to . be . empty
523+ expect ( errors . length ) . to . equal ( 1 )
524+ expect ( errors [ 0 ] . message ) . match ( / ^ E r r o r o n L o a d i n g P o s t C S S C o n f i g \: / )
525+ fs . unlinkSync ( '.postcssrc.js' )
526+ done ( )
527+ } , true )
528+ } )
529+
530+ it ( 'postcss lang' , done => {
515531 test ( {
516532 entry : './test/fixtures/postcss-lang.vue'
517533 } , ( window ) => {
0 commit comments