@@ -3,13 +3,68 @@ import test from 'ava'
33import tmp from './helpers/tmp.js'
44import cli from './helpers/cli.js'
55
6- test ( 'multiple input files && --output' , ( t ) => {
7- return cli ( [ 'test/fixtures/*.css' , '-o' , tmp ( ) ] ) . then ( ( { error, code } ) => {
6+ // ensure that configuration errors are thrown in watch mode as well as normal mode
7+ ; [ false , true ] . forEach ( ( watch ) => {
8+ const prefix = watch ? 'watch mode: ' : ''
9+ const additionalArgs = watch ? [ '--watch' ] : [ ]
10+
11+ test ( `${ prefix } multiple input files && --output` , ( t ) => {
12+ return cli ( [ 'test/fixtures/*.css' , '-o' , tmp ( ) , ...additionalArgs ] ) . then (
13+ ( { error, code } ) => {
14+ t . is ( code , 1 , 'expected non-zero error code' )
15+ t . regex ( error . toString ( ) , / I n p u t E r r o r : M u s t u s e - - d i r o r - - r e p l a c e / )
16+ } ,
17+ )
18+ } )
19+
20+ test ( `${ prefix } plugin not found` , ( t ) => {
21+ return cli ( [
22+ 'test/fixtures/a.css' ,
23+ '-u' ,
24+ 'postcss-plugin' ,
25+ '-o' ,
26+ tmp ( ) ,
27+ ...additionalArgs ,
28+ ] ) . then ( ( { error, code } ) => {
29+ t . is ( code , 1 , 'expected non-zero error code' )
30+ t . regex (
31+ error . toString ( ) ,
32+ / P l u g i n E r r o r : C a n n o t f i n d p a c k a g e ' p o s t c s s - p l u g i n ' / ,
33+ )
34+ } )
35+ } )
36+
37+ test ( `${ prefix } plugin throws on require` , ( t ) => {
38+ return cli ( [
39+ 'test/fixtures/a.css' ,
40+ '-u' ,
41+ './test/fixtures/_bad-plugin.js' ,
42+ '-o' ,
43+ tmp ( ) ,
44+ ...additionalArgs ,
45+ ] ) . then ( ( { error, code } ) => {
46+ t . is ( code , 1 , 'expected non-zero error code' )
47+ t . regex ( error . toString ( ) , / P l u g i n E r r o r \( .* b a d - p l u g i n .j s \) : T h i s f a i l s / )
48+ } )
49+ } )
50+
51+ test ( `${ prefix } fails on invalid explicit config` , async ( t ) => {
52+ const output = tmp ( 'output-ignore.css' )
53+
54+ const { stderr, code } = await cli ( [
55+ 'test/fixtures/a.css' ,
56+ '-o' ,
57+ output ,
58+ '--config' ,
59+ '/foo/bar' ,
60+ ...additionalArgs ,
61+ ] )
862 t . is ( code , 1 , 'expected non-zero error code' )
9- t . regex ( error . toString ( ) , / I n p u t E r r o r : M u s t u s e - - d i r o r - - r e p l a c e / )
63+ t . regex ( stderr , / N o P o s t C S S C o n f i g f o u n d / )
1064 } )
1165} )
1266
67+ // These errors cannot occur in watch mode; watch mode does not support stdout
1368test ( 'multiple input files && writing to stdout' , ( t ) => {
1469 return cli ( [ 'test/fixtures/*.css' ] ) . then ( ( { error, code } ) => {
1570 t . is ( code , 1 , 'expected non-zero error code' )
@@ -27,31 +82,7 @@ test('--map && writing to stdout', (t) => {
2782 } )
2883} )
2984
30- test ( 'plugin not found' , ( t ) => {
31- return cli ( [ 'test/fixtures/a.css' , '-u' , 'postcss-plugin' , '-o' , tmp ( ) ] ) . then (
32- ( { error, code } ) => {
33- t . is ( code , 1 , 'expected non-zero error code' )
34- t . regex (
35- error . toString ( ) ,
36- / P l u g i n E r r o r : C a n n o t f i n d p a c k a g e ' p o s t c s s - p l u g i n ' / ,
37- )
38- } ,
39- )
40- } )
41-
42- test ( 'plugin throws on require' , ( t ) => {
43- return cli ( [
44- 'test/fixtures/a.css' ,
45- '-u' ,
46- './test/fixtures/_bad-plugin.js' ,
47- '-o' ,
48- tmp ( ) ,
49- ] ) . then ( ( { error, code } ) => {
50- t . is ( code , 1 , 'expected non-zero error code' )
51- t . regex ( error . toString ( ) , / P l u g i n E r r o r \( .* b a d - p l u g i n .j s \) : T h i s f a i l s / )
52- } )
53- } )
54-
85+ // Watch mode does not exit on CssSyntaxError, this is tested in ./watch.js
5586test ( 'CssSyntaxError' , ( t ) => {
5687 return cli ( [ 'test/fixtures/a.css' , '--parser' , 'sugarss' , '-o' , tmp ( ) ] ) . then (
5788 ( { error, code } ) => {
@@ -63,17 +94,3 @@ test('CssSyntaxError', (t) => {
6394 } ,
6495 )
6596} )
66-
67- test ( 'fails on invalid explicit config' , async ( t ) => {
68- const output = tmp ( 'output-ignore.css' )
69-
70- const { stderr, code } = await cli ( [
71- 'test/fixtures/a.css' ,
72- '-o' ,
73- output ,
74- '--config' ,
75- '/foo/bar' ,
76- ] )
77- t . is ( code , 1 , 'expected non-zero error code' )
78- t . regex ( stderr , / N o P o s t C S S C o n f i g f o u n d / )
79- } )
0 commit comments