@@ -4,8 +4,9 @@ import chai, { expect } from 'chai';
44import sinon from 'sinon' ;
55import { default as sinonChai } from 'sinon-chai' ;
66import Util from 'browser/model/helpers/util' ;
7+ import Platform from 'browser/services/platform' ;
78import child_process from 'child_process' ;
8- import fs from 'fs' ;
9+ import fs from 'fs-extra ' ;
910chai . use ( sinonChai ) ;
1011
1112describe ( 'Util' , function ( ) {
@@ -39,6 +40,15 @@ describe('Util', function() {
3940 } ) ;
4041 } ) ;
4142
43+ it ( 'should resolve to standard output when called with only one param' , function ( ) {
44+ sandbox . stub ( child_process , 'exec' ) . yields ( null , 'stdout' , 'stderr' ) ;
45+
46+ return Util . executeCommand ( 'command' )
47+ . then ( ( result ) => {
48+ expect ( result ) . to . equal ( 'stdout' ) ;
49+ } ) ;
50+ } ) ;
51+
4252 it ( 'should resolve to error output with 2 as second param' , function ( ) {
4353 sandbox . stub ( child_process , 'exec' ) . yields ( null , 'stdout' , 'stderr' ) ;
4454
@@ -60,6 +70,58 @@ describe('Util', function() {
6070 expect ( error ) . to . equal ( err ) ;
6171 } ) ;
6272 } ) ;
73+
74+ describe ( 'on macos' , function ( ) {
75+ describe ( 'when options parameter is undefined' , function ( ) {
76+ it ( 'should set options.env.PATH to "/usr/local/bin" if process.env.PATH is not present or empty' , function ( ) {
77+ sandbox . stub ( Platform , 'getOS' ) . returns ( 'darwin' ) ;
78+ sandbox . stub ( Platform , 'getEnv' ) . returns ( { PATH :'' } ) ;
79+ let mock = sandbox . mock ( child_process ) ;
80+ let execExpect = mock . expects ( 'exec' ) ;
81+ execExpect . withArgs ( 'command' , { env : { PATH :'/usr/local/bin' } } ) ;
82+ execExpect . yields ( null , 'stdout' , 'stderr' ) ;
83+ return Util . executeCommand ( 'command' , 1 ) . then ( ( ) => {
84+ mock . verify ( ) ;
85+ } ) ;
86+ } ) ;
87+
88+ it ( 'should add ":/usr/local/bin" to the options.env.PATH if process.env.PATH is not empty' , function ( ) {
89+ sandbox . stub ( Platform , 'getOS' ) . returns ( 'darwin' ) ;
90+ sandbox . stub ( Platform , 'getEnv' ) . returns ( { PATH :'/bin' } ) ;
91+ let mock = sandbox . mock ( child_process ) ;
92+ let execExpect = mock . expects ( 'exec' ) ;
93+ execExpect . withArgs ( 'command' , { env : { PATH :'/bin:/usr/local/bin' } } ) ;
94+ execExpect . yields ( null , 'stdout' , 'stderr' ) ;
95+ return Util . executeCommand ( 'command' , 1 ) . then ( ( ) => {
96+ mock . verify ( ) ;
97+ } ) ;
98+ } ) ;
99+ } ) ;
100+
101+ describe ( 'when options parameter is provided' , function ( ) {
102+ it ( 'should set options.env.PATH to "/usr/local/bin" if options.env.PATH is not present or empty' , function ( ) {
103+ sandbox . stub ( Platform , 'getOS' ) . returns ( 'darwin' ) ;
104+ let mock = sandbox . mock ( child_process ) ;
105+ let execExpect = mock . expects ( 'exec' ) ;
106+ execExpect . withArgs ( 'command' , { env : { PATH :'/usr/local/bin' } } ) ;
107+ execExpect . yields ( null , 'stdout' , 'stderr' ) ;
108+ return Util . executeCommand ( 'command' , 1 , { env : { PATH :'' } } ) . then ( ( ) => {
109+ mock . verify ( ) ;
110+ } ) ;
111+ } ) ;
112+
113+ it ( 'should add ":/usr/local/bin" to the options.env.PATH if options.env.PATH is not empty' , function ( ) {
114+ sandbox . stub ( Platform , 'getOS' ) . returns ( 'darwin' ) ;
115+ let mock = sandbox . mock ( child_process ) ;
116+ let execExpect = mock . expects ( 'exec' ) ;
117+ execExpect . withArgs ( 'command' , { env : { PATH :'/bin:/usr/local/bin' } } ) ;
118+ execExpect . yields ( null , 'stdout' , 'stderr' ) ;
119+ return Util . executeCommand ( 'command' , 1 , { env : { PATH :'/bin' } } ) . then ( ( ) => {
120+ mock . verify ( ) ;
121+ } ) ;
122+ } ) ;
123+ } ) ;
124+ } ) ;
63125 } ) ;
64126
65127 describe ( 'executeFile' , function ( ) {
@@ -82,6 +144,15 @@ describe('Util', function() {
82144 } ) ;
83145 } ) ;
84146
147+ it ( 'should resolve to standard output when called with only one param' , function ( ) {
148+ sandbox . stub ( child_process , 'execFile' ) . yields ( null , 'stdout' , 'stderr' ) ;
149+
150+ return Util . executeFile ( 'file' , 'arguments' )
151+ . then ( ( result ) => {
152+ expect ( result ) . to . equal ( 'stdout' ) ;
153+ } ) ;
154+ } ) ;
155+
85156 it ( 'should resolve to error output with 2 as second param' , function ( ) {
86157 sandbox . stub ( child_process , 'execFile' ) . yields ( null , 'stdout' , 'stderr' ) ;
87158
@@ -210,4 +281,16 @@ describe('Util', function() {
210281 } ) ;
211282 } ) ;
212283 } ) ;
284+
285+ describe ( 'writeFile' , function ( ) {
286+ it ( 'calls fs#writeFile with correct arguments' , function ( ) {
287+ sandbox . stub ( fs , 'writeFile' ) . yields ( ) ;
288+
289+ return Util . writeFile ( 'file' , 'data' )
290+ . then ( function ( ) {
291+ expect ( fs . writeFile ) . to . have . been . calledOnce ;
292+ expect ( fs . writeFile ) . to . have . been . calledWith ( 'file' , 'data' ) ;
293+ } ) ;
294+ } ) ;
295+ } ) ;
213296} ) ;
0 commit comments