@@ -39,7 +39,7 @@ function genId (file) {
39
39
return hash ( path . join ( 'test' , 'fixtures' , file ) )
40
40
}
41
41
42
- function bundle ( options , cb ) {
42
+ function bundle ( options , cb , wontThrowError ) {
43
43
const vueOptions = options . vue
44
44
delete options . vue
45
45
const config = Object . assign ( { } , globalConfig , options )
@@ -54,41 +54,41 @@ function bundle (options, cb) {
54
54
const webpackCompiler = webpack ( config )
55
55
webpackCompiler . outputFileSystem = mfs
56
56
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
67
66
}
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 )
70
68
} )
71
69
}
72
70
73
- function test ( options , assert ) {
74
- bundle ( options , ( code , warnings ) => {
71
+ function test ( options , assert , wontThrowError ) {
72
+ bundle ( options , ( code , stats , err ) => {
75
73
jsdom . env ( {
76
74
html : '<!DOCTYPE html><html><head></head><body></body></html>' ,
77
75
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
+ }
82
82
}
83
83
const module = interopDefault ( window . vueModule )
84
84
const instance = { }
85
85
if ( module && module . beforeCreate ) {
86
86
module . beforeCreate . forEach ( hook => hook . call ( instance ) )
87
87
}
88
- assert ( window , module , window . vueModule , instance )
88
+ assert ( window , module , window . vueModule , instance , errors , { stats , err } )
89
89
}
90
90
} )
91
- } )
91
+ } , wontThrowError )
92
92
}
93
93
94
94
function mockRender ( options , data = { } ) {
@@ -511,7 +511,23 @@ describe('vue-loader', () => {
511
511
} )
512
512
} )
513
513
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 => {
515
531
test ( {
516
532
entry : './test/fixtures/postcss-lang.vue'
517
533
} , ( window ) => {
0 commit comments