@@ -65,14 +65,48 @@ describe('shell module', () => {
65
65
const fakeArgs = [ '"hi there"' ] ;
66
66
shell . runCommandSync ( fakeCmd , fakeArgs ) ;
67
67
sandbox . assert . calledOnce ( assembleSpy ) ;
68
- sandbox . assert . calledWithMatch ( runSpy , fakeCmd , fakeArgs , sinon . match ( { shell : true , env : fakeEnv } ) ) ;
68
+ sandbox . assert . calledWithMatch (
69
+ runSpy ,
70
+ sinon . match . string ,
71
+ sinon . match . array ,
72
+ sinon . match ( { shell : true , env : fakeEnv } ) ,
73
+ ) ;
69
74
} ) ;
70
75
it ( 'should raise bubble error details up' , ( ) => {
71
76
runSpy . throws ( new Error ( 'this is bat country' ) ) ;
72
77
assert . throw ( ( ) => {
73
78
shell . runCommandSync ( 'about to explode' , [ ] ) ;
74
79
} , / t h i s i s b a t c o u n t r y / ) ;
75
80
} ) ;
81
+ if ( process . platform === 'win32' ) {
82
+ it ( 'on Windows, should wrap command to shell out in a `cmd /s /c` wrapper process' , ( ) => {
83
+ const fakeEnv = { HEY : 'yo' } ;
84
+ sandbox . stub ( shell , 'assembleShellEnv' ) . returns ( fakeEnv ) ;
85
+ const fakeCmd = 'echo' ;
86
+ const fakeArgs = [ '"hi there"' ] ;
87
+ shell . runCommandSync ( fakeCmd , fakeArgs ) ;
88
+ sandbox . assert . calledWithMatch (
89
+ runSpy ,
90
+ 'cmd' ,
91
+ sinon . match . array . contains ( [ '/s' , '/c' , fakeCmd , ...fakeArgs ] ) ,
92
+ sinon . match ( { shell : true , env : fakeEnv } ) ,
93
+ ) ;
94
+ } ) ;
95
+ } else {
96
+ it ( 'on non-Windows, should shell out to provided command directly' , ( ) => {
97
+ const fakeEnv = { HEY : 'yo' } ;
98
+ sandbox . stub ( shell , 'assembleShellEnv' ) . returns ( fakeEnv ) ;
99
+ const fakeCmd = 'echo' ;
100
+ const fakeArgs = [ '"hi there"' ] ;
101
+ shell . runCommandSync ( fakeCmd , fakeArgs ) ;
102
+ sandbox . assert . calledWithMatch (
103
+ runSpy ,
104
+ fakeCmd ,
105
+ sinon . match . array . contains ( fakeArgs ) ,
106
+ sinon . match ( { shell : true , env : fakeEnv } ) ,
107
+ ) ;
108
+ } ) ;
109
+ }
76
110
} ) ;
77
111
78
112
describe ( 'spawnProcess method' , ( ) => {
@@ -83,14 +117,48 @@ describe('shell module', () => {
83
117
const fakeArgs = [ '"hi there"' ] ;
84
118
shell . spawnProcess ( fakeCmd , fakeArgs ) ;
85
119
sandbox . assert . calledOnce ( assembleSpy ) ;
86
- sandbox . assert . calledWithMatch ( spawnSpy , fakeCmd , fakeArgs , sinon . match ( { shell : true , env : fakeEnv } ) ) ;
120
+ sandbox . assert . calledWithMatch (
121
+ spawnSpy ,
122
+ sinon . match . string ,
123
+ sinon . match . array ,
124
+ sinon . match ( { shell : true , env : fakeEnv } ) ,
125
+ ) ;
87
126
} ) ;
88
127
it ( 'should raise bubble error details up' , ( ) => {
89
128
spawnSpy . throws ( new Error ( 'this is bat country' ) ) ;
90
129
assert . throw ( ( ) => {
91
130
shell . spawnProcess ( 'about to explode' , [ ] ) ;
92
131
} , / t h i s i s b a t c o u n t r y / ) ;
93
132
} ) ;
133
+ if ( process . platform === 'win32' ) {
134
+ it ( 'on Windows, should wrap command to shell out in a `cmd /s /c` wrapper process' , ( ) => {
135
+ const fakeEnv = { HEY : 'yo' } ;
136
+ sandbox . stub ( shell , 'assembleShellEnv' ) . returns ( fakeEnv ) ;
137
+ const fakeCmd = 'echo' ;
138
+ const fakeArgs = [ '"hi there"' ] ;
139
+ shell . spawnProcess ( fakeCmd , fakeArgs ) ;
140
+ sandbox . assert . calledWithMatch (
141
+ spawnSpy ,
142
+ 'cmd' ,
143
+ sinon . match . array . contains ( [ '/s' , '/c' , fakeCmd , ...fakeArgs ] ) ,
144
+ sinon . match ( { shell : true , env : fakeEnv } ) ,
145
+ ) ;
146
+ } ) ;
147
+ } else {
148
+ it ( 'on non-Windows, should shell out to provided command directly' , ( ) => {
149
+ const fakeEnv = { HEY : 'yo' } ;
150
+ sandbox . stub ( shell , 'assembleShellEnv' ) . returns ( fakeEnv ) ;
151
+ const fakeCmd = 'echo' ;
152
+ const fakeArgs = [ '"hi there"' ] ;
153
+ shell . spawnProcess ( fakeCmd , fakeArgs ) ;
154
+ sandbox . assert . calledWithMatch (
155
+ spawnSpy ,
156
+ fakeCmd ,
157
+ sinon . match . array . contains ( fakeArgs ) ,
158
+ sinon . match ( { shell : true , env : fakeEnv } ) ,
159
+ ) ;
160
+ } ) ;
161
+ }
94
162
} ) ;
95
163
96
164
describe ( 'waitForOutput method' , ( ) => {
0 commit comments