concurrently 10.0.0 → 10.0.1

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 (63) hide show
  1. package/dist/lib/flow-control/flow-controller.d.ts +13 -0
  2. package/dist/tsconfig.tsbuildinfo +1 -1
  3. package/package.json +11 -14
  4. package/dist/bin/index.spec.js +0 -368
  5. package/dist/bin/normalize-cli-command.spec.js +0 -36
  6. package/dist/lib/__fixtures__/create-mock-instance.d.ts +0 -2
  7. package/dist/lib/__fixtures__/create-mock-instance.js +0 -5
  8. package/dist/lib/__fixtures__/fake-command.d.ts +0 -6
  9. package/dist/lib/__fixtures__/fake-command.js +0 -37
  10. package/dist/lib/assert.spec.js +0 -41
  11. package/dist/lib/command-parser/expand-arguments.spec.d.ts +0 -1
  12. package/dist/lib/command-parser/expand-arguments.spec.js +0 -57
  13. package/dist/lib/command-parser/expand-shortcut.spec.d.ts +0 -1
  14. package/dist/lib/command-parser/expand-shortcut.spec.js +0 -36
  15. package/dist/lib/command-parser/expand-wildcard.spec.d.ts +0 -1
  16. package/dist/lib/command-parser/expand-wildcard.spec.js +0 -288
  17. package/dist/lib/command.spec.d.ts +0 -1
  18. package/dist/lib/command.spec.js +0 -369
  19. package/dist/lib/completion-listener.spec.d.ts +0 -1
  20. package/dist/lib/completion-listener.spec.js +0 -229
  21. package/dist/lib/concurrently.spec.d.ts +0 -1
  22. package/dist/lib/concurrently.spec.js +0 -320
  23. package/dist/lib/date-format.spec.d.ts +0 -1
  24. package/dist/lib/date-format.spec.js +0 -480
  25. package/dist/lib/flow-control/input-handler.spec.d.ts +0 -1
  26. package/dist/lib/flow-control/input-handler.spec.js +0 -116
  27. package/dist/lib/flow-control/kill-on-signal.spec.d.ts +0 -1
  28. package/dist/lib/flow-control/kill-on-signal.spec.js +0 -63
  29. package/dist/lib/flow-control/kill-others.spec.d.ts +0 -1
  30. package/dist/lib/flow-control/kill-others.spec.js +0 -98
  31. package/dist/lib/flow-control/log-error.spec.d.ts +0 -1
  32. package/dist/lib/flow-control/log-error.spec.js +0 -33
  33. package/dist/lib/flow-control/log-exit.spec.d.ts +0 -1
  34. package/dist/lib/flow-control/log-exit.spec.js +0 -24
  35. package/dist/lib/flow-control/log-output.spec.d.ts +0 -1
  36. package/dist/lib/flow-control/log-output.spec.js +0 -33
  37. package/dist/lib/flow-control/log-timings.spec.d.ts +0 -1
  38. package/dist/lib/flow-control/log-timings.spec.js +0 -89
  39. package/dist/lib/flow-control/logger-padding.spec.d.ts +0 -1
  40. package/dist/lib/flow-control/logger-padding.spec.js +0 -60
  41. package/dist/lib/flow-control/output-error-handler.spec.d.ts +0 -1
  42. package/dist/lib/flow-control/output-error-handler.spec.js +0 -41
  43. package/dist/lib/flow-control/restart-process.spec.d.ts +0 -1
  44. package/dist/lib/flow-control/restart-process.spec.js +0 -127
  45. package/dist/lib/flow-control/teardown.spec.d.ts +0 -1
  46. package/dist/lib/flow-control/teardown.spec.js +0 -93
  47. package/dist/lib/jsonc.spec.d.ts +0 -1
  48. package/dist/lib/jsonc.spec.js +0 -73
  49. package/dist/lib/logger.spec.d.ts +0 -1
  50. package/dist/lib/logger.spec.js +0 -507
  51. package/dist/lib/observables.spec.d.ts +0 -1
  52. package/dist/lib/observables.spec.js +0 -29
  53. package/dist/lib/output-writer.spec.d.ts +0 -1
  54. package/dist/lib/output-writer.spec.js +0 -96
  55. package/dist/lib/prefix-color-selector.spec.d.ts +0 -1
  56. package/dist/lib/prefix-color-selector.spec.js +0 -159
  57. package/dist/lib/spawn.spec.d.ts +0 -1
  58. package/dist/lib/spawn.spec.js +0 -100
  59. package/dist/lib/utils.spec.d.ts +0 -1
  60. package/dist/lib/utils.spec.js +0 -58
  61. /package/dist/bin/{index.spec.d.ts → bin-options.d.ts} +0 -0
  62. /package/dist/bin/{normalize-cli-command.spec.d.ts → bin-options.js} +0 -0
  63. /package/dist/lib/{assert.spec.d.ts → flow-control/flow-controller.js} +0 -0
