2017-06-10 06:56:03 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*
|
|
|
|
* @format
|
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
let spawnError = false;
|
2016-05-20 11:52:08 +00:00
|
|
|
|
|
|
|
jest.setMock('child_process', {
|
|
|
|
spawn: () => ({
|
2017-06-10 06:56:03 +00:00
|
|
|
on: (event, cb) => cb(spawnError),
|
2016-05-20 11:52:08 +00:00
|
|
|
}),
|
|
|
|
});
|
|
|
|
|
2016-08-22 15:56:14 +00:00
|
|
|
const makeCommand = require('../makeCommand');
|
2016-05-20 11:52:08 +00:00
|
|
|
|
|
|
|
describe('makeCommand', () => {
|
|
|
|
const command = makeCommand('echo');
|
|
|
|
|
2017-06-10 06:56:03 +00:00
|
|
|
it('generates a function around shell command', () => {
|
2016-05-20 11:52:08 +00:00
|
|
|
expect(typeof command).toBe('function');
|
|
|
|
});
|
|
|
|
|
2017-06-10 06:56:03 +00:00
|
|
|
it('throws an error if there is no callback provided', () => {
|
2016-05-20 11:52:08 +00:00
|
|
|
expect(command).toThrow();
|
|
|
|
});
|
|
|
|
|
2017-06-10 06:56:03 +00:00
|
|
|
it('invokes a callback after command execution', () => {
|
|
|
|
const spy = jest.fn();
|
2016-05-20 11:52:08 +00:00
|
|
|
command(spy);
|
2017-06-10 06:56:03 +00:00
|
|
|
expect(spy.mock.calls).toHaveLength(1);
|
2016-05-20 11:52:08 +00:00
|
|
|
});
|
|
|
|
|
2017-06-10 06:56:03 +00:00
|
|
|
it('throws an error if spawn ended up with error', () => {
|
2016-05-20 11:52:08 +00:00
|
|
|
spawnError = true;
|
2017-06-10 06:56:03 +00:00
|
|
|
const cb = jest.fn();
|
|
|
|
expect(() => {
|
|
|
|
command(cb);
|
|
|
|
}).toThrow();
|
2016-05-20 11:52:08 +00:00
|
|
|
});
|
|
|
|
});
|