concurrently 6.3.0 → 7.0.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.
Files changed (99) hide show
  1. package/README.md +82 -35
  2. package/dist/bin/concurrently.d.ts +2 -0
  3. package/dist/bin/concurrently.js +193 -0
  4. package/dist/bin/concurrently.spec.d.ts +1 -0
  5. package/dist/bin/epilogue.d.ts +1 -0
  6. package/dist/bin/epilogue.js +65 -0
  7. package/dist/src/command-parser/command-parser.d.ts +19 -0
  8. package/dist/src/command-parser/command-parser.js +2 -0
  9. package/dist/src/command-parser/expand-npm-shortcut.d.ts +8 -0
  10. package/{src → dist/src}/command-parser/expand-npm-shortcut.js +10 -3
  11. package/dist/src/command-parser/expand-npm-shortcut.spec.d.ts +1 -0
  12. package/dist/src/command-parser/expand-npm-wildcard.d.ts +13 -0
  13. package/dist/src/command-parser/expand-npm-wildcard.js +73 -0
  14. package/dist/src/command-parser/expand-npm-wildcard.spec.d.ts +1 -0
  15. package/dist/src/command-parser/strip-quotes.d.ts +10 -0
  16. package/{src → dist/src}/command-parser/strip-quotes.js +10 -4
  17. package/dist/src/command-parser/strip-quotes.spec.d.ts +1 -0
  18. package/dist/src/command.d.ts +101 -0
  19. package/dist/src/command.js +101 -0
  20. package/dist/src/command.spec.d.ts +1 -0
  21. package/dist/src/completion-listener.d.ts +37 -0
  22. package/dist/src/completion-listener.js +60 -0
  23. package/dist/src/completion-listener.spec.d.ts +1 -0
  24. package/dist/src/concurrently.d.ts +77 -0
  25. package/dist/src/concurrently.js +120 -0
  26. package/dist/src/concurrently.spec.d.ts +1 -0
  27. package/dist/src/defaults.d.ts +52 -0
  28. package/dist/src/defaults.js +58 -0
  29. package/dist/src/flow-control/flow-controller.d.ts +13 -0
  30. package/dist/src/flow-control/flow-controller.js +2 -0
  31. package/dist/src/flow-control/input-handler.d.ts +33 -0
  32. package/dist/src/flow-control/input-handler.js +73 -0
  33. package/dist/src/flow-control/input-handler.spec.d.ts +1 -0
  34. package/dist/src/flow-control/kill-on-signal.d.ts +17 -0
  35. package/{src → dist/src}/flow-control/kill-on-signal.js +13 -11
  36. package/dist/src/flow-control/kill-on-signal.spec.d.ts +1 -0
  37. package/dist/src/flow-control/kill-others.d.ts +18 -0
  38. package/dist/src/flow-control/kill-others.js +35 -0
  39. package/dist/src/flow-control/kill-others.spec.d.ts +1 -0
  40. package/dist/src/flow-control/log-error.d.ts +15 -0
  41. package/dist/src/flow-control/log-error.js +21 -0
  42. package/dist/src/flow-control/log-error.spec.d.ts +1 -0
  43. package/dist/src/flow-control/log-exit.d.ts +15 -0
  44. package/dist/src/flow-control/log-exit.js +19 -0
  45. package/dist/src/flow-control/log-exit.spec.d.ts +1 -0
  46. package/dist/src/flow-control/log-output.d.ts +15 -0
  47. package/{src → dist/src}/flow-control/log-output.js +13 -5
  48. package/dist/src/flow-control/log-output.spec.d.ts +1 -0
  49. package/dist/src/flow-control/log-timings.d.ts +27 -0
  50. package/dist/src/flow-control/log-timings.js +88 -0
  51. package/dist/src/flow-control/log-timings.spec.d.ts +1 -0
  52. package/dist/src/flow-control/restart-process.d.ts +22 -0
  53. package/dist/src/flow-control/restart-process.js +71 -0
  54. package/dist/src/flow-control/restart-process.spec.d.ts +1 -0
  55. package/dist/src/get-spawn-opts.d.ts +30 -0
  56. package/dist/src/get-spawn-opts.js +11 -0
  57. package/dist/src/get-spawn-opts.spec.d.ts +1 -0
  58. package/dist/src/index.d.ts +69 -0
  59. package/dist/src/index.js +69 -0
  60. package/dist/src/logger.d.ts +72 -0
  61. package/dist/src/logger.js +199 -0
  62. package/dist/src/logger.spec.d.ts +1 -0
  63. package/dist/src/output-writer.d.ts +19 -0
  64. package/dist/src/output-writer.js +69 -0
  65. package/dist/src/output-writer.spec.d.ts +1 -0
  66. package/index.js +6 -60
  67. package/index.mjs +9 -0
  68. package/package.json +37 -11
  69. package/bin/concurrently.js +0 -170
  70. package/bin/concurrently.spec.js +0 -365
  71. package/bin/epilogue.txt +0 -42
  72. package/src/command-parser/expand-npm-shortcut.spec.js +0 -36
  73. package/src/command-parser/expand-npm-wildcard.js +0 -43
  74. package/src/command-parser/expand-npm-wildcard.spec.js +0 -58
  75. package/src/command-parser/strip-quotes.spec.js +0 -20
  76. package/src/command.js +0 -63
  77. package/src/command.spec.js +0 -183
  78. package/src/completion-listener.js +0 -39
  79. package/src/completion-listener.spec.js +0 -88
  80. package/src/concurrently.js +0 -111
  81. package/src/concurrently.spec.js +0 -199
  82. package/src/defaults.js +0 -31
  83. package/src/flow-control/base-handler.js +0 -16
  84. package/src/flow-control/input-handler.js +0 -50
  85. package/src/flow-control/input-handler.spec.js +0 -113
  86. package/src/flow-control/kill-on-signal.spec.js +0 -79
  87. package/src/flow-control/kill-others.js +0 -38
  88. package/src/flow-control/kill-others.spec.js +0 -66
  89. package/src/flow-control/log-error.js +0 -18
  90. package/src/flow-control/log-error.spec.js +0 -40
  91. package/src/flow-control/log-exit.js +0 -11
  92. package/src/flow-control/log-exit.spec.js +0 -36
  93. package/src/flow-control/log-output.spec.js +0 -41
  94. package/src/flow-control/restart-process.js +0 -56
  95. package/src/flow-control/restart-process.spec.js +0 -131
  96. package/src/get-spawn-opts.js +0 -16
  97. package/src/get-spawn-opts.spec.js +0 -30
  98. package/src/logger.js +0 -115
  99. package/src/logger.spec.js +0 -195
