11var assert = require ( 'assert' ) ;
22var exec = require ( 'child_process' ) . exec ;
3+ var execSync = require ( 'child_process' ) . execSync ;
34var fs = require ( 'fs' ) ;
45var http = require ( 'http' ) ;
56var path = require ( 'path' ) ;
@@ -12,6 +13,8 @@ var vows = require('vows');
1213
1314function binaryContext ( options , context ) {
1415 context . topic = function ( ) {
16+ ( context . setup || Function . prototype ) ( ) ;
17+
1518 // We add __DIRECT__=1 to force binary into 'non-piped' mode
1619 exec ( '__DIRECT__=1 ./bin/cleancss ' + options , this . callback ) ;
1720 } ;
@@ -788,68 +791,72 @@ vows.describe('cleancss')
788791 assert . equal ( stdout , '.one{color:red}' ) ;
789792 }
790793 } ) ,
791- 'batch processing with explicitely given paths' : binaryContext ( '-b ./test/fixtures/partials/one.css ./test/fixtures/partials/five.css' , {
794+ 'batch processing with explicitely given paths' : binaryContext ( '-b ./test/fixtures-batch-1/partials/one.css ./test/fixtures-batch-1/partials/five.css' , {
795+ 'setup' : function ( ) {
796+ execSync ( 'cp -fr test/fixtures test/fixtures-batch-1' ) ;
797+ } ,
792798 'creates two separate minified files' : function ( ) {
793- assert . isTrue ( fs . existsSync ( 'test/fixtures/partials/one-min.css' ) ) ;
794- assert . isFalse ( fs . existsSync ( 'test/fixtures/partials/two-min.css' ) ) ;
795- assert . isTrue ( fs . existsSync ( 'test/fixtures/partials/five-min.css' ) ) ;
799+ assert . isTrue ( fs . existsSync ( 'test/fixtures-batch-1 /partials/one-min.css' ) ) ;
800+ assert . isFalse ( fs . existsSync ( 'test/fixtures-batch-1 /partials/two-min.css' ) ) ;
801+ assert . isTrue ( fs . existsSync ( 'test/fixtures-batch-1 /partials/five-min.css' ) ) ;
796802 } ,
797803 'teardown' : function ( ) {
798- deleteFile ( 'test/fixtures/partials/one-min.css' ) ;
799- deleteFile ( 'test/fixtures/partials/five-min.css' ) ;
804+ execSync ( 'rm -fr test/fixtures-batch-1' ) ;
800805 }
801806 } )
802807 } )
803808 . addBatch ( {
804- 'batch processing with wildard paths' : binaryContext ( '-b ./test/fixtures/partials/\\*\\*/*.css' , {
809+ 'batch processing with wildard paths' : binaryContext ( '-b ./test/fixtures-batch-2/partials/\\*\\*/*.css' , {
810+ 'setup' : function ( ) {
811+ execSync ( 'cp -fr test/fixtures test/fixtures-batch-2' ) ;
812+ } ,
805813 'creates two separate minified files' : function ( ) {
806- assert . isTrue ( fs . existsSync ( 'test/fixtures/partials/extra/four-min.css' ) ) ;
807- assert . isTrue ( fs . existsSync ( 'test/fixtures/partials/extra/three-min.css' ) ) ;
808- assert . isTrue ( fs . existsSync ( 'test/fixtures/partials/one-min.css' ) ) ;
809- assert . isTrue ( fs . existsSync ( 'test/fixtures/partials/two-min.css' ) ) ;
810- assert . isTrue ( fs . existsSync ( 'test/fixtures/partials/quoted-svg-min.css' ) ) ;
811- assert . isTrue ( fs . existsSync ( 'test/fixtures/partials/five-min.css' ) ) ;
814+ assert . isTrue ( fs . existsSync ( 'test/fixtures-batch-2 /partials/extra/four-min.css' ) ) ;
815+ assert . isTrue ( fs . existsSync ( 'test/fixtures-batch-2 /partials/extra/three-min.css' ) ) ;
816+ assert . isTrue ( fs . existsSync ( 'test/fixtures-batch-2 /partials/one-min.css' ) ) ;
817+ assert . isTrue ( fs . existsSync ( 'test/fixtures-batch-2 /partials/two-min.css' ) ) ;
818+ assert . isTrue ( fs . existsSync ( 'test/fixtures-batch-2 /partials/quoted-svg-min.css' ) ) ;
819+ assert . isTrue ( fs . existsSync ( 'test/fixtures-batch-2 /partials/five-min.css' ) ) ;
812820 } ,
813821 'teardown' : function ( ) {
814- deleteFile ( 'test/fixtures/partials/extra/four-min.css' ) ;
815- deleteFile ( 'test/fixtures/partials/extra/three-min.css' ) ;
816- deleteFile ( 'test/fixtures/partials/one-min.css' ) ;
817- deleteFile ( 'test/fixtures/partials/two-min.css' ) ;
818- deleteFile ( 'test/fixtures/partials/quoted-svg-min.css' ) ;
819- deleteFile ( 'test/fixtures/partials/five-min.css' ) ;
822+ execSync ( 'rm -fr test/fixtures-batch-2' ) ;
820823 }
821824 } )
822825 } )
823826 . addBatch ( {
824- 'batch processing with custom suffix' : binaryContext ( '--batch --batch-suffix \'.min\' ./test/fixtures/partials/one.css ./test/fixtures/partials/five.css' , {
827+ 'batch processing with custom suffix' : binaryContext ( '--batch --batch-suffix \'.min\' ./test/fixtures-batch-3/partials/one.css ./test/fixtures-batch-3/partials/five.css' , {
828+ 'setup' : function ( ) {
829+ execSync ( 'cp -fr test/fixtures test/fixtures-batch-3' ) ;
830+ } ,
825831 'creates two separate minified files' : function ( ) {
826- assert . isFalse ( fs . existsSync ( 'test/fixtures/partials/one-min.css' ) ) ;
827- assert . isFalse ( fs . existsSync ( 'test/fixtures/partials/two-min.css' ) ) ;
828- assert . isFalse ( fs . existsSync ( 'test/fixtures/partials/five-min.css' ) ) ;
832+ assert . isFalse ( fs . existsSync ( 'test/fixtures-batch-3 /partials/one-min.css' ) ) ;
833+ assert . isFalse ( fs . existsSync ( 'test/fixtures-batch-3 /partials/two-min.css' ) ) ;
834+ assert . isFalse ( fs . existsSync ( 'test/fixtures-batch-3 /partials/five-min.css' ) ) ;
829835
830- assert . isTrue ( fs . existsSync ( 'test/fixtures/partials/one.min.css' ) ) ;
831- assert . isFalse ( fs . existsSync ( 'test/fixtures/partials/two.min.css' ) ) ;
832- assert . isTrue ( fs . existsSync ( 'test/fixtures/partials/five.min.css' ) ) ;
836+ assert . isTrue ( fs . existsSync ( 'test/fixtures-batch-3 /partials/one.min.css' ) ) ;
837+ assert . isFalse ( fs . existsSync ( 'test/fixtures-batch-3 /partials/two.min.css' ) ) ;
838+ assert . isTrue ( fs . existsSync ( 'test/fixtures-batch-3 /partials/five.min.css' ) ) ;
833839 } ,
834840 'teardown' : function ( ) {
835- deleteFile ( 'test/fixtures/partials/one.min.css' ) ;
836- deleteFile ( 'test/fixtures/partials/five.min.css' ) ;
841+ execSync ( 'rm -fr test/fixtures-batch-3' ) ;
837842 }
838843 } )
839844 } )
840845 . addBatch ( {
841- 'batch processing with output given' : binaryContext ( '-b -o ./test ./test/fixtures/partials/one.css ./test/fixtures/partials/five.css' , {
846+ 'batch processing with output given' : binaryContext ( '-b -o ./test ./test/fixtures-batch-4/partials/one.css ./test/fixtures-batch-4/partials/five.css' , {
847+ 'setup' : function ( ) {
848+ execSync ( 'cp -fr test/fixtures test/fixtures-batch-4' ) ;
849+ } ,
842850 'does not produce any errors' : function ( error ) {
843851 assert . equal ( error , '' ) ;
844852 } ,
845853 'creates two separate minified files' : function ( ) {
846- assert . isTrue ( fs . existsSync ( 'test/fixtures/partials/one-min.css' ) ) ;
847- assert . isFalse ( fs . existsSync ( 'test/fixtures/partials/two-min.css' ) ) ;
848- assert . isTrue ( fs . existsSync ( 'test/fixtures/partials/five-min.css' ) ) ;
854+ assert . isTrue ( fs . existsSync ( 'test/fixtures-batch-4 /partials/one-min.css' ) ) ;
855+ assert . isFalse ( fs . existsSync ( 'test/fixtures-batch-4 /partials/two-min.css' ) ) ;
856+ assert . isTrue ( fs . existsSync ( 'test/fixtures-batch-4 /partials/five-min.css' ) ) ;
849857 } ,
850858 'teardown' : function ( ) {
851- deleteFile ( 'test/fixtures/partials/one-min.css' ) ;
852- deleteFile ( 'test/fixtures/partials/five-min.css' ) ;
859+ execSync ( 'rm -fr test/fixtures-batch-4' ) ;
853860 }
854861 } )
855862 } )
0 commit comments