@@ -1,480 +0,0 @@
1
- import { afterAll, beforeAll, describe, expect, it } from 'vitest';
2
- import { DateFormatter } from './date-format.js';
3
- const withTime = (time) => `2000-01-01T${time}`;
4
- const withDate = (date) => `${date}T00:00:00`;
5
- /**
6
- * Generates a suite of tests for token `token`.
7
- *
8
- * Each entry in `patternTests` makes the token longer, e.g.
9
- * ```
10
- * makeTests('year', 'y', [
11
- * [{ expected: '2', input: withDate('0002-01-01') }], // y
12
- * [{ expected: '02', input: withDate('0002-01-01') }], // yy
13
- * // ...
14
- * ]);
15
- * ```
16
- */
17
- const makeTests = (name, token, patternTests, options) => describe(`${name}`, () => {
18
- patternTests.forEach((tests, i) => {
19
- const pattern = token.repeat(i + 1);
20
- if (!tests) {
21
- return it(`is not implemented for ${pattern}`, () => {
22
- expect(() => new DateFormatter(pattern)).toThrow(RangeError);
23
- });
24
- }
25
- else if (!tests.length) {
26
- return;
27
- }
28
- it.each(tests)(`for pattern ${pattern} and input "$input" returns "$expected"`, ({ expected, input }) => {
29
- const formatter = new DateFormatter(pattern, {
30
- locale: 'en',
31
- calendar: 'gregory',
32
- ...options,
33
- });
34
- expect(formatter.format(new Date(input))).toBe(expected);
35
- });
36
- });
37
- });
38
- describe('combined', () => {
39
- it('works with tokens and punctuation', () => {
40
- const formatter = new DateFormatter('yyyy-MM-dd HH:mm:ss', { locale: 'en' });
41
- const date = new Date(2024, 8, 1, 15, 30, 50);
42
- expect(formatter.format(date)).toBe('2024-09-01 15:30:50');
43
- });
44
- it('works with tokens and literals', () => {
45
- const formatter = new DateFormatter("HH 'o''clock'", { locale: 'en' });
46
- const date = new Date();
47
- date.setHours(10);
48
- expect(formatter.format(date)).toBe("10 o'clock");
49
- });
50
- });
51
- describe('literals', () => {
52
- it.each([
53
- ["'", "''"],
54
- ['foo bar', "'foo bar'"],
55
- ["foo ' bar", "'foo '' bar'"],
56
- ["foo bar'?", "'foo bar'''?"],
57
- ])('returns "%s" for pattern "%s"', (expected, pattern) => {
58
- const formatter = new DateFormatter(pattern);
59
- expect(formatter.format(new Date())).toBe(expected);
60
- });
61
- });
62
- describe('tokens', () => {
63
- it('throws if a token does not exist', () => {
64
- expect(() => new DateFormatter('t')).toThrow(SyntaxError);
65
- });
66
- makeTests('era', 'G', [
67
- [
68
- { input: withDate('-000001-01-01'), expected: 'BC' },
69
- { input: withDate('0001-01-01'), expected: 'AD' },
70
- ],
71
- [
72
- { input: withDate('-000001-01-01'), expected: 'BC' },
73
- { input: withDate('0001-01-01'), expected: 'AD' },
74
- ],
75
- [
76
- { input: withDate('-000001-01-01'), expected: 'BC' },
77
- { input: withDate('0001-01-01'), expected: 'AD' },
78
- ],
79
- [
80
- { input: withDate('-000001-01-01'), expected: 'Before Christ' },
81
- { input: withDate('0001-01-01'), expected: 'Anno Domini' },
82
- ],
83
- [
84
- { input: withDate('-000001-01-01'), expected: 'B' },
85
- { input: withDate('0001-01-01'), expected: 'A' },
86
- ],
87
- ]);
88
- makeTests('year', 'y', [
89
- [
90
- { expected: '2', input: withDate('0002-01-01') },
91
- { expected: '20', input: withDate('0020-01-01') },
92
- { expected: '200', input: withDate('0200-01-01') },
93
- { expected: '2000', input: withDate('2000-01-01') },
94
- ],
95
- [
96
- { expected: '02', input: withDate('0002-01-01') },
97
- { expected: '20', input: withDate('0020-01-01') },
98
- { expected: '00', input: withDate('0200-01-01') },
99
- { expected: '05', input: withDate('0205-01-01') },
100
- { expected: '00', input: withDate('2000-01-01') },
101
- { expected: '05', input: withDate('2005-01-01') },
102
- ],
103
- [
104
- { expected: '002', input: withDate('0002-01-01') },
105
- { expected: '020', input: withDate('0020-01-01') },
106
- { expected: '200', input: withDate('0200-01-01') },
107
- { expected: '2000', input: withDate('2000-01-01') },
108
- ],
109
- [
110
- { expected: '0002', input: withDate('0002-01-01') },
111
- { expected: '0020', input: withDate('0020-01-01') },
112
- { expected: '0200', input: withDate('0200-01-01') },
113
- { expected: '2000', input: withDate('2000-01-01') },
114
- ],
115
- [
116
- { expected: '00002', input: withDate('0002-01-01') },
117
- { expected: '00020', input: withDate('0020-01-01') },
118
- { expected: '00200', input: withDate('0200-01-01') },
119
- { expected: '02000', input: withDate('2000-01-01') },
120
- ],
121
- ]);
122
- describe('year name', () => {
123
- makeTests('with en locale', 'U', [[{ expected: '2024', input: withDate('2024-01-01') }]], {
124
- locale: 'en',
125
- });
126
- makeTests('with zh-CN locale + chinese calendar', 'U', [[{ expected: '癸卯', input: withDate('2024-01-01') }]], { locale: 'zh-CN', calendar: 'chinese' });
127
- });
128
- describe('related year', () => {
129
- makeTests('with en locale', 'r', [[{ expected: '2024', input: withDate('2024-01-01') }]], {
130
- locale: 'en',
131
- });
132
- makeTests('with zh-CN locale + chinese calendar', 'r', [
133
- [
134
- { expected: '2023', input: withDate('2024-01-01') },
135
- { expected: '2024', input: withDate('2024-03-01') },
136
- ],
137
- ], { locale: 'zh-CN', calendar: 'chinese' });
138
- });
139
- describe('week year', () => {
140
- makeTests('with en locale', 'Y', [
141
- [
142
- { expected: '2023', input: withDate('2023-01-01') },
143
- { expected: '2024', input: withDate('2023-12-31') },
144
- { expected: '2024', input: withDate('2024-01-01') },
145
- { expected: '2025', input: withDate('2024-12-31') },
146
- ],
147
- [
148
- { expected: '23', input: withDate('2023-01-01') },
149
- { expected: '24', input: withDate('2023-12-31') },
150
- { expected: '24', input: withDate('2024-01-01') },
151
- { expected: '25', input: withDate('2024-12-31') },
152
- ],
153
- ], { locale: 'en' });
154
- makeTests('with de-DE locale', 'Y', [
155
- [
156
- { expected: '2022', input: withDate('2023-01-01') },
157
- { expected: '2023', input: withDate('2023-12-31') },
158
- { expected: '2024', input: withDate('2024-01-01') },
159
- { expected: '2025', input: withDate('2024-12-31') },
160
- ],
161
- [
162
- { expected: '22', input: withDate('2023-01-01') },
163
- { expected: '23', input: withDate('2023-12-31') },
164
- { expected: '24', input: withDate('2024-01-01') },
165
- { expected: '25', input: withDate('2024-12-31') },
166
- ],
167
- ], { locale: 'de-DE' });
168
- describe(`when minimalDays is missing`, () => {
169
- beforeAll(() => {
170
- if (typeof Intl.Locale.prototype.getWeekInfo === 'function') {
171
- Intl.Locale.prototype.getWeekInfoOrig = Intl.Locale.prototype.getWeekInfo;
172
- }
173
- Intl.Locale.prototype.getWeekInfo = function () {
174
- const data = typeof Intl.Locale.prototype.getWeekInfoOrig === 'function'
175
- ? this.getWeekInfoOrig()
176
- : this.weekInfo;
177
- delete data.minimalDays;
178
- return data;
179
- };
180
- });
181
- afterAll(() => {
182
- if (Intl.Locale.prototype.getWeekInfoOrig) {
183
- Intl.Locale.prototype.getWeekInfo = Intl.Locale.prototype.getWeekInfoOrig;
184
- delete Intl.Locale.prototype.getWeekInfoOrig;
185
- }
186
- });
187
- makeTests(
188
- // Needs to be a different locale than in tests above to not use cached weekInfo
189
- 'with de-CH locale', 'Y', [
190
- [
191
- { expected: '2022', input: withDate('2023-01-01') },
192
- { expected: '2023', input: withDate('2023-12-31') },
193
- { expected: '2024', input: withDate('2024-01-01') },
194
- { expected: '2025', input: withDate('2024-12-31') },
195
- ],
196
- [
197
- { expected: '22', input: withDate('2023-01-01') },
198
- { expected: '23', input: withDate('2023-12-31') },
199
- { expected: '24', input: withDate('2024-01-01') },
200
- { expected: '25', input: withDate('2024-12-31') },
201
- ],
202
- ], { locale: 'de-CH' });
203
- });
204
- });
205
- makeTests('quarter', 'Q', [
206
- [
207
- { expected: '1', input: withDate('2000-01-01') },
208
- { expected: '2', input: withDate('2000-04-01') },
209
- { expected: '3', input: withDate('2000-07-01') },
210
- { expected: '4', input: withDate('2000-10-01') },
211
- ],
212
- [
213
- { expected: '01', input: withDate('2000-01-01') },
214
- { expected: '02', input: withDate('2000-04-01') },
215
- { expected: '03', input: withDate('2000-07-01') },
216
- { expected: '04', input: withDate('2000-10-01') },
217
- ],
218
- undefined,
219
- undefined,
220
- [
221
- { expected: '1', input: withDate('2000-01-01') },
222
- { expected: '2', input: withDate('2000-04-01') },
223
- { expected: '3', input: withDate('2000-07-01') },
224
- { expected: '4', input: withDate('2000-10-01') },
225
- ],
226
- ]);
227
- makeTests('quarter - stand-alone', 'q', [
228
- [
229
- { expected: '1', input: withDate('2000-01-01') },
230
- { expected: '2', input: withDate('2000-04-01') },
231
- { expected: '3', input: withDate('2000-07-01') },
232
- { expected: '4', input: withDate('2000-10-01') },
233
- ],
234
- [
235
- { expected: '01', input: withDate('2000-01-01') },
236
- { expected: '02', input: withDate('2000-04-01') },
237
- { expected: '03', input: withDate('2000-07-01') },
238
- { expected: '04', input: withDate('2000-10-01') },
239
- ],
240
- undefined,
241
- undefined,
242
- [
243
- { expected: '1', input: withDate('2000-01-01') },
244
- { expected: '2', input: withDate('2000-04-01') },
245
- { expected: '3', input: withDate('2000-07-01') },
246
- { expected: '4', input: withDate('2000-10-01') },
247
- ],
248
- ]);
249
- describe('month', () => {
250
- makeTests('with en locale', 'M', [
251
- [{ expected: '1', input: withDate('2000-01-01') }],
252
- [{ expected: '01', input: withDate('2000-01-01') }],
253
- [{ expected: 'Jan', input: withDate('2000-01-01') }],
254
- [{ expected: 'January', input: withDate('2000-01-01') }],
255
- [{ expected: 'J', input: withDate('2000-01-01') }],
256
- ], { locale: 'en' });
257
- makeTests('with pl locale', 'M', [
258
- [{ expected: '1', input: withDate('2000-01-01') }],
259
- [{ expected: '01', input: withDate('2000-01-01') }],
260
- [{ expected: 'sty', input: withDate('2000-01-01') }],
261
- [{ expected: 'stycznia', input: withDate('2000-01-01') }],
262
- [{ expected: 's', input: withDate('2000-01-01') }],
263
- ], { locale: 'pl' });
264
- });
265
- describe('month - stand-alone', () => {
266
- makeTests('with en locale', 'L', [
267
- [{ expected: '1', input: withDate('2000-01-01') }],
268
- [{ expected: '01', input: withDate('2000-01-01') }],
269
- [{ expected: 'Jan', input: withDate('2000-01-01') }],
270
- [{ expected: 'January', input: withDate('2000-01-01') }],
271
- [{ expected: 'J', input: withDate('2000-01-01') }],
272
- ], { locale: 'en' });
273
- makeTests('with pl locale', 'L', [
274
- [{ expected: '1', input: withDate('2000-01-01') }],
275
- [{ expected: '01', input: withDate('2000-01-01') }],
276
- [{ expected: 'sty', input: withDate('2000-01-01') }],
277
- [{ expected: 'styczeń', input: withDate('2000-01-01') }],
278
- [{ expected: 'S', input: withDate('2000-01-01') }],
279
- ], { locale: 'pl' });
280
- });
281
- describe('week of year', () => {
282
- makeTests('with en locale', 'w', [
283
- [
284
- { expected: '1', input: withDate('2023-01-01') },
285
- { expected: '1', input: withDate('2023-12-31') },
286
- { expected: '1', input: withDate('2024-01-01') },
287
- { expected: '1', input: withDate('2024-12-31') },
288
- ],
289
- [
290
- { expected: '01', input: withDate('2023-01-01') },
291
- { expected: '01', input: withDate('2023-12-31') },
292
- { expected: '01', input: withDate('2024-01-01') },
293
- { expected: '01', input: withDate('2024-12-31') },
294
- ],
295
- ], { locale: 'en' });
296
- makeTests('with de-DE locale', 'w', [
297
- [
298
- { expected: '52', input: withDate('2023-01-01') },
299
- { expected: '52', input: withDate('2023-12-31') },
300
- { expected: '1', input: withDate('2024-01-01') },
301
- { expected: '1', input: withDate('2024-12-31') },
302
- ],
303
- [
304
- { expected: '52', input: withDate('2023-01-01') },
305
- { expected: '52', input: withDate('2023-12-31') },
306
- { expected: '01', input: withDate('2024-01-01') },
307
- { expected: '01', input: withDate('2024-12-31') },
308
- ],
309
- ], { locale: 'de-DE' });
310
- });
311
- describe('week of month', () => {
312
- makeTests('with en locale', 'W', [
313
- [
314
- { expected: '6', input: withDate('2021-01-31') },
315
- { expected: '5', input: withDate('2021-02-28') },
316
- ],
317
- ], { locale: 'en' });
318
- makeTests('with de-DE locale', 'W', [
319
- [
320
- { expected: '5', input: withDate('2021-01-31') },
321
- { expected: '4', input: withDate('2021-02-28') },
322
- ],
323
- ], { locale: 'de-DE' });
324
- });
325
- makeTests('day', 'd', [
326
- [
327
- { expected: '1', input: withDate('2000-01-01') },
328
- { expected: '10', input: withDate('2000-01-10') },
329
- ],
330
- [
331
- { expected: '01', input: withDate('2000-01-01') },
332
- { expected: '10', input: withDate('2000-01-10') },
333
- ],
334
- ]);
335
- makeTests('day of week in month', 'F', [
336
- [
337
- { expected: '1', input: withDate('2024-09-01') },
338
- { expected: '2', input: withDate('2024-09-08') },
339
- ],
340
- ]);
341
- makeTests('day of year', 'D', [
342
- [
343
- { expected: '1', input: withDate('2024-01-01') },
344
- { expected: '32', input: withDate('2024-02-01') },
345
- { expected: '366', input: withDate('2024-12-31') },
346
- ],
347
- [
348
- { expected: '01', input: withDate('2024-01-01') },
349
- { expected: '32', input: withDate('2024-02-01') },
350
- { expected: '366', input: withDate('2024-12-31') },
351
- ],
352
- [
353
- { expected: '001', input: withDate('2024-01-01') },
354
- { expected: '032', input: withDate('2024-02-01') },
355
- { expected: '366', input: withDate('2024-12-31') },
356
- ],
357
- ]);
358
- makeTests('week day', 'E', [
359
- [{ expected: 'Sat', input: withDate('2024-09-07') }],
360
- [{ expected: 'Sat', input: withDate('2024-09-07') }],
361
- [{ expected: 'Sat', input: withDate('2024-09-07') }],
362
- [{ expected: 'Saturday', input: withDate('2024-09-07') }],
363
- ]);
364
- makeTests('local week day', 'e', [
365
- undefined,
366
- undefined,
367
- [{ expected: 'Sat', input: withDate('2024-09-07') }],
368
- [{ expected: 'Saturday', input: withDate('2024-09-07') }],
369
- ]);
370
- makeTests('period', 'a', [
371
- [
372
- { expected: 'AM', input: withTime('10:00:00') },
373
- { expected: 'PM', input: withTime('12:00:00') },
374
- ],
375
- [
376
- { expected: 'AM', input: withTime('10:00:00') },
377
- { expected: 'PM', input: withTime('12:00:00') },
378
- ],
379
- [
380
- { expected: 'AM', input: withTime('10:00:00') },
381
- { expected: 'PM', input: withTime('12:00:00') },
382
- ],
383
- ]);
384
- makeTests('flexible day period', 'B', [
385
- [
386
- { expected: 'in the morning', input: withTime('06:00:00') },
387
- { expected: 'noon', input: withTime('12:00:00') },
388
- { expected: 'in the afternoon', input: withTime('16:00:00') },
389
- { expected: 'at night', input: withTime('23:00:00') },
390
- ],
391
- [],
392
- [],
393
- [
394
- { expected: 'in the morning', input: withTime('06:00:00') },
395
- { expected: 'noon', input: withTime('12:00:00') },
396
- { expected: 'in the afternoon', input: withTime('16:00:00') },
397
- { expected: 'at night', input: withTime('23:00:00') },
398
- ],
399
- ]);
400
- describe('hour', () => {
401
- makeTests('1-12 format (1 PM)', 'h', [
402
- [{ expected: '1', input: withTime('13:00:00') }],
403
- [{ expected: '01', input: withTime('13:00:00') }],
404
- ]);
405
- makeTests('1-12 format (12 PM)', 'h', [
406
- [{ expected: '12', input: withTime('00:00:00') }],
407
- [{ expected: '12', input: withTime('00:00:00') }],
408
- ]);
409
- makeTests('0-23 format', 'H', [
410
- [
411
- { expected: '0', input: withTime('00:00:00') },
412
- { expected: '13', input: withTime('13:00:00') },
413
- ],
414
- [
415
- { expected: '00', input: withTime('00:00:00') },
416
- { expected: '13', input: withTime('13:00:00') },
417
- ],
418
- ]);
419
- makeTests('0-11 format', 'K', [
420
- [
421
- { expected: '0', input: withTime('00:00:00') },
422
- { expected: '1', input: withTime('13:00:00') },
423
- ],
424
- [
425
- { expected: '00', input: withTime('00:00:00') },
426
- { expected: '01', input: withTime('13:00:00') },
427
- ],
428
- ]);
429
- makeTests('1-24 format', 'k', [
430
- [
431
- { expected: '13', input: withTime('13:00:00') },
432
- { expected: '24', input: withTime('00:00:00') },
433
- ],
434
- [
435
- { expected: '13', input: withTime('13:00:00') },
436
- { expected: '24', input: withTime('00:00:00') },
437
- ],
438
- ]);
439
- });
440
- makeTests('minute', 'm', [
441
- [
442
- { expected: '0', input: withTime('00:00:00') },
443
- { expected: '59', input: withTime('00:59:00') },
444
- ],
445
- [
446
- { expected: '00', input: withTime('00:00:00') },
447
- { expected: '59', input: withTime('00:59:00') },
448
- ],
449
- ]);
450
- makeTests('seconds', 's', [
451
- [
452
- { expected: '0', input: withTime('00:00:00') },
453
- { expected: '59', input: withTime('00:00:59') },
454
- ],
455
- [
456
- { expected: '00', input: withTime('00:00:00') },
457
- { expected: '59', input: withTime('00:00:59') },
458
- ],
459
- ]);
460
- makeTests('fractional seconds', 'S', [
461
- [
462
- { expected: '0', input: withTime('00:00:00.000') },
463
- { expected: '0', input: withTime('00:00:00.001') },
464
- { expected: '0', input: withTime('00:00:00.010') },
465
- { expected: '1', input: withTime('00:00:00.100') },
466
- ],
467
- [
468
- { expected: '00', input: withTime('00:00:00.000') },
469
- { expected: '00', input: withTime('00:00:00.001') },
470
- { expected: '01', input: withTime('00:00:00.010') },
471
- { expected: '10', input: withTime('00:00:00.100') },
472
- ],
473
- [
474
- { expected: '000', input: withTime('00:00:00.000') },
475
- { expected: '001', input: withTime('00:00:00.001') },
476
- { expected: '010', input: withTime('00:00:00.010') },
477
- { expected: '100', input: withTime('00:00:00.100') },
478
- ],
479
- ]);
480
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,116 +0,0 @@
1
- import { Buffer } from 'node:buffer';
2
- import { PassThrough } from 'node:stream';
3
- import { beforeEach, expect, it } from 'vitest';
4
- import { createMockInstance } from '../__fixtures__/create-mock-instance.js';
5
- import { FakeCommand } from '../__fixtures__/fake-command.js';
6
- import { Logger } from '../logger.js';
7
- import { InputHandler } from './input-handler.js';
8
- let commands;
9
- let controller;
10
- let inputStream;
11
- let logger;
12
- beforeEach(() => {
13
- commands = [new FakeCommand('foo', 'echo foo', 0), new FakeCommand('bar', 'echo bar', 1)];
14
- inputStream = new PassThrough();
15
- logger = createMockInstance(Logger);
16
- controller = new InputHandler({
17
- defaultInputTarget: 0,
18
- inputStream,
19
- logger,
20
- });
21
- });
22
- it('returns same commands', () => {
23
- expect(controller.handle(commands)).toMatchObject({ commands });
24
- controller = new InputHandler({ logger, inputStream });
25
- expect(controller.handle(commands)).toMatchObject({ commands });
26
- });
27
- it('does nothing if called without input stream', () => {
28
- new InputHandler({
29
- defaultInputTarget: 0,
30
- inputStream: undefined,
31
- logger,
32
- }).handle(commands);
33
- inputStream.write('something');
34
- expect(commands[0].stdin?.write).not.toHaveBeenCalled();
35
- });
36
- it('forwards input stream to default target ID', () => {
37
- controller.handle(commands);
38
- inputStream.write('something');
39
- expect(commands[0].stdin?.write).toHaveBeenCalledExactlyOnceWith('something');
40
- expect(commands[1].stdin?.write).not.toHaveBeenCalled();
41
- });
42
- it('forwards input stream to target index specified in input', () => {
43
- controller.handle(commands);
44
- inputStream.write('1:something');
45
- inputStream.write('1:multi\nline\n');
46
- expect(commands[0].stdin?.write).not.toHaveBeenCalled();
47
- expect(commands[1].stdin?.write).toHaveBeenCalledTimes(2);
48
- expect(commands[1].stdin?.write).toHaveBeenCalledWith('something');
49
- expect(commands[1].stdin?.write).toHaveBeenCalledWith('multi\nline\n');
50
- });
51
- it('forwards input stream to target index specified in input when input contains colon', () => {
52
- controller.handle(commands);
53
- inputStream.emit('data', Buffer.from('1:some:thing'));
54
- inputStream.emit('data', Buffer.from('1: :something'));
55
- inputStream.emit('data', Buffer.from('1::something'));
56
- expect(commands[0].stdin?.write).not.toHaveBeenCalled();
57
- expect(commands[1].stdin?.write).toHaveBeenCalledTimes(3);
58
- expect(commands[1].stdin?.write).toHaveBeenCalledWith('some:thing');
59
- expect(commands[1].stdin?.write).toHaveBeenCalledWith(' :something');
60
- expect(commands[1].stdin?.write).toHaveBeenCalledWith(':something');
61
- });
62
- it('does not forward input stream when input contains colon in a different format', () => {
63
- controller.handle(commands);
64
- inputStream.emit('data', Buffer.from('Ruby0::Const::Syntax'));
65
- inputStream.emit('data', Buffer.from('1:Ruby1::Const::Syntax'));
66
- inputStream.emit('data', Buffer.from('ruby_symbol_arg :my_symbol'));
67
- inputStream.emit('data', Buffer.from('ruby_symbol_arg(:my_symbol)'));
68
- inputStream.emit('data', Buffer.from('{ruby_key: :my_val}'));
69
- inputStream.emit('data', Buffer.from('{:ruby_key=>:my_val}'));
70
- inputStream.emit('data', Buffer.from('js_obj = {key: "my_val"}'));
71
- expect(commands[1].stdin?.write).toHaveBeenCalledExactlyOnceWith('Ruby1::Const::Syntax');
72
- expect(commands[0].stdin?.write).toHaveBeenCalledTimes(6);
73
- expect(commands[0].stdin?.write).toHaveBeenCalledWith('Ruby0::Const::Syntax');
74
- expect(commands[0].stdin?.write).toHaveBeenCalledWith('ruby_symbol_arg :my_symbol');
75
- expect(commands[0].stdin?.write).toHaveBeenCalledWith('ruby_symbol_arg(:my_symbol)');
76
- expect(commands[0].stdin?.write).toHaveBeenCalledWith('{ruby_key: :my_val}');
77
- expect(commands[0].stdin?.write).toHaveBeenCalledWith('{:ruby_key=>:my_val}');
78
- expect(commands[0].stdin?.write).toHaveBeenCalledWith('js_obj = {key: "my_val"}');
79
- });
80
- it('forwards input stream to target name specified in input', () => {
81
- controller.handle(commands);
82
- inputStream.write('bar:something');
83
- expect(commands[0].stdin?.write).not.toHaveBeenCalled();
84
- expect(commands[1].stdin?.write).toHaveBeenCalledExactlyOnceWith('something');
85
- });
86
- it('logs error if command has no stdin open', () => {
87
- commands[0].stdin = undefined;
88
- controller.handle(commands);
89
- inputStream.write('something');
90
- expect(commands[1].stdin?.write).not.toHaveBeenCalled();
91
- expect(logger.logGlobalEvent).toHaveBeenCalledWith('Unable to find command "0", or it has no stdin open\n');
92
- });
93
- it('fallback to default input stream if command is not found', () => {
94
- controller.handle(commands);
95
- inputStream.write('foobar:something');
96
- expect(commands[0].stdin?.write).toHaveBeenCalledExactlyOnceWith('foobar:something');
97
- expect(commands[1].stdin?.write).not.toHaveBeenCalled();
98
- expect(logger.logGlobalEvent).not.toHaveBeenCalled();
99
- });
100
- it('pauses input stream when finished', () => {
101
- expect(inputStream.readableFlowing).toBeNull();
102
- const { onFinish } = controller.handle(commands);
103
- expect(inputStream.readableFlowing).toBe(true);
104
- expect(onFinish).toBeDefined();
105
- onFinish?.();
106
- expect(inputStream.readableFlowing).toBe(false);
107
- });
108
- it('does not pause input stream when pauseInputStreamOnFinish is set to false', () => {
109
- controller = new InputHandler({ logger, inputStream, pauseInputStreamOnFinish: false });
110
- expect(inputStream.readableFlowing).toBeNull();
111
- const { onFinish } = controller.handle(commands);
112
- expect(inputStream.readableFlowing).toBe(true);
113
- expect(onFinish).toBeDefined();
114
- onFinish?.();
115
- expect(inputStream.readableFlowing).toBe(true);
116
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,63 +0,0 @@
1
- import { EventEmitter } from 'node:events';
2
- import { beforeEach, describe, expect, it, vi } from 'vitest';
3
- import { createFakeCloseEvent, FakeCommand } from '../__fixtures__/fake-command.js';
4
- import { KillOnSignal } from './kill-on-signal.js';
5
- let commands;
6
- let controller;
7
- let process;
8
- let abortController;
9
- beforeEach(() => {
10
- process = new EventEmitter();
11
- commands = [new FakeCommand(), new FakeCommand()];
12
- abortController = new AbortController();
13
- controller = new KillOnSignal({ process, abortController });
14
- });
15
- it('returns commands that keep non-close streams from original commands', () => {
16
- const { commands: newCommands } = controller.handle(commands);
17
- newCommands.forEach((newCommand, i) => {
18
- expect(newCommand.close).not.toBe(commands[i].close);
19
- expect(newCommand.error).toBe(commands[i].error);
20
- expect(newCommand.stdout).toBe(commands[i].stdout);
21
- expect(newCommand.stderr).toBe(commands[i].stderr);
22
- });
23
- });
24
- it('returns commands that map SIGINT to exit code 0', () => {
25
- const { commands: newCommands } = controller.handle(commands);
26
- expect(newCommands).not.toBe(commands);
27
- expect(newCommands).toHaveLength(commands.length);
28
- const callback = vi.fn();
29
- newCommands[0].close.subscribe(callback);
30
- process.emit('SIGINT', 'SIGINT');
31
- // A fake command's .kill() call won't trigger a close event automatically...
32
- commands[0].close.next(createFakeCloseEvent({ exitCode: 1 }));
33
- expect(callback).not.toHaveBeenCalledWith(expect.objectContaining({ exitCode: 'SIGINT' }));
34
- expect(callback).toHaveBeenCalledWith(expect.objectContaining({ exitCode: 0 }));
35
- });
36
- it('returns commands that keep non-SIGINT exit codes', () => {
37
- const { commands: newCommands } = controller.handle(commands);
38
- expect(newCommands).not.toBe(commands);
39
- expect(newCommands).toHaveLength(commands.length);
40
- const callback = vi.fn();
41
- newCommands[0].close.subscribe(callback);
42
- commands[0].close.next(createFakeCloseEvent({ exitCode: 1 }));
43
- expect(callback).toHaveBeenCalledWith(expect.objectContaining({ exitCode: 1 }));
44
- });
45
- describe.each(['SIGINT', 'SIGTERM', 'SIGHUP'])('on %s', (signal) => {
46
- it('kills all commands', () => {
47
- controller.handle(commands);
48
- process.emit(signal, signal);
49
- expect(process.listenerCount(signal)).toBe(1);
50
- expect(commands[0].kill).toHaveBeenCalledWith(signal);
51
- expect(commands[1].kill).toHaveBeenCalledWith(signal);
52
- });
53
- it('sends abort signal', () => {
54
- controller.handle(commands);
55
- process.emit(signal, signal);
56
- expect(abortController.signal.aborted).toBe(true);
57
- });
58
- it('removes event listener on finish', () => {
59
- const { onFinish } = controller.handle(commands);
60
- onFinish();
61
- expect(process.listenerCount(signal)).toBe(0);
62
- });
63
- });
@@ -1 +0,0 @@
1
- export {};