@@ -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)).toMatchObject({ commands });
19
- });
20
-
21
- it('logs the close event of each command', () => {
22
- controller.handle(commands);
23
-
24
- commands[0].close.next({ exitCode: 0 });
25
- commands[1].close.next({ exitCode: '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)).toMatchObject({ 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,56 +0,0 @@
1
- const Rx = require('rxjs');
2
- const { defaultIfEmpty, delay, filter, mapTo, skip, take, takeWhile } = require('rxjs/operators');
3
-
4
- const defaults = require('../defaults');
5
- const BaseHandler = require('./base-handler');
6
-
7
- module.exports = class RestartProcess extends BaseHandler {
8
- constructor({ delay, tries, logger, scheduler }) {
9
- super({ logger });
10
-
11
- this.delay = +delay || defaults.restartDelay;
12
- this.tries = +tries || defaults.restartTries;
13
- this.tries = this.tries < 0 ? Infinity : this.tries;
14
- this.scheduler = scheduler;
15
- }
16
-
17
- handle(commands) {
18
- if (this.tries === 0) {
19
- return { commands };
20
- }
21
-
22
- commands.map(command => command.close.pipe(
23
- take(this.tries),
24
- takeWhile(({ exitCode }) => exitCode !== 0)
25
- )).map((failure, index) => Rx.merge(
26
- // Delay the emission (so that the restarts happen on time),
27
- // explicitly telling the subscriber that a restart is needed
28
- failure.pipe(delay(this.delay, this.scheduler), mapTo(true)),
29
- // Skip the first N emissions (as these would be duplicates of the above),
30
- // meaning it will be empty because of success, or failed all N times,
31
- // and no more restarts should be attempted.
32
- failure.pipe(skip(this.tries), defaultIfEmpty(false))
33
- ).subscribe(restart => {
34
- const command = commands[index];
35
- if (restart) {
36
- this.logger.logCommandEvent(`${command.command} restarted`, command);
37
- command.start();
38
- }
39
- }));
40
-
41
- return {
42
- commands: commands.map(command => {
43
- const closeStream = command.close.pipe(filter(({ exitCode }, emission) => {
44
- // We let all success codes pass, and failures only after restarting won't happen again
45
- return exitCode === 0 || emission >= this.tries;
46
- }));
47
-
48
- return new Proxy(command, {
49
- get(target, prop) {
50
- return prop === 'close' ? closeStream : target[prop];
51
- }
52
- });
53
- })
54
- };
55
- }
56
- };
@@ -1,131 +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({ exitCode: 0 });
29
- commands[1].close.next({ exitCode: 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({ exitCode: 1 });
41
- commands[1].close.next({ exitCode: 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({ exitCode: 1 });
58
- commands[0].close.next({ exitCode: 'SIGTERM' });
59
- commands[0].close.next({ exitCode: 'SIGTERM' });
60
- commands[1].close.next({ exitCode: 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.todo('restart processes forever, if tries is negative');
73
-
74
- it('restarts processes until they succeed', () => {
75
- controller.handle(commands);
76
-
77
- commands[0].close.next({ exitCode: 1 });
78
- commands[0].close.next({ exitCode: 0 });
79
- commands[1].close.next({ exitCode: 0 });
80
-
81
- scheduler.flush();
82
-
83
- expect(logger.logCommandEvent).toHaveBeenCalledTimes(1);
84
- expect(logger.logCommandEvent).toHaveBeenCalledWith(
85
- `${commands[0].command} restarted`,
86
- commands[0]
87
- );
88
- expect(commands[0].start).toHaveBeenCalledTimes(1);
89
- });
90
-
91
- describe('returned commands', () => {
92
- it('are the same if 0 tries are to be attempted', () => {
93
- controller = new RestartProcess({ logger, scheduler });
94
- expect(controller.handle(commands)).toMatchObject({ commands });
95
- });
96
-
97
- it('are not the same, but with same length if 1+ tries are to be attempted', () => {
98
- const { commands: newCommands } = controller.handle(commands);
99
- expect(newCommands).not.toBe(commands);
100
- expect(newCommands).toHaveLength(commands.length);
101
- });
102
-
103
- it('skip close events followed by restarts', () => {
104
- const { commands: newCommands } = controller.handle(commands);
105
-
106
- const callback = jest.fn();
107
- newCommands[0].close.subscribe(callback);
108
- newCommands[1].close.subscribe(callback);
109
-
110
- commands[0].close.next({ exitCode: 1 });
111
- commands[0].close.next({ exitCode: 1 });
112
- commands[0].close.next({ exitCode: 1 });
113
- commands[1].close.next({ exitCode: 1 });
114
- commands[1].close.next({ exitCode: 0 });
115
-
116
- scheduler.flush();
117
-
118
- // 1 failure from commands[0], 1 success from commands[1]
119
- expect(callback).toHaveBeenCalledTimes(2);
120
- });
121
-
122
- it('keep non-close streams from original commands', () => {
123
- const { commands: newCommands } = controller.handle(commands);
124
- newCommands.forEach((newCommand, i) => {
125
- expect(newCommand.close).not.toBe(commands[i].close);
126
- expect(newCommand.error).toBe(commands[i].error);
127
- expect(newCommand.stdout).toBe(commands[i].stdout);
128
- expect(newCommand.stderr).toBe(commands[i].stderr);
129
- });
130
- });
131
- });
@@ -1,16 +0,0 @@
1
- const supportsColor = require('supports-color');
2
-
3
- module.exports = ({
4
- colorSupport = supportsColor.stdout,
5
- cwd,
6
- process = global.process,
7
- raw = false,
8
- env = {},
9
- }) => Object.assign(
10
- {
11
- cwd: cwd || process.cwd(),
12
- },
13
- raw && { stdio: 'inherit' },
14
- /^win/.test(process.platform) && { detached: false },
15
- { env: Object.assign(colorSupport ? { FORCE_COLOR: colorSupport.level } : {}, process.env, env) }
16
- );
@@ -1,30 +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', cwd: jest.fn() } }).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' }, cwd: jest.fn() };
13
- expect(getSpawnOpts({ process, colorSupport: false }).env).toEqual(process.env);
14
- expect(getSpawnOpts({ process, colorSupport: { level: 1 } }).env).toEqual({
15
- FORCE_COLOR: 1,
16
- foo: 'bar'
17
- });
18
- });
19
-
20
- it('sets default cwd to process.cwd()', () => {
21
- const process = { cwd: jest.fn().mockReturnValue('process-cwd') };
22
- expect(getSpawnOpts({
23
- process,
24
- }).cwd).toBe('process-cwd');
25
- });
26
-
27
- it('overrides default cwd', () => {
28
- const cwd = 'foobar';
29
- expect(getSpawnOpts({ cwd }).cwd).toBe(cwd);
30
- });
package/src/logger.js DELETED
@@ -1,115 +0,0 @@
1
- const chalk = require('chalk');
2
- const _ = require('lodash');
3
- const formatDate = require('date-fns/format');
4
-
5
- const defaults = require('./defaults');
6
-
7
- module.exports = class Logger {
8
- constructor({ outputStream, prefixFormat, prefixLength, raw, timestampFormat }) {
9
- this.raw = raw;
10
- this.outputStream = outputStream;
11
- this.prefixFormat = prefixFormat;
12
- this.prefixLength = prefixLength || defaults.prefixLength;
13
- this.timestampFormat = timestampFormat || defaults.timestampFormat;
14
- }
15
-
16
- shortenText(text) {
17
- if (!text || text.length <= this.prefixLength) {
18
- return text;
19
- }
20
-
21
- const ellipsis = '..';
22
- const prefixLength = this.prefixLength - ellipsis.length;
23
- const endLength = Math.floor(prefixLength / 2);
24
- const beginningLength = prefixLength - endLength;
25
-
26
- const beginnning = text.substring(0, beginningLength);
27
- const end = text.substring(text.length - endLength, text.length);
28
- return beginnning + ellipsis + end;
29
- }
30
-
31
- getPrefixesFor(command) {
32
- return {
33
- none: '',
34
- pid: command.pid,
35
- index: command.index,
36
- name: command.name,
37
- command: this.shortenText(command.command),
38
- time: formatDate(Date.now(), this.timestampFormat)
39
- };
40
- }
41
-
42
- getPrefix(command) {
43
- const prefix = this.prefixFormat || (command.name ? 'name' : 'index');
44
- if (prefix === 'none') {
45
- return '';
46
- }
47
-
48
- const prefixes = this.getPrefixesFor(command);
49
- if (Object.keys(prefixes).includes(prefix)) {
50
- return `[${prefixes[prefix]}]`;
51
- }
52
-
53
- return _.reduce(prefixes, (prev, val, key) => {
54
- const keyRegex = new RegExp(_.escapeRegExp(`{${key}}`), 'g');
55
- return prev.replace(keyRegex, val);
56
- }, prefix);
57
- }
58
-
59
- colorText(command, text) {
60
- let color;
61
- if (command.prefixColor && command.prefixColor.startsWith('#')) {
62
- color = chalk.hex(command.prefixColor);
63
- } else {
64
- const defaultColor = _.get(chalk, defaults.prefixColors, chalk.reset);
65
- color = _.get(chalk, command.prefixColor, defaultColor);
66
- }
67
- return color(text);
68
- }
69
-
70
- logCommandEvent(text, command) {
71
- if (this.raw) {
72
- return;
73
- }
74
-
75
- this.logCommandText(chalk.reset(text) + '\n', command);
76
- }
77
-
78
- logCommandText(text, command) {
79
- const prefix = this.colorText(command, this.getPrefix(command));
80
- return this.log(prefix + (prefix ? ' ' : ''), text);
81
- }
82
-
83
- logGlobalEvent(text) {
84
- if (this.raw) {
85
- return;
86
- }
87
-
88
- this.log(chalk.reset('-->') + ' ', chalk.reset(text) + '\n');
89
- }
90
-
91
- log(prefix, text) {
92
- if (this.raw) {
93
- return this.outputStream.write(text);
94
- }
95
-
96
- // #70 - replace some ANSI code that would impact clearing lines
97
- text = text.replace(/\u2026/g, '...');
98
-
99
- const lines = text.split('\n').map((line, index, lines) => {
100
- // First line will write prefix only if we finished the last write with a LF.
101
- // Last line won't write prefix because it should be empty.
102
- if (index === 0 || index === lines.length - 1) {
103
- return line;
104
- }
105
- return prefix + line;
106
- });
107
-
108
- if (!this.lastChar || this.lastChar === '\n') {
109
- this.outputStream.write(prefix);
110
- }
111
-
112
- this.lastChar = text[text.length - 1];
113
- this.outputStream.write(lines.join('\n'));
114
- }
115
- };
@@ -1,195 +0,0 @@
1
- const { Writable } = require('stream');
2
- const chalk = require('chalk');
3
- const { createMockInstance } = require('jest-create-mock-instance');
4
- const Logger = require('./logger');
5
-
6
- let outputStream;
7
- beforeEach(() => {
8
- outputStream = createMockInstance(Writable);
9
- // Force chalk to use colours, otherwise tests may pass when they were supposed to be failing.
10
- chalk.level = 3;
11
- });
12
-
13
- const createLogger = options => {
14
- const logger = new Logger(Object.assign({ outputStream }, options));
15
- jest.spyOn(logger, 'log');
16
- return logger;
17
- };
18
-
19
- describe('#log()', () => {
20
- it('writes prefix + text to the output stream', () => {
21
- const logger = new Logger({ outputStream });
22
- logger.log('foo', 'bar');
23
-
24
- expect(outputStream.write).toHaveBeenCalledTimes(2);
25
- expect(outputStream.write).toHaveBeenCalledWith('foo');
26
- expect(outputStream.write).toHaveBeenCalledWith('bar');
27
- });
28
-
29
- it('writes multiple lines of text with prefix on each', () => {
30
- const logger = new Logger({ outputStream });
31
- logger.log('foo', 'bar\nbaz\n');
32
-
33
- expect(outputStream.write).toHaveBeenCalledTimes(2);
34
- expect(outputStream.write).toHaveBeenCalledWith('foo');
35
- expect(outputStream.write).toHaveBeenCalledWith('bar\nfoobaz\n');
36
- });
37
-
38
- it('does not prepend prefix if last call did not finish with a LF', () => {
39
- const logger = new Logger({ outputStream });
40
- logger.log('foo', 'bar');
41
- outputStream.write.mockClear();
42
- logger.log('foo', 'baz');
43
-
44
- expect(outputStream.write).toHaveBeenCalledTimes(1);
45
- expect(outputStream.write).toHaveBeenCalledWith('baz');
46
- });
47
-
48
- it('does not prepend prefix or handle text if logger is in raw mode', () => {
49
- const logger = new Logger({ outputStream, raw: true });
50
- logger.log('foo', 'bar\nbaz\n');
51
-
52
- expect(outputStream.write).toHaveBeenCalledTimes(1);
53
- expect(outputStream.write).toHaveBeenCalledWith('bar\nbaz\n');
54
- });
55
- });
56
-
57
- describe('#logGlobalEvent()', () => {
58
- it('does nothing if in raw mode', () => {
59
- const logger = createLogger({ raw: true });
60
- logger.logGlobalEvent('foo');
61
-
62
- expect(logger.log).not.toHaveBeenCalled();
63
- });
64
-
65
- it('logs in gray dim style with arrow prefix', () => {
66
- const logger = createLogger();
67
- logger.logGlobalEvent('foo');
68
-
69
- expect(logger.log).toHaveBeenCalledWith(
70
- chalk.reset('-->') + ' ',
71
- chalk.reset('foo') + '\n'
72
- );
73
- });
74
- });
75
-
76
- describe('#logCommandText()', () => {
77
- it('logs with name if no prefixFormat is set', () => {
78
- const logger = createLogger();
79
- logger.logCommandText('foo', { name: 'bla' });
80
-
81
- expect(logger.log).toHaveBeenCalledWith(chalk.reset('[bla]') + ' ', 'foo');
82
- });
83
-
84
- it('logs with index if no prefixFormat is set, and command has no name', () => {
85
- const logger = createLogger();
86
- logger.logCommandText('foo', { index: 2 });
87
-
88
- expect(logger.log).toHaveBeenCalledWith(chalk.reset('[2]') + ' ', 'foo');
89
- });
90
-
91
- it('logs with prefixFormat set to pid', () => {
92
- const logger = createLogger({ prefixFormat: 'pid' });
93
- logger.logCommandText('foo', {
94
- pid: 123,
95
- info: {}
96
- });
97
-
98
- expect(logger.log).toHaveBeenCalledWith(chalk.reset('[123]') + ' ', 'foo');
99
- });
100
-
101
- it('logs with prefixFormat set to name', () => {
102
- const logger = createLogger({ prefixFormat: 'name' });
103
- logger.logCommandText('foo', { name: 'bar' });
104
-
105
- expect(logger.log).toHaveBeenCalledWith(chalk.reset('[bar]') + ' ', 'foo');
106
- });
107
-
108
- it('logs with prefixFormat set to index', () => {
109
- const logger = createLogger({ prefixFormat: 'index' });
110
- logger.logCommandText('foo', { index: 3 });
111
-
112
- expect(logger.log).toHaveBeenCalledWith(chalk.reset('[3]') + ' ', 'foo');
113
- });
114
-
115
- it('logs with prefixFormat set to time (with timestampFormat)', () => {
116
- const logger = createLogger({ prefixFormat: 'time', timestampFormat: 'yyyy' });
117
- logger.logCommandText('foo', {});
118
-
119
- const year = new Date().getFullYear();
120
- expect(logger.log).toHaveBeenCalledWith(chalk.reset(`[${year}]`) + ' ', 'foo');
121
- });
122
-
123
- it('logs with templated prefixFormat', () => {
124
- const logger = createLogger({ prefixFormat: '{index}-{name}' });
125
- logger.logCommandText('foo', { index: 0, name: 'bar' });
126
-
127
- expect(logger.log).toHaveBeenCalledWith(chalk.reset('0-bar') + ' ', 'foo');
128
- });
129
-
130
- it('does not strip spaces from beginning or end of prefixFormat', () => {
131
- const logger = createLogger({ prefixFormat: ' {index}-{name} ' });
132
- logger.logCommandText('foo', { index: 0, name: 'bar' });
133
-
134
- expect(logger.log).toHaveBeenCalledWith(chalk.reset(' 0-bar ') + ' ', 'foo');
135
- });
136
-
137
- it('logs with no prefix', () => {
138
- const logger = createLogger({ prefixFormat: 'none' });
139
- logger.logCommandText('foo', { command: 'echo foo' });
140
-
141
- expect(logger.log).toHaveBeenCalledWith(chalk.reset(''), 'foo');
142
- });
143
-
144
- it('logs prefix using command line itself', () => {
145
- const logger = createLogger({ prefixFormat: 'command' });
146
- logger.logCommandText('foo', { command: 'echo foo' });
147
-
148
- expect(logger.log).toHaveBeenCalledWith(chalk.reset('[echo foo]') + ' ', 'foo');
149
- });
150
-
151
- it('logs prefix using command line itself, capped at prefixLength bytes', () => {
152
- const logger = createLogger({ prefixFormat: 'command', prefixLength: 6 });
153
- logger.logCommandText('foo', { command: 'echo foo' });
154
-
155
- expect(logger.log).toHaveBeenCalledWith(chalk.reset('[ec..oo]') + ' ', 'foo');
156
- });
157
-
158
- it('logs prefix using prefixColor from command', () => {
159
- const logger = createLogger();
160
- logger.logCommandText('foo', { prefixColor: 'blue', index: 1 });
161
-
162
- expect(logger.log).toHaveBeenCalledWith(chalk.blue('[1]') + ' ', 'foo');
163
- });
164
-
165
- it('logs prefix in gray dim if prefixColor from command does not exist', () => {
166
- const logger = createLogger();
167
- logger.logCommandText('foo', { prefixColor: 'blue.fake', index: 1 });
168
-
169
- expect(logger.log).toHaveBeenCalledWith(chalk.reset('[1]') + ' ', 'foo');
170
- });
171
-
172
- it('logs prefix using prefixColor from command if prefixColor is a hex value', () => {
173
- const logger = createLogger();
174
- const prefixColor = '#32bd8a';
175
- logger.logCommandText('foo', {prefixColor, index: 1});
176
-
177
- expect(logger.log).toHaveBeenCalledWith(chalk.hex(prefixColor)('[1]') + ' ', 'foo');
178
- });
179
- });
180
-
181
- describe('#logCommandEvent()', () => {
182
- it('does nothing if in raw mode', () => {
183
- const logger = createLogger({ raw: true });
184
- logger.logCommandEvent('foo');
185
-
186
- expect(logger.log).not.toHaveBeenCalled();
187
- });
188
-
189
- it('logs text in gray dim', () => {
190
- const logger = createLogger();
191
- logger.logCommandEvent('foo', { index: 1 });
192
-
193
- expect(logger.log).toHaveBeenCalledWith(chalk.reset('[1]') + ' ', chalk.reset('foo') + '\n');
194
- });
195
- });