@@ -103,23 +103,6 @@ describe('api', function() {
103103 } ) ;
104104 } ) ;
105105
106- it ( 'should throw error when libsass binary is missing.' , function ( done ) {
107- var originalBin = process . sass . binaryPath ,
108- renamedBin = [ originalBin , '_moved' ] . join ( '' ) ;
109-
110- assert . throws ( function ( ) {
111- fs . renameSync ( originalBin , renamedBin ) ;
112- process . sass . getBinaryPath ( true ) ;
113- } , function ( err ) {
114- fs . renameSync ( renamedBin , originalBin ) ;
115-
116- if ( ( err instanceof Error ) && / ` l i b s a s s ` b i n d i n g s n o t f o u n d . T r y r e i n s t a l l i n g ` n o d e - s a s s ` ? / . test ( err ) ) {
117- done ( ) ;
118- return true ;
119- }
120- } ) ;
121- } ) ;
122-
123106 it ( 'should render with --precision option' , function ( done ) {
124107 var src = read ( fixture ( 'precision/index.scss' ) , 'utf8' ) ;
125108 var expected = read ( fixture ( 'precision/expected.css' ) , 'utf8' ) . trim ( ) ;
@@ -729,4 +712,87 @@ describe('api', function() {
729712 done ( ) ;
730713 } ) ;
731714 } ) ;
715+
716+ describe ( 'extensions' , function ( ) {
717+ it ( 'should use the binary path and name set in package.json.' , function ( done ) {
718+ var packagePath = require . resolve ( '../package' ) ,
719+ extensionsPath = require . resolve ( '../lib/extensions' ) ;
720+
721+ delete require . cache [ extensionsPath ] ;
722+
723+ require . cache [ packagePath ] . exports . nodeSassConfig = { binaryName : 'foo' , binaryPath : 'bar' } ;
724+ require ( extensionsPath ) ;
725+
726+ assert . equal ( process . sass . binaryName , 'foo_binding.node' ) ;
727+ assert . equal ( process . sass . binaryPath , 'bar' ) ;
728+
729+ delete require . cache [ packagePath ] ;
730+ delete require . cache [ extensionsPath ] ;
731+
732+ require ( extensionsPath ) ;
733+
734+ done ( ) ;
735+ } ) ;
736+
737+ it ( 'should use the binary path and name set as environment variable.' , function ( done ) {
738+ var extensionsPath = require . resolve ( '../lib/extensions' ) ;
739+
740+ delete require . cache [ extensionsPath ] ;
741+
742+ process . env . SASS_BINARY_NAME = 'foo' ;
743+ process . env . SASS_BINARY_PATH = 'bar' ;
744+
745+ require ( extensionsPath ) ;
746+
747+ assert . equal ( process . sass . binaryName , 'foo_binding.node' ) ;
748+ assert . equal ( process . sass . binaryPath , 'bar' ) ;
749+
750+ delete process . env . SASS_BINARY_NAME ;
751+ delete process . env . SASS_BINARY_PATH ;
752+ delete require . cache [ extensionsPath ] ;
753+
754+ require ( extensionsPath ) ;
755+
756+ done ( ) ;
757+ } ) ;
758+
759+ it ( 'should use the binary path and name set as process argument.' , function ( done ) {
760+ var extensionsPath = require . resolve ( '../lib/extensions' ) ,
761+ argv = process . argv ;
762+
763+ delete require . cache [ extensionsPath ] ;
764+
765+ process . argv = argv . concat ( [ '--binary-name' , 'foo' , '--binary-path' , 'bar' ] ) ;
766+
767+ require ( extensionsPath ) ;
768+
769+ assert . equal ( process . sass . binaryName , 'foo_binding.node' ) ;
770+ assert . equal ( process . sass . binaryPath , 'bar' ) ;
771+
772+ process . argv = argv ;
773+
774+ delete require . cache [ extensionsPath ] ;
775+
776+ require ( extensionsPath ) ;
777+
778+ done ( ) ;
779+ } ) ;
780+
781+ it ( 'should throw error when libsass binary is missing.' , function ( done ) {
782+ var originalBin = process . sass . binaryPath ,
783+ renamedBin = [ originalBin , '_moved' ] . join ( '' ) ;
784+
785+ assert . throws ( function ( ) {
786+ fs . renameSync ( originalBin , renamedBin ) ;
787+ process . sass . getBinaryPath ( true ) ;
788+ } , function ( err ) {
789+ fs . renameSync ( renamedBin , originalBin ) ;
790+
791+ if ( ( err instanceof Error ) && / ` l i b s a s s ` b i n d i n g s n o t f o u n d . T r y r e i n s t a l l i n g ` n o d e - s a s s ` ? / . test ( err ) ) {
792+ done ( ) ;
793+ return true ;
794+ }
795+ } ) ;
796+ } ) ;
797+ } ) ;
732798} ) ;
0 commit comments