Skip to content

feat: spawn instead of exec (#259) #264

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions __tests__/command.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import {
testChildProcess,
setChildProcessParams,
spyOnExec,
spyOnSpawn,
execCalledWith,
spyOnStdout,
stdoutCalledWith,
Expand All @@ -18,7 +18,7 @@ describe('execAsync', () => {
const command = new Command(new Logger());

it('should run command', async() => {
const mockExec = spyOnExec();
const mockExec = spyOnSpawn();
const mockStdout = spyOnStdout();

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

it('should run command with cwd, altCommand', async() => {
setChildProcessParams({stderr: 'stderr'});
const mockExec = spyOnExec();
const mockExec = spyOnSpawn();
const mockStdout = spyOnStdout();

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

execCalledWith(mockExec, [
['test', {'cwd': 'dir'}],
['test', [], {'cwd': 'dir', shell: true}],
]);
stdoutCalledWith(mockStdout, [
'[command]alt',
Expand All @@ -50,7 +50,7 @@ describe('execAsync', () => {
});

it('should run command with args', async() => {
const mockExec = spyOnExec();
const mockExec = spyOnSpawn();
const mockStdout = spyOnStdout();

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

it('should run command with args, altCommand', async() => {
const mockExec = spyOnExec();
const mockExec = spyOnSpawn();
const mockStdout = spyOnStdout();

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

it('should not output empty stdout', async() => {
setChildProcessParams({stdout: ' \n\n \n'});
const mockExec = spyOnExec();
const mockExec = spyOnSpawn();
const mockStdout = spyOnStdout();

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

it('should not output empty stderr', async() => {
setChildProcessParams({stderr: ' \n\n \n'});
const mockExec = spyOnExec();
const mockExec = spyOnSpawn();
const mockStdout = spyOnStdout();

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

await expect(command.execAsync({
command: 'test',
})).rejects.toBe('command [test] exited with code 123. message: test message');
})).rejects.toThrow('command [test] exited with code 123. message: test message');
});

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

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

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

it('should suppress stdout', async() => {
const mockExec = spyOnExec();
const mockExec = spyOnSpawn();
const mockStdout = spyOnStdout();

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

it('should output stdout instead of stderr', async() => {
setChildProcessParams({stderr: 'stderr'});
const mockExec = spyOnExec();
const mockExec = spyOnSpawn();
const mockStdout = spyOnStdout();

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

it('should not output stdout', async() => {
setChildProcessParams({stdout: ''});
const mockExec = spyOnExec();
const mockExec = spyOnSpawn();
const mockStdout = spyOnStdout();

await command.execAsync({
Expand All @@ -217,7 +217,7 @@ describe('execAsync', () => {
});

it('should run suppress error command', async() => {
const mockExec = spyOnExec();
const mockExec = spyOnSpawn();
const mockStdout = spyOnStdout();

await command.execAsync({
Expand Down
Loading