Skip to content

Commit 4b2252e

Browse files
feat: spawn instead of exec (#259)
1 parent 487c8e5 commit 4b2252e

File tree

3 files changed

+172
-108
lines changed

3 files changed

+172
-108
lines changed

__tests__/command.test.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import {
33
testChildProcess,
44
setChildProcessParams,
5-
spyOnExec,
5+
spyOnSpawn,
66
execCalledWith,
77
spyOnStdout,
88
stdoutCalledWith,
@@ -18,7 +18,7 @@ describe('execAsync', () => {
1818
const command = new Command(new Logger());
1919

2020
it('should run command', async() => {
21-
const mockExec = spyOnExec();
21+
const mockExec = spyOnSpawn();
2222
const mockStdout = spyOnStdout();
2323

2424
expect(await command.execAsync({command: 'test'})).toEqual({stdout: 'stdout', stderr: '', command: 'test'});
@@ -34,13 +34,13 @@ describe('execAsync', () => {
3434

3535
it('should run command with cwd, altCommand', async() => {
3636
setChildProcessParams({stderr: 'stderr'});
37-
const mockExec = spyOnExec();
37+
const mockExec = spyOnSpawn();
3838
const mockStdout = spyOnStdout();
3939

4040
expect(await command.execAsync({command: 'test', cwd: 'dir', altCommand: 'alt'})).toEqual({stdout: 'stdout', stderr: 'stderr', command: 'alt'});
4141

4242
execCalledWith(mockExec, [
43-
['test', {'cwd': 'dir'}],
43+
['test', [], {'cwd': 'dir', shell: true}],
4444
]);
4545
stdoutCalledWith(mockStdout, [
4646
'[command]alt',
@@ -50,7 +50,7 @@ describe('execAsync', () => {
5050
});
5151

5252
it('should run command with args', async() => {
53-
const mockExec = spyOnExec();
53+
const mockExec = spyOnSpawn();
5454
const mockStdout = spyOnStdout();
5555

5656
expect(await command.execAsync({command: 'test', args: ['hello!', 'how are you doing $USER', '"double"', '\'single\'']})).toEqual({
@@ -69,7 +69,7 @@ describe('execAsync', () => {
6969
});
7070

7171
it('should run command with args, altCommand', async() => {
72-
const mockExec = spyOnExec();
72+
const mockExec = spyOnSpawn();
7373
const mockStdout = spyOnStdout();
7474

7575
expect(await command.execAsync({command: 'test', args: ['hello!', 'how are you doing $USER', '"double"', '\'single\''], altCommand: 'alt'})).toEqual({
@@ -89,7 +89,7 @@ describe('execAsync', () => {
8989

9090
it('should not output empty stdout', async() => {
9191
setChildProcessParams({stdout: ' \n\n \n'});
92-
const mockExec = spyOnExec();
92+
const mockExec = spyOnSpawn();
9393
const mockStdout = spyOnStdout();
9494

9595
expect(await command.execAsync({command: 'test'})).toEqual({stdout: '', stderr: '', command: 'test'});
@@ -104,7 +104,7 @@ describe('execAsync', () => {
104104

105105
it('should not output empty stderr', async() => {
106106
setChildProcessParams({stderr: ' \n\n \n'});
107-
const mockExec = spyOnExec();
107+
const mockExec = spyOnSpawn();
108108
const mockStdout = spyOnStdout();
109109

110110
expect(await command.execAsync({command: 'test'})).toEqual({stdout: 'stdout', stderr: '', command: 'test'});
@@ -125,7 +125,7 @@ describe('execAsync', () => {
125125

126126
await expect(command.execAsync({
127127
command: 'test',
128-
})).rejects.toBe('command [test] exited with code 123. message: test message');
128+
})).rejects.toThrow('command [test] exited with code 123. message: test message');
129129
});
130130

131131
it('should catch error 2', async() => {
@@ -136,7 +136,7 @@ describe('execAsync', () => {
136136
await expect(command.execAsync({
137137
command: 'test',
138138
altCommand: 'alt',
139-
})).rejects.toBe('command [alt] exited with code 123. message: test message');
139+
})).rejects.toThrow('command [alt] exited with code 123. message: test message');
140140
});
141141

142142
it('should catch error 3', async() => {
@@ -148,7 +148,7 @@ describe('execAsync', () => {
148148
command: 'test',
149149
altCommand: 'alt',
150150
quiet: true,
151-
})).rejects.toBe('command [alt] exited with code 123.');
151+
})).rejects.toThrow('command [alt] exited with code 123.');
152152
});
153153

154154
it('should catch error 4', async() => {
@@ -159,11 +159,11 @@ describe('execAsync', () => {
159159
await expect(command.execAsync({
160160
command: 'test',
161161
quiet: true,
162-
})).rejects.toBe('command exited with code 123.');
162+
})).rejects.toThrow('command exited with code 123.');
163163
});
164164

165165
it('should suppress stdout', async() => {
166-
const mockExec = spyOnExec();
166+
const mockExec = spyOnSpawn();
167167
const mockStdout = spyOnStdout();
168168

169169
await command.execAsync({
@@ -181,7 +181,7 @@ describe('execAsync', () => {
181181

182182
it('should output stdout instead of stderr', async() => {
183183
setChildProcessParams({stderr: 'stderr'});
184-
const mockExec = spyOnExec();
184+
const mockExec = spyOnSpawn();
185185
const mockStdout = spyOnStdout();
186186

187187
await command.execAsync({
@@ -201,7 +201,7 @@ describe('execAsync', () => {
201201

202202
it('should not output stdout', async() => {
203203
setChildProcessParams({stdout: ''});
204-
const mockExec = spyOnExec();
204+
const mockExec = spyOnSpawn();
205205
const mockStdout = spyOnStdout();
206206

207207
await command.execAsync({
@@ -217,7 +217,7 @@ describe('execAsync', () => {
217217
});
218218

219219
it('should run suppress error command', async() => {
220-
const mockExec = spyOnExec();
220+
const mockExec = spyOnSpawn();
221221
const mockStdout = spyOnStdout();
222222

223223
await command.execAsync({

0 commit comments

Comments
 (0)