@@ -14,7 +14,7 @@ test('css-extract', function (t) {
1414 t . throws ( cssExtract . bind ( null , { } ) , 123 , / o b j e c t / )
1515 } )
1616
17- t . test ( 'should extract css' , function ( t ) {
17+ t . test ( 'should extract sheetify css to given stream ' , function ( t ) {
1818 t . plan ( 2 )
1919 browserify ( path . join ( __dirname , 'source.js' ) )
2020 . transform ( 'sheetify/transform' )
@@ -31,7 +31,7 @@ test('css-extract', function (t) {
3131 }
3232 } )
3333
34- t . test ( 'should write file' , function ( t ) {
34+ t . test ( 'should extract sheetify css to file' , function ( t ) {
3535 t . plan ( 3 )
3636 tmpDir ( { unsafeCleanup : true } , onDir )
3737
@@ -54,4 +54,42 @@ test('css-extract', function (t) {
5454 } )
5555 }
5656 } )
57+
58+ t . test ( 'should extract static insert-css statements' , function ( t ) {
59+ t . plan ( 2 )
60+ browserify ( path . join ( __dirname , 'source-static.js' ) )
61+ . plugin ( cssExtract , { out : createWs } )
62+ . bundle ( )
63+
64+ function createWs ( ) {
65+ return bl ( function ( err , data ) {
66+ t . ifError ( err , 'no error' )
67+ const exPath = path . join ( __dirname , './expected-static.css' )
68+ const expected = fs . readFileSync ( exPath , 'utf8' ) . trim ( )
69+ t . equal ( String ( data ) , expected , 'extracted all the CSS' )
70+ } )
71+ }
72+ } )
73+
74+ t . test ( 'should not extract dynamic insert-css statements' , function ( t ) {
75+ t . plan ( 4 )
76+ const sourcePath = path . join ( __dirname , 'source-dynamic.js' )
77+
78+ browserify ( sourcePath )
79+ . plugin ( cssExtract , { out : readCss } )
80+ . bundle ( readJs )
81+
82+ function readCss ( ) {
83+ return bl ( function ( err , data ) {
84+ t . ifError ( err , 'no error' )
85+ t . equal ( String ( data ) , '' , 'no css extracted' )
86+ } )
87+ }
88+
89+ function readJs ( err , data ) {
90+ t . ifError ( err , 'no error' )
91+ const source = fs . readFileSync ( sourcePath , 'utf8' )
92+ t . ok ( String ( data ) . indexOf ( String ( source ) ) !== - 1 , 'source is still in built bundle' )
93+ }
94+ } )
5795} )
0 commit comments