concurrently 5.0.0 → 5.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -18
- package/bin/concurrently.js +9 -1
- package/bin/epilogue.txt +0 -4
- package/index.js +3 -1
- package/package.json +11 -4
- package/src/completion-listener.js +26 -22
- package/src/concurrently.js +27 -9
- package/src/defaults.js +2 -0
- package/src/flow-control/kill-on-signal.js +1 -1
- package/src/get-spawn-opts.js +5 -4
- package/.editorconfig +0 -28
- package/.eslintrc.json +0 -23
- package/.travis.yml +0 -11
- package/.vscode/settings.json +0 -6
- package/CONTRIBUTING.md +0 -23
- package/appveyor.yml +0 -19
- package/bin/concurrently.spec.js +0 -365
- package/bin/fixtures/read-echo.js +0 -10
- package/docs/demo.gif +0 -0
- package/docs/frontend-demo.gif +0 -0
- package/docs/kill-demo.gif +0 -0
- package/docs/raw-demo.gif +0 -0
- package/src/command-parser/expand-npm-shortcut.spec.js +0 -36
- package/src/command-parser/expand-npm-wildcard.spec.js +0 -58
- package/src/command-parser/strip-quotes.spec.js +0 -20
- package/src/command.spec.js +0 -142
- package/src/completion-listener.spec.js +0 -88
- package/src/concurrently.spec.js +0 -77
- package/src/flow-control/input-handler.spec.js +0 -79
- package/src/flow-control/kill-on-signal.spec.js +0 -79
- package/src/flow-control/kill-others.spec.js +0 -66
- package/src/flow-control/log-error.spec.js +0 -40
- package/src/flow-control/log-exit.spec.js +0 -36
- package/src/flow-control/log-output.spec.js +0 -41
- package/src/flow-control/restart-process.spec.js +0 -129
- package/src/get-spawn-opts.spec.js +0 -18
- package/src/logger.spec.js +0 -178
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
const { TestScheduler } = require('rxjs/testing');
|
|
2
|
-
|
|
3
|
-
const createFakeCommand = require('./flow-control/fixtures/fake-command');
|
|
4
|
-
const CompletionListener = require('./completion-listener');
|
|
5
|
-
|
|
6
|
-
let commands, scheduler;
|
|
7
|
-
beforeEach(() => {
|
|
8
|
-
commands = [createFakeCommand('foo'), createFakeCommand('bar')];
|
|
9
|
-
scheduler = new TestScheduler();
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
const createController = successCondition => new CompletionListener({
|
|
13
|
-
successCondition,
|
|
14
|
-
scheduler
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
describe('with default success condition set', () => {
|
|
18
|
-
it('succeeds if all processes exited with code 0', () => {
|
|
19
|
-
const result = createController().listen(commands);
|
|
20
|
-
|
|
21
|
-
commands[0].close.next(0);
|
|
22
|
-
commands[1].close.next(0);
|
|
23
|
-
|
|
24
|
-
scheduler.flush();
|
|
25
|
-
|
|
26
|
-
return expect(result).resolves.toBeNull();
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('fails if one of the processes exited with non-0 code', () => {
|
|
30
|
-
const result = createController().listen(commands);
|
|
31
|
-
|
|
32
|
-
commands[0].close.next(0);
|
|
33
|
-
commands[1].close.next(1);
|
|
34
|
-
|
|
35
|
-
scheduler.flush();
|
|
36
|
-
|
|
37
|
-
expect(result).rejects.toThrowError();
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
describe('with success condition set to first', () => {
|
|
43
|
-
it('succeeds if first process to exit has code 0', () => {
|
|
44
|
-
const result = createController('first').listen(commands);
|
|
45
|
-
|
|
46
|
-
commands[1].close.next(0);
|
|
47
|
-
commands[0].close.next(1);
|
|
48
|
-
|
|
49
|
-
scheduler.flush();
|
|
50
|
-
|
|
51
|
-
return expect(result).resolves.toBeNull();
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('fails if first process to exit has non-0 code', () => {
|
|
55
|
-
const result = createController('first').listen(commands);
|
|
56
|
-
|
|
57
|
-
commands[1].close.next(1);
|
|
58
|
-
commands[0].close.next(0);
|
|
59
|
-
|
|
60
|
-
scheduler.flush();
|
|
61
|
-
|
|
62
|
-
return expect(result).rejects.toThrowError();
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
describe('with success condition set to last', () => {
|
|
67
|
-
it('succeeds if last process to exit has code 0', () => {
|
|
68
|
-
const result = createController('last').listen(commands);
|
|
69
|
-
|
|
70
|
-
commands[1].close.next(1);
|
|
71
|
-
commands[0].close.next(0);
|
|
72
|
-
|
|
73
|
-
scheduler.flush();
|
|
74
|
-
|
|
75
|
-
return expect(result).resolves.toBeNull();
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('fails if last process to exit has non-0 code', () => {
|
|
79
|
-
const result = createController('last').listen(commands);
|
|
80
|
-
|
|
81
|
-
commands[1].close.next(0);
|
|
82
|
-
commands[0].close.next(1);
|
|
83
|
-
|
|
84
|
-
scheduler.flush();
|
|
85
|
-
|
|
86
|
-
return expect(result).rejects.toThrowError();
|
|
87
|
-
});
|
|
88
|
-
});
|
package/src/concurrently.spec.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
const EventEmitter = require('events');
|
|
2
|
-
const { Subject } = require('rxjs');
|
|
3
|
-
|
|
4
|
-
const createFakeCommand = require('./flow-control/fixtures/fake-command');
|
|
5
|
-
const concurrently = require('./concurrently');
|
|
6
|
-
|
|
7
|
-
let spawn, kill, controllers;
|
|
8
|
-
beforeEach(() => {
|
|
9
|
-
const process = new EventEmitter();
|
|
10
|
-
process.pid = 1;
|
|
11
|
-
|
|
12
|
-
spawn = jest.fn(() => process);
|
|
13
|
-
kill = jest.fn();
|
|
14
|
-
controllers = [{ handle: jest.fn(arg => arg) }, { handle: jest.fn(arg => arg) }];
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
const create = (commands, options = {}) => concurrently(
|
|
18
|
-
commands,
|
|
19
|
-
Object.assign(options, { controllers, spawn, kill })
|
|
20
|
-
);
|
|
21
|
-
|
|
22
|
-
it('fails if commands is not an array', () => {
|
|
23
|
-
const bomb = () => create('foo');
|
|
24
|
-
expect(bomb).toThrowError();
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('fails if no commands were provided', () => {
|
|
28
|
-
const bomb = () => create([]);
|
|
29
|
-
expect(bomb).toThrowError();
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it('spawns all commands', () => {
|
|
33
|
-
create(['echo', 'kill']);
|
|
34
|
-
expect(spawn).toHaveBeenCalledTimes(2);
|
|
35
|
-
expect(spawn).toHaveBeenCalledWith('echo', expect.objectContaining({}));
|
|
36
|
-
expect(spawn).toHaveBeenCalledWith('kill', expect.objectContaining({}));
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it('runs controllers with the commands', () => {
|
|
40
|
-
create(['echo', '"echo wrapped"']);
|
|
41
|
-
|
|
42
|
-
controllers.forEach(controller => {
|
|
43
|
-
expect(controller.handle).toHaveBeenCalledWith([
|
|
44
|
-
expect.objectContaining({ command: 'echo', index: 0 }),
|
|
45
|
-
expect.objectContaining({ command: 'echo wrapped', index: 1 }),
|
|
46
|
-
]);
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('runs commands with a name or prefix color', () => {
|
|
51
|
-
create([
|
|
52
|
-
{ command: 'echo', prefixColor: 'red', name: 'foo' },
|
|
53
|
-
'kill'
|
|
54
|
-
]);
|
|
55
|
-
|
|
56
|
-
controllers.forEach(controller => {
|
|
57
|
-
expect(controller.handle).toHaveBeenCalledWith([
|
|
58
|
-
expect.objectContaining({ command: 'echo', index: 0, name: 'foo', prefixColor: 'red' }),
|
|
59
|
-
expect.objectContaining({ command: 'kill', index: 1, name: '', prefixColor: '' }),
|
|
60
|
-
]);
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('passes commands wrapped from a controller to the next one', () => {
|
|
65
|
-
const fakeCommand = createFakeCommand('banana', 'banana');
|
|
66
|
-
controllers[0].handle.mockReturnValue([fakeCommand]);
|
|
67
|
-
|
|
68
|
-
create(['echo']);
|
|
69
|
-
|
|
70
|
-
expect(controllers[0].handle).toHaveBeenCalledWith([
|
|
71
|
-
expect.objectContaining({ command: 'echo', index: 0 })
|
|
72
|
-
]);
|
|
73
|
-
|
|
74
|
-
expect(controllers[1].handle).toHaveBeenCalledWith([fakeCommand]);
|
|
75
|
-
|
|
76
|
-
expect(fakeCommand.start).toHaveBeenCalledTimes(1);
|
|
77
|
-
});
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
const EventEmitter = require('events');
|
|
2
|
-
const { createMockInstance } = require('jest-create-mock-instance');
|
|
3
|
-
|
|
4
|
-
const Logger = require('../logger');
|
|
5
|
-
const createFakeCommand = require('./fixtures/fake-command');
|
|
6
|
-
const InputHandler = require('./input-handler');
|
|
7
|
-
|
|
8
|
-
let commands, controller, inputStream, logger;
|
|
9
|
-
|
|
10
|
-
beforeEach(() => {
|
|
11
|
-
commands = [
|
|
12
|
-
createFakeCommand('foo', 'echo foo', 0),
|
|
13
|
-
createFakeCommand('bar', 'echo bar', 1),
|
|
14
|
-
];
|
|
15
|
-
inputStream = new EventEmitter();
|
|
16
|
-
logger = createMockInstance(Logger);
|
|
17
|
-
controller = new InputHandler({
|
|
18
|
-
defaultInputTarget: 0,
|
|
19
|
-
inputStream,
|
|
20
|
-
logger
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('returns same commands', () => {
|
|
25
|
-
expect(controller.handle(commands)).toBe(commands);
|
|
26
|
-
|
|
27
|
-
controller = new InputHandler({ logger });
|
|
28
|
-
expect(controller.handle(commands)).toBe(commands);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('forwards input stream to default target ID', () => {
|
|
32
|
-
controller.handle(commands);
|
|
33
|
-
|
|
34
|
-
inputStream.emit('data', Buffer.from('something'));
|
|
35
|
-
|
|
36
|
-
expect(commands[0].stdin.write).toHaveBeenCalledTimes(1);
|
|
37
|
-
expect(commands[0].stdin.write).toHaveBeenCalledWith('something');
|
|
38
|
-
expect(commands[1].stdin.write).not.toHaveBeenCalled();
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('forwards input stream to target index specified in input', () => {
|
|
42
|
-
controller.handle(commands);
|
|
43
|
-
|
|
44
|
-
inputStream.emit('data', Buffer.from('1:something'));
|
|
45
|
-
|
|
46
|
-
expect(commands[0].stdin.write).not.toHaveBeenCalled();
|
|
47
|
-
expect(commands[1].stdin.write).toHaveBeenCalledTimes(1);
|
|
48
|
-
expect(commands[1].stdin.write).toHaveBeenCalledWith('something');
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it('forwards input stream to target name specified in input', () => {
|
|
52
|
-
controller.handle(commands);
|
|
53
|
-
|
|
54
|
-
inputStream.emit('data', Buffer.from('bar:something'));
|
|
55
|
-
|
|
56
|
-
expect(commands[0].stdin.write).not.toHaveBeenCalled();
|
|
57
|
-
expect(commands[1].stdin.write).toHaveBeenCalledTimes(1);
|
|
58
|
-
expect(commands[1].stdin.write).toHaveBeenCalledWith('something');
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('logs error if command has no stdin open', () => {
|
|
62
|
-
commands[0].stdin = null;
|
|
63
|
-
controller.handle(commands);
|
|
64
|
-
|
|
65
|
-
inputStream.emit('data', Buffer.from('something'));
|
|
66
|
-
|
|
67
|
-
expect(commands[1].stdin.write).not.toHaveBeenCalled();
|
|
68
|
-
expect(logger.logGlobalEvent).toHaveBeenCalledWith('Unable to find command 0, or it has no stdin open\n');
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it('logs error if command is not found', () => {
|
|
72
|
-
controller.handle(commands);
|
|
73
|
-
|
|
74
|
-
inputStream.emit('data', Buffer.from('foobar:something'));
|
|
75
|
-
|
|
76
|
-
expect(commands[0].stdin.write).not.toHaveBeenCalled();
|
|
77
|
-
expect(commands[1].stdin.write).not.toHaveBeenCalled();
|
|
78
|
-
expect(logger.logGlobalEvent).toHaveBeenCalledWith('Unable to find command foobar, or it has no stdin open\n');
|
|
79
|
-
});
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
const EventEmitter = require('events');
|
|
2
|
-
|
|
3
|
-
const createFakeCommand = require('./fixtures/fake-command');
|
|
4
|
-
const KillOnSignal = require('./kill-on-signal');
|
|
5
|
-
|
|
6
|
-
let commands, controller, process;
|
|
7
|
-
beforeEach(() => {
|
|
8
|
-
process = new EventEmitter();
|
|
9
|
-
commands = [
|
|
10
|
-
createFakeCommand(),
|
|
11
|
-
createFakeCommand(),
|
|
12
|
-
];
|
|
13
|
-
controller = new KillOnSignal({ process });
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it('returns commands that keep non-close streams from original commands', () => {
|
|
17
|
-
const newCommands = controller.handle(commands);
|
|
18
|
-
newCommands.forEach((newCommand, i) => {
|
|
19
|
-
expect(newCommand.close).not.toBe(commands[i].close);
|
|
20
|
-
expect(newCommand.error).toBe(commands[i].error);
|
|
21
|
-
expect(newCommand.stdout).toBe(commands[i].stdout);
|
|
22
|
-
expect(newCommand.stderr).toBe(commands[i].stderr);
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it('returns commands that map SIGINT to exit code 0', () => {
|
|
27
|
-
const newCommands = controller.handle(commands);
|
|
28
|
-
expect(newCommands).not.toBe(commands);
|
|
29
|
-
expect(newCommands).toHaveLength(commands.length);
|
|
30
|
-
|
|
31
|
-
const callback = jest.fn();
|
|
32
|
-
newCommands[0].close.subscribe(callback);
|
|
33
|
-
process.emit('SIGINT');
|
|
34
|
-
|
|
35
|
-
// A fake command's .kill() call won't trigger a close event automatically...
|
|
36
|
-
commands[0].close.next(1);
|
|
37
|
-
|
|
38
|
-
expect(callback).not.toHaveBeenCalledWith('SIGINT');
|
|
39
|
-
expect(callback).toHaveBeenCalledWith(0);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('returns commands that keep non-SIGINT exit codes', () => {
|
|
43
|
-
const newCommands = controller.handle(commands);
|
|
44
|
-
expect(newCommands).not.toBe(commands);
|
|
45
|
-
expect(newCommands).toHaveLength(commands.length);
|
|
46
|
-
|
|
47
|
-
const callback = jest.fn();
|
|
48
|
-
newCommands[0].close.subscribe(callback);
|
|
49
|
-
commands[0].close.next(1);
|
|
50
|
-
|
|
51
|
-
expect(callback).toHaveBeenCalledWith(1);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('kills all commands on SIGINT', () => {
|
|
55
|
-
controller.handle(commands);
|
|
56
|
-
process.emit('SIGINT');
|
|
57
|
-
|
|
58
|
-
expect(process.listenerCount('SIGINT')).toBe(1);
|
|
59
|
-
expect(commands[0].kill).toHaveBeenCalledWith('SIGINT');
|
|
60
|
-
expect(commands[1].kill).toHaveBeenCalledWith('SIGINT');
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it('kills all commands on SIGTERM', () => {
|
|
64
|
-
controller.handle(commands);
|
|
65
|
-
process.emit('SIGTERM');
|
|
66
|
-
|
|
67
|
-
expect(process.listenerCount('SIGTERM')).toBe(1);
|
|
68
|
-
expect(commands[0].kill).toHaveBeenCalledWith('SIGTERM');
|
|
69
|
-
expect(commands[1].kill).toHaveBeenCalledWith('SIGTERM');
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('kills all commands on SIGHUP', () => {
|
|
73
|
-
controller.handle(commands);
|
|
74
|
-
process.emit('SIGHUP');
|
|
75
|
-
|
|
76
|
-
expect(process.listenerCount('SIGHUP')).toBe(1);
|
|
77
|
-
expect(commands[0].kill).toHaveBeenCalledWith('SIGHUP');
|
|
78
|
-
expect(commands[1].kill).toHaveBeenCalledWith('SIGHUP');
|
|
79
|
-
});
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
const { createMockInstance } = require('jest-create-mock-instance');
|
|
2
|
-
|
|
3
|
-
const Logger = require('../logger');
|
|
4
|
-
const createFakeCommand = require('./fixtures/fake-command');
|
|
5
|
-
const KillOthers = require('./kill-others');
|
|
6
|
-
|
|
7
|
-
let commands, logger;
|
|
8
|
-
beforeEach(() => {
|
|
9
|
-
commands = [
|
|
10
|
-
createFakeCommand(),
|
|
11
|
-
createFakeCommand()
|
|
12
|
-
];
|
|
13
|
-
|
|
14
|
-
logger = createMockInstance(Logger);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
const createWithConditions = conditions => new KillOthers({
|
|
18
|
-
logger,
|
|
19
|
-
conditions
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it('returns same commands', () => {
|
|
23
|
-
expect(createWithConditions(['foo']).handle(commands)).toBe(commands);
|
|
24
|
-
expect(createWithConditions(['failure']).handle(commands)).toBe(commands);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('does not kill others if condition does not match', () => {
|
|
28
|
-
createWithConditions(['failure']).handle(commands);
|
|
29
|
-
commands[1].killable = true;
|
|
30
|
-
commands[0].close.next(0);
|
|
31
|
-
|
|
32
|
-
expect(logger.logGlobalEvent).not.toHaveBeenCalled();
|
|
33
|
-
expect(commands[0].kill).not.toHaveBeenCalled();
|
|
34
|
-
expect(commands[1].kill).not.toHaveBeenCalled();
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('kills other killable processes on success', () => {
|
|
38
|
-
createWithConditions(['success']).handle(commands);
|
|
39
|
-
commands[1].killable = true;
|
|
40
|
-
commands[0].close.next(0);
|
|
41
|
-
|
|
42
|
-
expect(logger.logGlobalEvent).toHaveBeenCalledTimes(1);
|
|
43
|
-
expect(logger.logGlobalEvent).toHaveBeenCalledWith('Sending SIGTERM to other processes..');
|
|
44
|
-
expect(commands[0].kill).not.toHaveBeenCalled();
|
|
45
|
-
expect(commands[1].kill).toHaveBeenCalled();
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('kills other killable processes on failure', () => {
|
|
49
|
-
createWithConditions(['failure']).handle(commands);
|
|
50
|
-
commands[1].killable = true;
|
|
51
|
-
commands[0].close.next(1);
|
|
52
|
-
|
|
53
|
-
expect(logger.logGlobalEvent).toHaveBeenCalledTimes(1);
|
|
54
|
-
expect(logger.logGlobalEvent).toHaveBeenCalledWith('Sending SIGTERM to other processes..');
|
|
55
|
-
expect(commands[0].kill).not.toHaveBeenCalled();
|
|
56
|
-
expect(commands[1].kill).toHaveBeenCalled();
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('does not try to kill processes already dead', () => {
|
|
60
|
-
createWithConditions(['failure']).handle(commands);
|
|
61
|
-
commands[0].close.next(1);
|
|
62
|
-
|
|
63
|
-
expect(logger.logGlobalEvent).not.toHaveBeenCalled();
|
|
64
|
-
expect(commands[0].kill).not.toHaveBeenCalled();
|
|
65
|
-
expect(commands[1].kill).not.toHaveBeenCalled();
|
|
66
|
-
});
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
const { createMockInstance } = require('jest-create-mock-instance');
|
|
2
|
-
const Logger = require('../logger');
|
|
3
|
-
const LogError = require('./log-error');
|
|
4
|
-
const createFakeCommand = require('./fixtures/fake-command');
|
|
5
|
-
|
|
6
|
-
let controller, logger, commands;
|
|
7
|
-
beforeEach(() => {
|
|
8
|
-
commands = [
|
|
9
|
-
createFakeCommand(),
|
|
10
|
-
createFakeCommand(),
|
|
11
|
-
];
|
|
12
|
-
|
|
13
|
-
logger = createMockInstance(Logger);
|
|
14
|
-
controller = new LogError({ logger });
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it('returns same commands', () => {
|
|
18
|
-
expect(controller.handle(commands)).toBe(commands);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it('logs the error event of each command', () => {
|
|
22
|
-
controller.handle(commands);
|
|
23
|
-
commands[0].error.next('error from command 0');
|
|
24
|
-
|
|
25
|
-
const error = new Error('some error message');
|
|
26
|
-
commands[1].error.next(error);
|
|
27
|
-
|
|
28
|
-
expect(logger.logCommandEvent).toHaveBeenCalledTimes(4);
|
|
29
|
-
expect(logger.logCommandEvent).toHaveBeenCalledWith(
|
|
30
|
-
`Error occurred when executing command: ${commands[0].command}`,
|
|
31
|
-
commands[0]
|
|
32
|
-
);
|
|
33
|
-
expect(logger.logCommandEvent).toHaveBeenCalledWith('error from command 0', commands[0]);
|
|
34
|
-
|
|
35
|
-
expect(logger.logCommandEvent).toHaveBeenCalledWith(
|
|
36
|
-
`Error occurred when executing command: ${commands[1].command}`,
|
|
37
|
-
commands[1]
|
|
38
|
-
);
|
|
39
|
-
expect(logger.logCommandEvent).toHaveBeenCalledWith(error.stack, commands[1]);
|
|
40
|
-
});
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
const { createMockInstance } = require('jest-create-mock-instance');
|
|
2
|
-
const Logger = require('../logger');
|
|
3
|
-
const LogExit = require('./log-exit');
|
|
4
|
-
const createFakeCommand = require('./fixtures/fake-command');
|
|
5
|
-
|
|
6
|
-
let controller, logger, commands;
|
|
7
|
-
beforeEach(() => {
|
|
8
|
-
commands = [
|
|
9
|
-
createFakeCommand(),
|
|
10
|
-
createFakeCommand(),
|
|
11
|
-
];
|
|
12
|
-
|
|
13
|
-
logger = createMockInstance(Logger);
|
|
14
|
-
controller = new LogExit({ logger });
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it('returns same commands', () => {
|
|
18
|
-
expect(controller.handle(commands)).toBe(commands);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it('logs the close event of each command', () => {
|
|
22
|
-
controller.handle(commands);
|
|
23
|
-
|
|
24
|
-
commands[0].close.next(0);
|
|
25
|
-
commands[1].close.next('SIGTERM');
|
|
26
|
-
|
|
27
|
-
expect(logger.logCommandEvent).toHaveBeenCalledTimes(2);
|
|
28
|
-
expect(logger.logCommandEvent).toHaveBeenCalledWith(
|
|
29
|
-
`${commands[0].command} exited with code 0`,
|
|
30
|
-
commands[0]
|
|
31
|
-
);
|
|
32
|
-
expect(logger.logCommandEvent).toHaveBeenCalledWith(
|
|
33
|
-
`${commands[1].command} exited with code SIGTERM`,
|
|
34
|
-
commands[1]
|
|
35
|
-
);
|
|
36
|
-
});
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
const { createMockInstance } = require('jest-create-mock-instance');
|
|
2
|
-
const Logger = require('../logger');
|
|
3
|
-
const LogOutput = require('./log-output');
|
|
4
|
-
const createFakeCommand = require('./fixtures/fake-command');
|
|
5
|
-
|
|
6
|
-
let controller, logger, commands;
|
|
7
|
-
beforeEach(() => {
|
|
8
|
-
commands = [
|
|
9
|
-
createFakeCommand(),
|
|
10
|
-
createFakeCommand(),
|
|
11
|
-
];
|
|
12
|
-
|
|
13
|
-
logger = createMockInstance(Logger);
|
|
14
|
-
controller = new LogOutput({ logger });
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it('returns same commands', () => {
|
|
18
|
-
expect(controller.handle(commands)).toBe(commands);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it('logs the stdout of each command', () => {
|
|
22
|
-
controller.handle(commands);
|
|
23
|
-
|
|
24
|
-
commands[0].stdout.next(Buffer.from('foo'));
|
|
25
|
-
commands[1].stdout.next(Buffer.from('bar'));
|
|
26
|
-
|
|
27
|
-
expect(logger.logCommandText).toHaveBeenCalledTimes(2);
|
|
28
|
-
expect(logger.logCommandText).toHaveBeenCalledWith('foo', commands[0]);
|
|
29
|
-
expect(logger.logCommandText).toHaveBeenCalledWith('bar', commands[1]);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it('logs the stderr of each command', () => {
|
|
33
|
-
controller.handle(commands);
|
|
34
|
-
|
|
35
|
-
commands[0].stderr.next(Buffer.from('foo'));
|
|
36
|
-
commands[1].stderr.next(Buffer.from('bar'));
|
|
37
|
-
|
|
38
|
-
expect(logger.logCommandText).toHaveBeenCalledTimes(2);
|
|
39
|
-
expect(logger.logCommandText).toHaveBeenCalledWith('foo', commands[0]);
|
|
40
|
-
expect(logger.logCommandText).toHaveBeenCalledWith('bar', commands[1]);
|
|
41
|
-
});
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
const { createMockInstance } = require('jest-create-mock-instance');
|
|
2
|
-
const { TestScheduler } = require('rxjs/testing');
|
|
3
|
-
|
|
4
|
-
const Logger = require('../logger');
|
|
5
|
-
const createFakeCommand = require('./fixtures/fake-command');
|
|
6
|
-
const RestartProcess = require('./restart-process');
|
|
7
|
-
|
|
8
|
-
let commands, controller, logger, scheduler;
|
|
9
|
-
beforeEach(() => {
|
|
10
|
-
commands = [
|
|
11
|
-
createFakeCommand(),
|
|
12
|
-
createFakeCommand()
|
|
13
|
-
];
|
|
14
|
-
|
|
15
|
-
logger = createMockInstance(Logger);
|
|
16
|
-
scheduler = new TestScheduler();
|
|
17
|
-
controller = new RestartProcess({
|
|
18
|
-
logger,
|
|
19
|
-
scheduler,
|
|
20
|
-
delay: 100,
|
|
21
|
-
tries: 2
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it('does not restart processes that complete with success', () => {
|
|
26
|
-
controller.handle(commands);
|
|
27
|
-
|
|
28
|
-
commands[0].close.next(0);
|
|
29
|
-
commands[1].close.next(0);
|
|
30
|
-
|
|
31
|
-
scheduler.flush();
|
|
32
|
-
|
|
33
|
-
expect(commands[0].start).toHaveBeenCalledTimes(0);
|
|
34
|
-
expect(commands[1].start).toHaveBeenCalledTimes(0);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('restarts processes that fail after delay has passed', () => {
|
|
38
|
-
controller.handle(commands);
|
|
39
|
-
|
|
40
|
-
commands[0].close.next(1);
|
|
41
|
-
commands[1].close.next(0);
|
|
42
|
-
|
|
43
|
-
scheduler.flush();
|
|
44
|
-
|
|
45
|
-
expect(logger.logCommandEvent).toHaveBeenCalledTimes(1);
|
|
46
|
-
expect(logger.logCommandEvent).toHaveBeenCalledWith(
|
|
47
|
-
`${commands[0].command} restarted`,
|
|
48
|
-
commands[0]
|
|
49
|
-
);
|
|
50
|
-
expect(commands[0].start).toHaveBeenCalledTimes(1);
|
|
51
|
-
expect(commands[1].start).not.toHaveBeenCalled();
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('restarts processes up to tries', () => {
|
|
55
|
-
controller.handle(commands);
|
|
56
|
-
|
|
57
|
-
commands[0].close.next(1);
|
|
58
|
-
commands[0].close.next('SIGTERM');
|
|
59
|
-
commands[0].close.next('SIGTERM');
|
|
60
|
-
commands[1].close.next(0);
|
|
61
|
-
|
|
62
|
-
scheduler.flush();
|
|
63
|
-
|
|
64
|
-
expect(logger.logCommandEvent).toHaveBeenCalledTimes(2);
|
|
65
|
-
expect(logger.logCommandEvent).toHaveBeenCalledWith(
|
|
66
|
-
`${commands[0].command} restarted`,
|
|
67
|
-
commands[0]
|
|
68
|
-
);
|
|
69
|
-
expect(commands[0].start).toHaveBeenCalledTimes(2);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('restarts processes until they succeed', () => {
|
|
73
|
-
controller.handle(commands);
|
|
74
|
-
|
|
75
|
-
commands[0].close.next(1);
|
|
76
|
-
commands[0].close.next(0);
|
|
77
|
-
commands[1].close.next(0);
|
|
78
|
-
|
|
79
|
-
scheduler.flush();
|
|
80
|
-
|
|
81
|
-
expect(logger.logCommandEvent).toHaveBeenCalledTimes(1);
|
|
82
|
-
expect(logger.logCommandEvent).toHaveBeenCalledWith(
|
|
83
|
-
`${commands[0].command} restarted`,
|
|
84
|
-
commands[0]
|
|
85
|
-
);
|
|
86
|
-
expect(commands[0].start).toHaveBeenCalledTimes(1);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
describe('returned commands', () => {
|
|
90
|
-
it('are the same if 0 tries are to be attempted', () => {
|
|
91
|
-
controller = new RestartProcess({ logger, scheduler });
|
|
92
|
-
expect(controller.handle(commands)).toBe(commands);
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it('are not the same, but with same length if 1+ tries are to be attempted', () => {
|
|
96
|
-
const newCommands = controller.handle(commands);
|
|
97
|
-
expect(newCommands).not.toBe(commands);
|
|
98
|
-
expect(newCommands).toHaveLength(commands.length);
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it('skip close events followed by restarts', () => {
|
|
102
|
-
const newCommands = controller.handle(commands);
|
|
103
|
-
|
|
104
|
-
const callback = jest.fn();
|
|
105
|
-
newCommands[0].close.subscribe(callback);
|
|
106
|
-
newCommands[1].close.subscribe(callback);
|
|
107
|
-
|
|
108
|
-
commands[0].close.next(1);
|
|
109
|
-
commands[0].close.next(1);
|
|
110
|
-
commands[0].close.next(1);
|
|
111
|
-
commands[1].close.next(1);
|
|
112
|
-
commands[1].close.next(0);
|
|
113
|
-
|
|
114
|
-
scheduler.flush();
|
|
115
|
-
|
|
116
|
-
// 1 failure from commands[0], 1 success from commands[1]
|
|
117
|
-
expect(callback).toHaveBeenCalledTimes(2);
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it('keep non-close streams from original commands', () => {
|
|
121
|
-
const newCommands = controller.handle(commands);
|
|
122
|
-
newCommands.forEach((newCommand, i) => {
|
|
123
|
-
expect(newCommand.close).not.toBe(commands[i].close);
|
|
124
|
-
expect(newCommand.error).toBe(commands[i].error);
|
|
125
|
-
expect(newCommand.stdout).toBe(commands[i].stdout);
|
|
126
|
-
expect(newCommand.stderr).toBe(commands[i].stderr);
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
});
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
const getSpawnOpts = require('./get-spawn-opts');
|
|
2
|
-
|
|
3
|
-
it('sets detached mode to false for Windows platform', () => {
|
|
4
|
-
expect(getSpawnOpts({ process: { platform: 'win32' } }).detached).toBe(false);
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
it('sets stdio to inherit when raw', () => {
|
|
8
|
-
expect(getSpawnOpts({ raw: true }).stdio).toBe('inherit');
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
it('merges FORCE_COLOR into env vars if color supported', () => {
|
|
12
|
-
const process = { env: { foo: 'bar' } };
|
|
13
|
-
expect(getSpawnOpts({ process, colorSupport: false }).env).toBeUndefined();
|
|
14
|
-
expect(getSpawnOpts({ process, colorSupport: { level: 1 } }).env).toEqual({
|
|
15
|
-
FORCE_COLOR: 1,
|
|
16
|
-
foo: 'bar'
|
|
17
|
-
});
|
|
18
|
-
});
|