11import path from 'path' ;
2- import { utimes , copy , readFile , outputFile } from 'fs-extra' ;
2+ import { copy } from 'fs-extra' ;
33import test from 'ava' ;
4- import pTimeout from 'p-timeout' ;
54import cssnano from 'cssnano' ;
65import mixins from 'postcss-mixins' ;
76import simpleVars from 'postcss-simple-vars' ;
@@ -21,21 +20,27 @@ test.after(() => {
2120} ) ;
2221
2322test ( 'Compile css file' , async t => {
24- const { success, error, disconnected} = await run ( [ 'test/fixtures/basic.css' , 'test/fixtures/styles.test.js' ] , {
25- options : { plugins : [ atImport , mixins , simpleVars , cssnano ] } ,
26- } ) ;
23+ const { success, error, disconnected, errMsg} = await run (
24+ [ 'test/fixtures/basic.css' , 'test/fixtures/styles.test.js' ] ,
25+ {
26+ options : { plugins : [ atImport , mixins , simpleVars , cssnano ] } ,
27+ }
28+ ) ;
2729
28- t . ifError ( error , ' Karma returned an error' ) ;
30+ t . ifError ( error , ` Karma returned the error: ${ errMsg } ` ) ;
2931 t . ifError ( disconnected , 'Karma disconnected' ) ;
3032 t . is ( success , 1 , 'Expected 1 test successful' ) ;
3133} ) ;
3234
3335test ( 'Compile css file with custom preprocessor' , async t => {
34- const { success, error, disconnected} = await run ( [ 'test/fixtures/basic.custom.css' , 'test/fixtures/styles.test.js' ] , {
35- options : { plugins : [ atImport , mixins , simpleVars , cssnano ] } ,
36- } ) ;
36+ const { success, error, disconnected, errMsg} = await run (
37+ [ 'test/fixtures/basic.custom.css' , 'test/fixtures/styles.test.js' ] ,
38+ {
39+ options : { plugins : [ atImport , mixins , simpleVars , cssnano ] } ,
40+ }
41+ ) ;
3742
38- t . ifError ( error , ' Karma returned an error' ) ;
43+ t . ifError ( error , ` Karma returned the error: ${ errMsg } ` ) ;
3944 t . ifError ( disconnected , 'Karma disconnected' ) ;
4045 t . is ( success , 1 , 'Expected 1 test successful' ) ;
4146} ) ;
@@ -63,67 +68,25 @@ test('Re-compile css file when dependency is modified', async t => {
6368 copy ( 'test/fixtures/with-partial.css' , fixture ) ,
6469 ] ) ;
6570
66- const server = await watch (
71+ const { server, watcher } = await watch (
6772 [ fixture . replace ( 'fixtures' , '*' ) . replace ( 'with' , '+(with|nomatch)' ) , 'test/fixtures/styles.test.js' ] ,
6873 { options : { plugins : [ atImport ( { path : [ includePath ] } ) , mixins , simpleVars , cssnano ] } }
6974 ) ;
7075
7176 try {
72- let { success, error, disconnected} = await waitForRunComplete ( server ) ;
77+ let { success, error, disconnected, errMsg } = await waitForRunComplete ( server ) ;
7378
74- t . ifError ( error , ' Karma returned an error' ) ;
79+ t . ifError ( error , ` Karma returned the error: ${ errMsg } ` ) ;
7580 t . ifError ( disconnected , 'Karma disconnected' ) ;
7681 t . is ( success , 1 , 'Expected 1 test successful' ) ;
7782
78- utimes ( partial , Date . now ( ) / 1000 , Date . now ( ) / 1000 ) ;
79- ( { success, error, disconnected} = await waitForRunComplete ( server ) ) ;
83+ watcher . emit ( 'change' , partial ) ;
84+ ( { success, error, disconnected, errMsg } = await waitForRunComplete ( server ) ) ;
8085
81- t . ifError ( error , ' Karma returned an error' ) ;
86+ t . ifError ( error , ` Karma returned the error: ${ errMsg } ` ) ;
8287 t . ifError ( disconnected , 'Karma disconnected' ) ;
8388 t . is ( success , 1 , 'Expected 1 test successful' ) ;
8489 } finally {
8590 await server . emitAsync ( 'exit' ) ;
8691 }
8792} ) ;
88-
89- test ( 'Do not recompile css file when dependency is not imported anymore' , async t => {
90- const dir = path . resolve ( tmp ( ) ) ;
91- const fixture = path . join ( dir , 'with-partial.css' ) ;
92- const includePath = path . join ( dir , 'partials' ) ;
93- const partial = path . join ( includePath , 'partial.css' ) ;
94- const partialAlt = path . join ( includePath , 'partial-alt.css' ) ;
95- const subPartial = path . join ( includePath , 'sub-partial.css' ) ;
96-
97- await Promise . all ( [
98- copy ( 'test/fixtures/partials/partial.css' , partial ) ,
99- copy ( 'test/fixtures/partials/partial.css' , partialAlt ) ,
100- copy ( 'test/fixtures/partials/sub-partial.css' , subPartial ) ,
101- copy ( 'test/fixtures/with-partial.css' , fixture ) ,
102- ] ) ;
103-
104- const server = await watch ( [ fixture , 'test/fixtures/styles.test.js' ] , {
105- options : { plugins : [ atImport ( { path : [ includePath ] } ) , mixins , simpleVars , cssnano ] } ,
106- } ) ;
107-
108- try {
109- let { success, error, disconnected} = await waitForRunComplete ( server ) ;
110-
111- t . ifError ( error , 'Karma returned an error' ) ;
112- t . ifError ( disconnected , 'Karma disconnected' ) ;
113- t . is ( success , 1 , 'Expected 1 test successful' ) ;
114-
115- await outputFile (
116- fixture ,
117- ( await readFile ( fixture ) ) . toString ( ) . replace ( `@import 'partial';` , `@import 'partial-alt';` )
118- ) ;
119- ( { success, error, disconnected} = await waitForRunComplete ( server ) ) ;
120- t . ifError ( error , 'Karma returned an error' ) ;
121- t . ifError ( disconnected , 'Karma disconnected' ) ;
122- t . is ( success , 1 , 'Expected 1 test successful' ) ;
123-
124- utimes ( partial , Date . now ( ) / 1000 , Date . now ( ) / 1000 ) ;
125- await t . throws ( waitForRunComplete ( server ) , pTimeout . TimeoutError ) ;
126- } finally {
127- await server . emitAsync ( 'exit' ) ;
128- }
129- } ) ;
0 commit comments