concurrently 6.5.1 → 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 (100) hide show
  1. package/README.md +58 -19
  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/{src → dist/src}/command.js +53 -29
  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/{src → dist/src}/logger.js +77 -58
  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 -68
  67. package/index.mjs +9 -0
  68. package/package.json +37 -11
  69. package/bin/concurrently.js +0 -186
  70. package/bin/concurrently.spec.js +0 -428
  71. package/bin/epilogue.txt +0 -46
  72. package/src/command-parser/expand-npm-shortcut.spec.js +0 -36
  73. package/src/command-parser/expand-npm-wildcard.js +0 -52
  74. package/src/command-parser/expand-npm-wildcard.spec.js +0 -104
  75. package/src/command-parser/strip-quotes.spec.js +0 -20
  76. package/src/command.spec.js +0 -275
  77. package/src/completion-listener.js +0 -39
  78. package/src/completion-listener.spec.js +0 -89
  79. package/src/concurrently.js +0 -116
  80. package/src/concurrently.spec.js +0 -199
  81. package/src/defaults.js +0 -35
  82. package/src/flow-control/base-handler.js +0 -16
  83. package/src/flow-control/base-handler.spec.js +0 -22
  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/log-timings.js +0 -64
  95. package/src/flow-control/log-timings.spec.js +0 -137
  96. package/src/flow-control/restart-process.js +0 -56
  97. package/src/flow-control/restart-process.spec.js +0 -139
  98. package/src/get-spawn-opts.js +0 -16
  99. package/src/get-spawn-opts.spec.js +0 -30
  100. package/src/logger.spec.js +0 -318
package/package.json CHANGED
@@ -1,16 +1,27 @@
1
1
  {
2
2
  "name": "concurrently",
3
- "version": "6.5.1",
3
+ "version": "7.0.0",
4
4
  "description": "Run commands concurrently",
5
5
  "main": "index.js",
6
+ "types": "dist/src/index.d.ts",
7
+ "type": "commonjs",
6
8
  "bin": {
7
- "concurrently": "./bin/concurrently.js"
9
+ "concurrently": "./dist/bin/concurrently.js"
8
10
  },
9
11
  "engines": {
10
- "node": ">=10.0.0"
12
+ "node": "^12.20.0 || ^14.13.0 || >=16.0.0"
13
+ },
14
+ "exports": {
15
+ "import": "./index.mjs",
16
+ "require": "./index.js",
17
+ "default": "./index.js"
11
18
  },
12
19
  "scripts": {
13
- "lint": "eslint . --ignore-path .gitignore",
20
+ "build": "tsc --build",
21
+ "postbuild": "chmod +x dist/bin/concurrently.js",
22
+ "clean": "tsc --build --clean",
23
+ "lint": "eslint . --ext js,ts --ignore-path .gitignore",
24
+ "prepublishOnly": "npm run build",
14
25
  "report-coverage": "cat coverage/lcov.info | coveralls",
15
26
  "test": "jest"
16
27
  },
@@ -39,27 +50,42 @@
39
50
  "yargs": "^16.2.0"
40
51
  },
41
52
  "devDependencies": {
53
+ "@types/jest": "^27.0.3",
54
+ "@types/lodash": "^4.14.178",
55
+ "@types/node": "^17.0.0",
56
+ "@types/supports-color": "^8.1.1",
57
+ "@typescript-eslint/eslint-plugin": "^5.8.1",
58
+ "@typescript-eslint/parser": "^5.8.1",
42
59
  "coveralls": "^3.1.0",
43
60
  "eslint": "^7.17.0",
44
61
  "jest": "^26.6.3",
45
- "jest-create-mock-instance": "^1.1.0"
62
+ "jest-create-mock-instance": "^1.1.0",
63
+ "ts-jest": "^26.5.6",
64
+ "ts-node": "^10.4.0",
65
+ "typescript": "^4.5.4"
46
66
  },
47
67
  "files": [
48
- "bin",
49
- "!**/fixtures",
68
+ "dist",
50
69
  "index.js",
51
- "src",
52
- "!*.spec.js"
70
+ "index.mjs",
71
+ "!**/fixtures",
72
+ "!**/*.spec.js"
53
73
  ],
