@@ -60,14 +60,16 @@ if (isWindows) {
60
60
t . teardown ( ( ) => {
61
61
whichPaths . delete ( 'cmd' )
62
62
} )
63
- t . match ( makeSpawnArgs ( {
64
- event : 'event' ,
65
- path : 'path' ,
66
- cmd : 'script "quoted parameter"; second command' ,
67
- } ) , [
68
- 'cmd' ,
69
- [ '/d' , '/s' , '/c' , / \. c m d $ / ] ,
70
- {
63
+
64
+ t . test ( 'simple script' , ( t ) => {
65
+ const [ shell , args , opts , cleanup ] = makeSpawnArgs ( {
66
+ event : 'event' ,
67
+ path : 'path' ,
68
+ cmd : 'script "quoted parameter"; second command' ,
69
+ } )
70
+ t . equal ( shell , 'cmd' , 'default shell applies' )
71
+ t . match ( args , [ '/d' , '/s' , '/c' , / \. c m d $ / ] , 'got expected args' )
72
+ t . match ( opts , {
71
73
env : {
72
74
npm_package_json : / p a c k a g e \. j s o n $ / ,
73
75
npm_lifecycle_event : 'event' ,
@@ -77,23 +79,29 @@ if (isWindows) {
77
79
stdio : undefined ,
78
80
cwd : 'path' ,
79
81
windowsVerbatimArguments : true ,
80
- } ,
81
- ] )
82
+ } , 'got expected options' )
82
83
83
- // with a funky ComSpec
84
- process . env . ComSpec = 'blrorp'
85
- whichPaths . set ( 'blrorp' , '/bin/blrorp ' )
86
- t . teardown ( ( ) => {
87
- whichPaths . delete ( 'blrorp' )
84
+ t . ok ( fs . existsSync ( args [ args . length - 1 ] ) , 'script file was written' )
85
+ cleanup ( )
86
+ t . not ( fs . existsSync ( args [ args . length - 1 ] ) , 'cleanup removes script file ' )
87
+
88
+ t . end ( )
88
89
} )
89
- t . match ( makeSpawnArgs ( {
90
- event : 'event' ,
91
- path : 'path' ,
92
- cmd : 'script "quoted parameter"; second command' ,
93
- } ) , [
94
- 'blrorp' ,
95
- [ '-c' , / \. s h $ / ] ,
96
- {
90
+
91
+ t . test ( 'with a funky ComSpec' , ( t ) => {
92
+ process . env . ComSpec = 'blrorp'
93
+ whichPaths . set ( 'blrorp' , '/bin/blrorp' )
94
+ t . teardown ( ( ) => {
95
+ whichPaths . delete ( 'blrorp' )
96
+ } )
97
+ const [ shell , args , opts , cleanup ] = makeSpawnArgs ( {
98
+ event : 'event' ,
99
+ path : 'path' ,
100
+ cmd : 'script "quoted parameter"; second command' ,
101
+ } )
102
+ t . equal ( shell , 'blrorp' , 'used ComSpec as default shell' )
103
+ t . match ( args , [ '-c' , / \. s h $ / ] , 'got expected args' )
104
+ t . match ( opts , {
97
105
env : {
98
106
npm_package_json : / p a c k a g e \. j s o n $ / ,
99
107
npm_lifecycle_event : 'event' ,
@@ -102,19 +110,26 @@ if (isWindows) {
102
110
stdio : undefined ,
103
111
cwd : 'path' ,
104
112
windowsVerbatimArguments : undefined ,
105
- } ,
106
- ] )
107
-
108
- t . match ( makeSpawnArgs ( {
109
- event : 'event' ,
110
- path : 'path' ,
111
- cmd : 'script' ,
112
- args : [ '"quoted parameter";' , 'second command' ] ,
113
- scriptShell : 'cmd.exe' ,
114
- } ) , [
115
- 'cmd.exe' ,
116
- [ '/d' , '/s' , '/c' , / \. c m d $ / ] ,
117
- {
113
+ } , 'got expected options' )
114
+
115
+ t . ok ( fs . existsSync ( args [ args . length - 1 ] ) , 'script file was written' )
116
+ cleanup ( )
117
+ t . not ( fs . existsSync ( args [ args . length - 1 ] ) , 'cleanup removes script file' )
118
+
119
+ t . end ( )
120
+ } )
121
+
122
+ t . test ( 'with cmd.exe as scriptShell' , ( t ) => {
123
+ const [ shell , args , opts , cleanup ] = makeSpawnArgs ( {
124
+ event : 'event' ,
125
+ path : 'path' ,
126
+ cmd : 'script' ,
127
+ args : [ '"quoted parameter";' , 'second command' ] ,
128
+ scriptShell : 'cmd.exe' ,
129
+ } )
130
+ t . equal ( shell , 'cmd.exe' , 'kept cmd.exe' )
131
+ t . match ( args , [ '/d' , '/s' , '/c' , / \. c m d $ / ] , 'got expected args' )
132
+ t . match ( opts , {
118
133
env : {
119
134
npm_package_json : / p a c k a g e \. j s o n $ / ,
120
135
npm_lifecycle_event : 'event' ,
@@ -123,8 +138,14 @@ if (isWindows) {
123
138
stdio : undefined ,
124
139
cwd : 'path' ,
125
140
windowsVerbatimArguments : true ,
126
- } ,
127
- ] )
141
+ } , 'got expected options' )
142
+
143
+ t . ok ( fs . existsSync ( args [ args . length - 1 ] ) , 'script file was written' )
144
+ cleanup ( )
145
+ t . not ( fs . existsSync ( args [ args . length - 1 ] ) , 'cleanup removes script file' )
146
+
147
+ t . end ( )
148
+ } )
128
149
129
150
t . end ( )
130
151
} )
@@ -134,15 +155,17 @@ if (isWindows) {
134
155
t . teardown ( ( ) => {
135
156
whichPaths . delete ( 'sh' )
136
157
} )
137
- t . match ( makeSpawnArgs ( {
138
- event : 'event' ,
139
- path : 'path' ,
140
- cmd : 'script' ,
141
- args : [ '"quoted parameter";' , 'second command' ] ,
142
- } ) , [
143
- 'sh' ,
144
- [ '-c' , / \. s h $ / ] ,
145
- {
158
+
159
+ t . test ( 'simple script' , ( t ) => {
160
+ const [ shell , args , opts , cleanup ] = makeSpawnArgs ( {
161
+ event : 'event' ,
162
+ path : 'path' ,
163
+ cmd : 'script' ,
164
+ args : [ '"quoted parameter";' , 'second command' ] ,
165
+ } )
166
+ t . equal ( shell , 'sh' , 'defaults to sh' )
167
+ t . match ( args , [ '-c' , / \. s h $ / ] , 'got expected args' )
168
+ t . match ( opts , {
146
169
env : {
147
170
npm_package_json : / p a c k a g e \. j s o n $ / ,
148
171
npm_lifecycle_event : 'event' ,
@@ -151,20 +174,27 @@ if (isWindows) {
151
174
stdio : undefined ,
152
175
cwd : 'path' ,
153
176
windowsVerbatimArguments : undefined ,
154
- } ,
155
- ] )
156
-
157
- // test that we can explicitly run in cmd.exe, even on posix systems
158
- // relevant for running under WSL
159
- t . match ( makeSpawnArgs ( {
160
- event : 'event' ,
161
- path : 'path' ,
162
- cmd : 'script "quoted parameter"; second command' ,
163
- scriptShell : 'cmd.exe' ,
164
- } ) , [
165
- 'cmd.exe' ,
166
- [ '/d' , '/s' , '/c' , / \. c m d $ / ] ,
167
- {
177
+ } , 'got expected options' )
178
+
179
+ t . ok ( fs . existsSync ( args [ args . length - 1 ] ) , 'script file was written' )
180
+ cleanup ( )
181
+ t . not ( fs . existsSync ( args [ args . length - 1 ] ) , 'cleanup removes script file' )
182
+
183
+ t . end ( )
184
+ } )
185
+
186
+ t . test ( 'can use cmd.exe' , ( t ) => {
187
+ // test that we can explicitly run in cmd.exe, even on posix systems
188
+ // relevant for running under WSL
189
+ const [ shell , args , opts , cleanup ] = makeSpawnArgs ( {
190
+ event : 'event' ,
191
+ path : 'path' ,
192
+ cmd : 'script "quoted parameter"; second command' ,
193
+ scriptShell : 'cmd.exe' ,
194
+ } )
195
+ t . equal ( shell , 'cmd.exe' , 'kept cmd.exe' )
196
+ t . match ( args , [ '/d' , '/s' , '/c' , / \. c m d $ / ] , 'got expected args' )
197
+ t . match ( opts , {
168
198
env : {
169
199
npm_package_json : / p a c k a g e \. j s o n $ / ,
170
200
npm_lifecycle_event : 'event' ,
@@ -173,8 +203,14 @@ if (isWindows) {
173
203
stdio : undefined ,
174
204
cwd : 'path' ,
175
205
windowsVerbatimArguments : true ,
176
- } ,
177
- ] )
206
+ } , 'got expected options' )
207
+
208
+ t . ok ( fs . existsSync ( args [ args . length - 1 ] ) , 'script file was written' )
209
+ cleanup ( )
210
+ t . not ( fs . existsSync ( args [ args . length - 1 ] ) , 'cleanup removes script file' )
211
+
212
+ t . end ( )
213
+ } )
178
214
179
215
t . end ( )
180
216
} )
0 commit comments