54
74
  "jest": {
75
+ "preset": "ts-jest",
55
76
  "collectCoverage": true,
56
77
  "collectCoverageFrom": [
57
- "src/**/*.js"
78
+ "src/**/*.ts",
79
+ "!src/index.ts"
58
80
  ],
59
81
  "coveragePathIgnorePatterns": [
60
82
  "/fixtures/",
61
83
  "/node_modules/"
62
84
  ],
63
- "testEnvironment": "node"
85
+ "testEnvironment": "node",
86
+ "testPathIgnorePatterns": [
87
+ "/node_modules/",
88
+ "/dist"
89
+ ]
64
90
  }
65
91
  }
@@ -1,186 +0,0 @@
1
- #!/usr/bin/env node
2
- const fs = require('fs');
3
- const yargs = require('yargs');
4
- const defaults = require('../src/defaults');
5
- const concurrently = require('../index');
6
-
7
- const args = yargs
8
- .usage('$0 [options] <command ...>')
9
- .help('h')
10
- .alias('h', 'help')
11
- .version('v', require('../package.json').version)
12
- .alias('v', 'V')
13
- .alias('v', 'version')
14
- // TODO: Add some tests for this.
15
- .env('CONCURRENTLY')
16
- .options({
17
- // General
18
- 'm': {
19
- alias: 'max-processes',
20
- describe:
21
- 'How many processes should run at once.\n' +
22
- 'New processes only spawn after all restart tries of a process.',
23
- type: 'number'
24
- },
25
- 'n': {
26
- alias: 'names',
27
- describe:
28
- 'List of custom names to be used in prefix template.\n' +
29
- 'Example names: "main,browser,server"',
30
- type: 'string'
31
- },
32
- 'name-separator': {
33
- describe:
34
- 'The character to split <names> on. Example usage:\n' +
35
- 'concurrently -n "styles|scripts|server" --name-separator "|"',
36
- default: defaults.nameSeparator,
37
- },
38
- 's': {
39
- alias: 'success',
40
- describe:
41
- 'Return exit code of zero or one based on the success or failure ' +
42
- 'of the "first" child to terminate, the "last child", or succeed ' +
43
- 'only if "all" child processes succeed.',
44
- choices: ['first', 'last', 'all'],
45
- default: defaults.success
46
- },
47
- 'r': {
48
- alias: 'raw',
49
- describe:
50
- 'Output only raw output of processes, disables prettifying ' +
51
- 'and concurrently coloring.',
52
- type: 'boolean'
53
- },
54
- // This one is provided for free. Chalk reads this itself and removes colours.
55
- // https://www.npmjs.com/package/chalk#chalksupportscolor
56
- 'no-color': {
57
- describe: 'Disables colors from logging',
58
- type: 'boolean'
59
- },
60
- 'hide': {
61
- describe:
62
- 'Comma-separated list of processes to hide the output.\n' +
63
- 'The processes can be identified by their name or index.',
64
- default: defaults.hide,
65
- type: 'string'
66
- },
67
- 'timings': {
68
- describe: 'Show timing information for all processes',
69
- type: 'boolean',
70
- default: defaults.timings
71
- },
72
-
73
- // Kill others
74
- 'k': {
75
- alias: 'kill-others',
76
- describe: 'kill other processes if one exits or dies',
77
- type: 'boolean'
78
- },
79
- 'kill-others-on-fail': {
80
- describe: 'kill other processes if one exits with non zero status code',
81
- type: 'boolean'
82
- },
83
-
84
- // Prefix
85
- 'p': {
86
- alias: 'prefix',
87
- describe:
88
- 'Prefix used in logging for each process.\n' +
89
- 'Possible values: index, pid, time, command, name, none, or a template. ' +
90
- 'Example template: "{time}-{pid}"',
91
- defaultDescription: 'index or name (when --names is set)',
92
- type: 'string'
93
- },
94
- 'c': {
95
- alias: 'prefix-colors',
96
- describe:
97
- 'Comma-separated list of chalk colors to use on prefixes. ' +
98
- 'If there are more commands than colors, the last color will be repeated.\n' +
99
- '- Available modifiers: reset, bold, dim, italic, underline, inverse, hidden, strikethrough\n' +
100
- '- Available colors: black, red, green, yellow, blue, magenta, cyan, white, gray \n' +
101
- 'or any hex values for colors, eg #23de43\n' +
102
- '- Available background colors: bgBlack, bgRed, bgGreen, bgYellow, bgBlue, bgMagenta, bgCyan, bgWhite\n' +
103
- 'See https://www.npmjs.com/package/chalk for more information.',
104
- default: defaults.prefixColors,
105
- type: 'string'
106
- },
107
- 'l': {
108
- alias: 'prefix-length',
109
- describe:
110
- 'Limit how many characters of the command is displayed in prefix. ' +
111
- 'The option can be used to shorten the prefix when it is set to "command"',
112
- default: defaults.prefixLength,
113
- type: 'number'
114
- },
115
- 't': {
116
- alias: 'timestamp-format',
117
- describe: 'Specify the timestamp in moment/date-fns format.',
118
- default: defaults.timestampFormat,
119
- type: 'string'
120
- },
121
-
122
- // Restarting
123
- 'restart-tries': {
124
- describe:
125
- 'How many times a process that died should restart.\n' +
126
- 'Negative numbers will make the process restart forever.',
127
- default: defaults.restartTries,
128
- type: 'number'
129
- },
130
- 'restart-after': {
131
- describe: 'Delay time to respawn the process, in milliseconds.',
132
- default: defaults.restartDelay,
133
- type: 'number'
134
- },
135
-
136
- // Input
137
- 'i': {
138
- alias: 'handle-input',
139
- describe:
140
- 'Whether input should be forwarded to the child processes. ' +
141
- 'See examples for more information.',
142
- type: 'boolean'
143
- },
144
- 'default-input-target': {
145
- default: defaults.defaultInputTarget,
146
- describe:
147
- 'Identifier for child process to which input on stdin ' +
148
- 'should be sent if not specified at start of input.\n' +
149
- 'Can be either the index or the name of the process.'
150
- }
151
- })
152
- .group(['m', 'n', 'name-separator', 'raw', 's', 'no-color', 'hide', 'timings'], 'General')
153
- .group(['p', 'c', 'l', 't'], 'Prefix styling')
154
- .group(['i', 'default-input-target'], 'Input handling')
155
- .group(['k', 'kill-others-on-fail'], 'Killing other processes')
156
- .group(['restart-tries', 'restart-after'], 'Restarting')
157
- // Too much text to write as JS strings, .txt file is better
158
- .epilogue(fs.readFileSync(__dirname + '/epilogue.txt', { encoding: 'utf8' }))
159
- .argv;
160
-
161
- const names = (args.names || '').split(args.nameSeparator);
162
-
163
- concurrently(args._.map((command, index) => ({
164
- command,
165
- name: names[index]
166
- })), {
167
- handleInput: args.handleInput,
168
- defaultInputTarget: args.defaultInputTarget,
169
- killOthers: args.killOthers
170
- ? ['success', 'failure']
171
- : (args.killOthersOnFail ? ['failure'] : []),
172
- maxProcesses: args.maxProcesses,
173
- raw: args.raw,
174
- hide: args.hide.split(','),
175
- prefix: args.prefix,
176
- prefixColors: args.prefixColors.split(','),
177
- prefixLength: args.prefixLength,
178
- restartDelay: args.restartAfter,
179
- restartTries: args.restartTries,
180
- successCondition: args.success,
181
- timestampFormat: args.timestampFormat,
182
- timings: args.timings
183
- }).then(
184
- () => process.exit(0),
185
- () => process.exit(1)
186
- );
@@ -1,428 +0,0 @@
1
- const readline = require('readline');
2
- const _ = require('lodash');
3
- const Rx = require('rxjs');
4
- const { buffer, map } = require('rxjs/operators');
5
- const spawn = require('spawn-command');
6
-
7
- const isWindows = process.platform === 'win32';
8
- const createKillMessage = prefix => new RegExp(
9
- _.escapeRegExp(prefix) +
10
- ' exited with code ' +
11
- (isWindows ? 1 : '(SIGTERM|143)')
12
- );
13
-
14
- const run = args => {
15
- const child = spawn('node ./concurrently.js ' + args, {
16
- cwd: __dirname,
17
- env: Object.assign({}, process.env, {
18
- // When upgrading from jest 23 -> 24, colors started printing in the test output.
19
- // They are forcibly disabled here
20
- FORCE_COLOR: 0
21
- }),
22
- });
23
-
24
- const stdout = readline.createInterface({
25
- input: child.stdout,
26
- output: null
27
- });
28
-
29
- const stderr = readline.createInterface({
30
- input: child.stderr,
31
- output: null
32
- });
33
-
34
- const close = Rx.fromEvent(child, 'close');
35
- const log = Rx.merge(
36
- Rx.fromEvent(stdout, 'line'),
37
- Rx.fromEvent(stderr, 'line')
38
- ).pipe(map(data => data.toString()));
39
-
40
- return {
41
- close,
42
- log,
43
- stdin: child.stdin,
44
- pid: child.pid
45
- };
46
- };
47
-
48
- it('has help command', done => {
49
- run('--help').close.subscribe(event => {
50
- expect(event[0]).toBe(0);
51
- done();
52
- }, done);
53
- });
54
-
55
- it('has version command', done => {
56
- Rx.combineLatest(
57
- run('--version').close,
58
- run('-V').close,
59
- run('-v').close
60
- ).subscribe(events => {
61
- expect(events[0][0]).toBe(0);
62
- expect(events[1][0]).toBe(0);
63
- expect(events[2][0]).toBe(0);
64
- done();
65
- }, done);
66
- });
67
-
68
- describe('exiting conditions', () => {
69
- it('is of success by default when running successful commands', done => {
70
- run('"echo foo" "echo bar"')
71
- .close
72
- .subscribe(exit => {
73
- expect(exit[0]).toBe(0);
74
- done();
75
- }, done);
76
- });
77
-
78
- it('is of failure by default when one of the command fails', done => {
79
- run('"echo foo" "exit 1"')
80
- .close
81
- .subscribe(exit => {
82
- expect(exit[0]).toBeGreaterThan(0);
83
- done();
84
- }, done);
85
- });
86
-
87
- it('is of success when --success=first and first command to exit succeeds', done => {
88
- run('--success=first "echo foo" "sleep 0.5 && exit 1"')
89
- .close
90
- .subscribe(exit => {
91
- expect(exit[0]).toBe(0);
92
- done();
93
- }, done);
94
- });
95
-
96
- it('is of failure when --success=first and first command to exit fails', done => {
97
- run('--success=first "exit 1" "sleep 0.5 && echo foo"')
98
- .close
99
- .subscribe(exit => {
100
- expect(exit[0]).toBeGreaterThan(0);
101
- done();
102
- }, done);
103
- });
104
-
105
- it('is of success when --success=last and last command to exit succeeds', done => {
106
- run('--success=last "exit 1" "sleep 0.5 && echo foo"')
107
- .close
108
- .subscribe(exit => {
109
- expect(exit[0]).toBe(0);
110
- done();
111
- }, done);
112
- });
113
-
114
- it('is of failure when --success=last and last command to exit fails', done => {
115
- run('--success=last "echo foo" "sleep 0.5 && exit 1"')
116
- .close
117
- .subscribe(exit => {
118
- expect(exit[0]).toBeGreaterThan(0);
119
- done();
120
- }, done);
121
- });
122
-
123
- it.skip('is of success when a SIGINT is sent', done => {
124
- const child = run('"node fixtures/read-echo.js"');
125
- child.close.subscribe(exit => {
126
- // TODO This is null within Node, but should be 0 outside (eg from real terminal)
127
- expect(exit[0]).toBe(0);
128
- done();
129
- }, done);
130
-
131
- process.kill(child.pid, 'SIGINT');
132
- });
133
-
134
- it('is aliased to -s', done => {
135
- run('-s last "exit 1" "sleep 0.5 && echo foo"')
136
- .close
137
- .subscribe(exit => {
138
- expect(exit[0]).toBe(0);
139
- done();
140
- }, done);
141
- });
142
- });
143
-
144
- describe('--raw', () => {
145
- it('is aliased to -r', done => {
146
- const child = run('-r "echo foo" "echo bar"');
147
- child.log.pipe(buffer(child.close)).subscribe(lines => {
148
- expect(lines).toHaveLength(2);
149
- expect(lines).toContainEqual(expect.stringContaining('foo'));
150
- expect(lines).toContainEqual(expect.stringContaining('bar'));
151
- done();
152
- }, done);
153
- });
154
-
155
- it('does not log any extra output', done => {
156
- const child = run('--raw "echo foo" "echo bar"');
157
- child.log.pipe(buffer(child.close)).subscribe(lines => {
158
- expect(lines).toHaveLength(2);
159
- expect(lines).toContainEqual(expect.stringContaining('foo'));
160
- expect(lines).toContainEqual(expect.stringContaining('bar'));
161
- done();
162
- }, done);
163
- });
164
- });
165
-
166
- describe('--hide', () => {
167
- it('hides the output of a process by its index', done => {
168
- const child = run('--hide 1 "echo foo" "echo bar"');
169
- child.log.pipe(buffer(child.close)).subscribe(lines => {
170
- expect(lines).toContainEqual(expect.stringContaining('foo'));
171
- expect(lines).not.toContainEqual(expect.stringContaining('bar'));
172
- done();
173
- }, done);
174
- });
175
-
176
- it('hides the output of a process by its name', done => {
177
- const child = run('-n foo,bar --hide bar "echo foo" "echo bar"');
178
- child.log.pipe(buffer(child.close)).subscribe(lines => {
179
- expect(lines).toContainEqual(expect.stringContaining('foo'));
180
- expect(lines).not.toContainEqual(expect.stringContaining('bar'));
181
- done();
182
- }, done);
183
- });
184
- });
185
-
186
- describe('--names', () => {
187
- it('is aliased to -n', done => {
188
- const child = run('-n foo,bar "echo foo" "echo bar"');
189
- child.log.pipe(buffer(child.close)).subscribe(lines => {
190
- expect(lines).toContainEqual(expect.stringContaining('[foo] foo'));
191
- expect(lines).toContainEqual(expect.stringContaining('[bar] bar'));
192
- done();
193
- }, done);
194
- });
195
-
196
- it('prefixes with names', done => {
197
- const child = run('--names foo,bar "echo foo" "echo bar"');
198
- child.log.pipe(buffer(child.close)).subscribe(lines => {
199
- expect(lines).toContainEqual(expect.stringContaining('[foo] foo'));
200
- expect(lines).toContainEqual(expect.stringContaining('[bar] bar'));
201
- done();
202
- }, done);
203
- });
204
-
205
- it('is split using --name-separator arg', done => {
206
- const child = run('--names "foo|bar" --name-separator "|" "echo foo" "echo bar"');
207
- child.log.pipe(buffer(child.close)).subscribe(lines => {
208
- expect(lines).toContainEqual(expect.stringContaining('[foo] foo'));
209
- expect(lines).toContainEqual(expect.stringContaining('[bar] bar'));
210
- done();
211
- }, done);
212
- });
213
- });
214
-
215
- describe('--prefix', () => {
216
- it('is aliased to -p', done => {
217
- const child = run('-p command "echo foo" "echo bar"');
218
- child.log.pipe(buffer(child.close)).subscribe(lines => {
219
- expect(lines).toContainEqual(expect.stringContaining('[echo foo] foo'));
220
- expect(lines).toContainEqual(expect.stringContaining('[echo bar] bar'));
221
- done();
222
- }, done);
223
- });
224
-
225
- it('specifies custom prefix', done => {
226
- const child = run('--prefix command "echo foo" "echo bar"');
227
- child.log.pipe(buffer(child.close)).subscribe(lines => {
228
- expect(lines).toContainEqual(expect.stringContaining('[echo foo] foo'));
229
- expect(lines).toContainEqual(expect.stringContaining('[echo bar] bar'));
230
- done();
231
- }, done);
232
- });
233
- });
234
-
235
- describe('--prefix-length', () => {
236
- it('is aliased to -l', done => {
237
- const child = run('-p command -l 5 "echo foo" "echo bar"');
238
- child.log.pipe(buffer(child.close)).subscribe(lines => {
239
- expect(lines).toContainEqual(expect.stringContaining('[ec..o] foo'));
240
- expect(lines).toContainEqual(expect.stringContaining('[ec..r] bar'));
241
- done();
242
- }, done);
243
- });
244
-
245
- it('specifies custom prefix length', done => {
246
- const child = run('--prefix command --prefix-length 5 "echo foo" "echo bar"');
247
- child.log.pipe(buffer(child.close)).subscribe(lines => {
248
- expect(lines).toContainEqual(expect.stringContaining('[ec..o] foo'));
249
- expect(lines).toContainEqual(expect.stringContaining('[ec..r] bar'));
250
- done();
251
- }, done);
252
- });
253
- });
254
-
255
- describe('--restart-tries', () => {
256
- it('changes how many times a command will restart', done => {
257
- const child = run('--restart-tries 1 "exit 1"');
258
- child.log.pipe(buffer(child.close)).subscribe(lines => {
259
- expect(lines).toEqual([
260
- expect.stringContaining('[0] exit 1 exited with code 1'),
261
- expect.stringContaining('[0] exit 1 restarted'),
262
- expect.stringContaining('[0] exit 1 exited with code 1'),
263
- ]);
264
- done();
265
- }, done);
266
- });
267
- });
268
-
269
- describe('--kill-others', () => {
270
- it('is aliased to -k', done => {
271
- const child = run('-k "sleep 10" "exit 0"');
272
- child.log.pipe(buffer(child.close)).subscribe(lines => {
273
- expect(lines).toContainEqual(expect.stringContaining('[1] exit 0 exited with code 0'));
274
- expect(lines).toContainEqual(expect.stringContaining('Sending SIGTERM to other processes'));
275
- expect(lines).toContainEqual(expect.stringMatching(createKillMessage('[0] sleep 10')));
276
- done();
277
- }, done);
278
- });
279
-
280
- it('kills on success', done => {
281
- const child = run('--kill-others "sleep 10" "exit 0"');
282
- child.log.pipe(buffer(child.close)).subscribe(lines => {
283
- expect(lines).toContainEqual(expect.stringContaining('[1] exit 0 exited with code 0'));
284
- expect(lines).toContainEqual(expect.stringContaining('Sending SIGTERM to other processes'));
285
- expect(lines).toContainEqual(expect.stringMatching(createKillMessage('[0] sleep 10')));
286
- done();
287
- }, done);
288
- });
289
-
290
- it('kills on failure', done => {
291
- const child = run('--kill-others "sleep 10" "exit 1"');
292
- child.log.pipe(buffer(child.close)).subscribe(lines => {
293
- expect(lines).toContainEqual(expect.stringContaining('[1] exit 1 exited with code 1'));
294
- expect(lines).toContainEqual(expect.stringContaining('Sending SIGTERM to other processes'));
295
- expect(lines).toContainEqual(expect.stringMatching(createKillMessage('[0] sleep 10')));
296
- done();
297
- }, done);
298
- });
299
- });
300
-
301
- describe('--kill-others-on-fail', () => {
302
- it('does not kill on success', done => {
303
- const child = run('--kill-others-on-fail "sleep 0.5" "exit 0"');
304
- child.log.pipe(buffer(child.close)).subscribe(lines => {
305
- expect(lines).toContainEqual(expect.stringContaining('[1] exit 0 exited with code 0'));
306
- expect(lines).toContainEqual(expect.stringContaining('[0] sleep 0.5 exited with code 0'));
307
- done();
308
- }, done);
309
- });
310
-
311
- it('kills on failure', done => {
312
- const child = run('--kill-others-on-fail "sleep 10" "exit 1"');
313
- child.log.pipe(buffer(child.close)).subscribe(lines => {
314
- expect(lines).toContainEqual(expect.stringContaining('[1] exit 1 exited with code 1'));
315
- expect(lines).toContainEqual(expect.stringContaining('Sending SIGTERM to other processes'));
316
- expect(lines).toContainEqual(expect.stringMatching(createKillMessage('[0] sleep 10')));
317
- done();
318
- }, done);
319
- });
320
- });
321
-
322
- describe('--handle-input', () => {
323
- it('is aliased to -i', done => {
324
- const child = run('-i "node fixtures/read-echo.js"');
325
- child.log.subscribe(line => {
326
- if (/READING/.test(line)) {
327
- child.stdin.write('stop\n');
328
- }
329
-
330
- if (/\[0\] stop/.test(line)) {
331
- done();
332
- }
333
- }, done);
334
- });
335
-
336
- it('forwards input to first process by default', done => {
337
- const child = run('--handle-input "node fixtures/read-echo.js"');
338
- child.log.subscribe(line => {
339
- if (/READING/.test(line)) {
340
- child.stdin.write('stop\n');
341
- }
342
-
343
- if (/\[0\] stop/.test(line)) {
344
- done();
345
- }
346
- }, done);
347
- });
348
-
349
- it('forwards input to process --default-input-target', done => {
350
- const lines = [];
351
- const child = run('-ki --default-input-target 1 "node fixtures/read-echo.js" "node fixtures/read-echo.js"');
352
- child.log.subscribe(line => {
353
- lines.push(line);
354
- if (/\[1\] READING/.test(line)) {
355
- child.stdin.write('stop\n');
356
- }
357
- }, done);
358
-
359
- child.close.subscribe(exit => {
360
- expect(exit[0]).toBeGreaterThan(0);
361
- expect(lines).toContainEqual(expect.stringContaining('[1] stop'));
362
- expect(lines).toContainEqual(expect.stringMatching(createKillMessage('[0] node fixtures/read-echo.js')));
363
- done();
364
- }, done);
365
- });
366
-
367
- it('forwards input to specified process', done => {
368
- const lines = [];
369
- const child = run('-ki "node fixtures/read-echo.js" "node fixtures/read-echo.js"');
370
- child.log.subscribe(line => {
371
- lines.push(line);
372
- if (/\[1\] READING/.test(line)) {
373
- child.stdin.write('1:stop\n');
374
- }
375
- }, done);
376
-
377
- child.close.subscribe(exit => {
378
- expect(exit[0]).toBeGreaterThan(0);
379
- expect(lines).toContainEqual(expect.stringContaining('[1] stop'));
380
- expect(lines).toContainEqual(expect.stringMatching(createKillMessage('[0] node fixtures/read-echo.js')));
381
- done();
382
- }, done);
383
- });
384
- });
385
-
386
- describe('--timings', () => {
387
- const defaultTimestampFormatRegex = /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3}/;
388
- const processStartedMessageRegex = (index, command) => {
389
- return new RegExp( `^\\[${ index }] ${ command } started at ${ defaultTimestampFormatRegex.source }$` );
390
- };
391
- const processStoppedMessageRegex = (index, command) => {
392
- return new RegExp( `^\\[${ index }] ${ command } stopped at ${ defaultTimestampFormatRegex.source } after (\\d|,)+ms$` );
393
- };
394
- const expectLinesForProcessStartAndStop = (lines, index, command) => {
395
- const escapedCommand = _.escapeRegExp(command);
396
- expect(lines).toContainEqual(expect.stringMatching(processStartedMessageRegex(index, escapedCommand)));
397
- expect(lines).toContainEqual(expect.stringMatching(processStoppedMessageRegex(index, escapedCommand)));
398
- };
399
-
400
- const expectLinesForTimingsTable = (lines) => {
401
- const tableTopBorderRegex = /┌[─┬]+┐/g;
402
- expect(lines).toContainEqual(expect.stringMatching(tableTopBorderRegex));
403
- const tableHeaderRowRegex = /(\W+(name|duration|exit code|killed|command)\W+){5}/g;
404
- expect(lines).toContainEqual(expect.stringMatching(tableHeaderRowRegex));
405
- const tableBottomBorderRegex = /└[─┴]+┘/g;
406
- expect(lines).toContainEqual(expect.stringMatching(tableBottomBorderRegex));
407
- };
408
-
409
- it('shows timings on success', done => {
410
- const child = run('--timings "sleep 0.5" "exit 0"');
411
- child.log.pipe(buffer(child.close)).subscribe(lines => {
412
- expectLinesForProcessStartAndStop(lines, 0, 'sleep 0.5');
413
- expectLinesForProcessStartAndStop(lines, 1, 'exit 0');
414
- expectLinesForTimingsTable(lines);
415
- done();
416
- }, done);
417
- });
418
-
419
- it('shows timings on failure', done => {
420
- const child = run('--timings "sleep 0.75" "exit 1"');
421
- child.log.pipe(buffer(child.close)).subscribe(lines => {
422
- expectLinesForProcessStartAndStop(lines, 0, 'sleep 0.75');
423
- expectLinesForProcessStartAndStop(lines, 1, 'exit 1');
424
- expectLinesForTimingsTable(lines);
425
- done();
426
- }, done);
427
- });
428
- });