Skip to content

Commit 026d28c

Browse files
watch: clarify completion/failure watch mode messages
clarify the messages that `node --watch` presents to the user when the process terminates (either successfully or because of some error) by clearly conveying that node is waiting for new file changes before restarting the process
1 parent 25842c5 commit 026d28c

File tree

2 files changed

+48
-47
lines changed

2 files changed

+48
-47
lines changed

lib/internal/main/watch_mode.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,11 @@ function start() {
7979
}
8080
child.once('exit', (code) => {
8181
exited = true;
82+
const waitingForChanges = 'Waiting for file changes before restarting...';
8283
if (code === 0) {
83-
process.stdout.write(`${blue}Completed running ${kCommandStr}${white}\n`);
84+
process.stdout.write(`${blue}Completed running ${kCommandStr}. ${waitingForChanges}${white}\n`);
8485
} else {
85-
process.stdout.write(`${red}Failed running ${kCommandStr}${white}\n`);
86+
process.stdout.write(`${red}Failed running ${kCommandStr}. ${waitingForChanges}${white}\n`);
8687
}
8788
});
8889
return child;

test/sequential/test-watch-mode.mjs

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,10 @@ describe('watch mode', { concurrency: !process.env.TEST_PARALLEL, timeout: 60_00
171171
assert.strictEqual(stderr, '');
172172
assert.deepStrictEqual(stdout, [
173173
'running',
174-
`Completed running ${inspect(file)}`,
174+
`Completed running ${inspect(file)}. Waiting for file changes before restarting...`,
175175
`Restarting ${inspect(file)}`,
176176
'running',
177-
`Completed running ${inspect(file)}`,
177+
`Completed running ${inspect(file)}. Waiting for file changes before restarting...`,
178178
]);
179179
});
180180

@@ -185,10 +185,10 @@ describe('watch mode', { concurrency: !process.env.TEST_PARALLEL, timeout: 60_00
185185
assert.strictEqual(stderr, '');
186186
assert.deepStrictEqual(stdout, [
187187
'running',
188-
`Completed running ${inspect(file)}`,
188+
`Completed running ${inspect(file)}. Waiting for file changes before restarting...`,
189189
`Restarting ${inspect(file)}`,
190190
'running',
191-
`Completed running ${inspect(file)}`,
191+
`Completed running ${inspect(file)}. Waiting for file changes before restarting...`,
192192
]);
193193
});
194194

@@ -209,7 +209,7 @@ describe('watch mode', { concurrency: !process.env.TEST_PARALLEL, timeout: 60_00
209209
assert.deepStrictEqual(stdout, [
210210
`Restarting ${inspect(jsFile)}`,
211211
'ENV: value2',
212-
`Completed running ${inspect(jsFile)}`,
212+
`Completed running ${inspect(jsFile)}. Waiting for file changes before restarting...`,
213213
]);
214214
} finally {
215215
await done();
@@ -235,7 +235,7 @@ describe('watch mode', { concurrency: !process.env.TEST_PARALLEL, timeout: 60_00
235235
`Restarting ${inspect(jsFile)}`,
236236
'ENV: value1',
237237
'ENV2: newValue',
238-
`Completed running ${inspect(jsFile)}`,
238+
`Completed running ${inspect(jsFile)}. Waiting for file changes before restarting...`,
239239
]);
240240
} finally {
241241
await done();
@@ -261,7 +261,7 @@ describe('watch mode', { concurrency: !process.env.TEST_PARALLEL, timeout: 60_00
261261
`Restarting ${inspect(jsFile)}`,
262262
'ENV: value1',
263263
'ENV2: newValue',
264-
`Completed running ${inspect(jsFile)}`,
264+
`Completed running ${inspect(jsFile)}. Waiting for file changes before restarting...`,
265265
]);
266266
} finally {
267267
await done();
@@ -279,9 +279,9 @@ describe('watch mode', { concurrency: !process.env.TEST_PARALLEL, timeout: 60_00
279279

280280
assert.match(stderr, /Error: fails\r?\n/);
281281
assert.deepStrictEqual(stdout, [
282-
`Failed running ${inspect(file)}`,
282+
`Failed running ${inspect(file)}. Waiting for file changes before restarting...`,
283283
`Restarting ${inspect(file)}`,
284-
`Failed running ${inspect(file)}`,
284+
`Failed running ${inspect(file)}. Waiting for file changes before restarting...`,
285285
]);
286286
});
287287

@@ -298,10 +298,10 @@ describe('watch mode', { concurrency: !process.env.TEST_PARALLEL, timeout: 60_00
298298
assert.strictEqual(stderr, '');
299299
assert.deepStrictEqual(stdout, [
300300
'running',
301-
`Completed running ${inspect(file)}`,
301+
`Completed running ${inspect(file)}. Waiting for file changes before restarting...`,
302302
`Restarting ${inspect(file)}`,
303303
'running',
304-
`Completed running ${inspect(file)}`,
304+
`Completed running ${inspect(file)}. Waiting for file changes before restarting...`,
305305
]);
306306
assert.strictEqual(stderr, '');
307307
});
@@ -324,9 +324,9 @@ describe('watch mode', { concurrency: !process.env.TEST_PARALLEL, timeout: 60_00
324324

325325
assert.match(stderr, /Error: Cannot find module/g);
326326
assert.deepStrictEqual(stdout, [
327-
`Failed running ${inspect(file)}`,
327+
`Failed running ${inspect(file)}. Waiting for file changes before restarting...`,
328328
`Restarting ${inspect(file)}`,
329-
`Failed running ${inspect(file)}`,
329+
`Failed running ${inspect(file)}. Waiting for file changes before restarting...`,
330330
]);
331331
});
332332

@@ -348,9 +348,9 @@ describe('watch mode', { concurrency: !process.env.TEST_PARALLEL, timeout: 60_00
348348

349349
assert.match(stderr, /Error: Cannot find module/g);
350350
assert.deepStrictEqual(stdout, [
351-
`Failed running ${inspect(file)}`,
351+
`Failed running ${inspect(file)}. Waiting for file changes before restarting...`,
352352
`Restarting ${inspect(file)}`,
353-
`Failed running ${inspect(file)}`,
353+
`Failed running ${inspect(file)}. Waiting for file changes before restarting...`,
354354
]);
355355
});
356356

@@ -380,10 +380,10 @@ console.log(dependency);
380380
assert.strictEqual(stderr, '');
381381
assert.deepStrictEqual(stdout, [
382382
'{}',
383-
`Completed running ${inspect(file)}`,
383+
`Completed running ${inspect(file)}. Waiting for file changes before restarting...`,
384384
`Restarting ${inspect(file)}`,
385385
'{}',
386-
`Completed running ${inspect(file)}`,
386+
`Completed running ${inspect(file)}. Waiting for file changes before restarting...`,
387387
]);
388388
});
389389

@@ -398,10 +398,10 @@ console.log(dependency);
398398
assert.strictEqual(stderr, '');
399399
assert.deepStrictEqual(stdout, [
400400
'{}',
401-
`Completed running ${inspect(file)}`,
401+
`Completed running ${inspect(file)}. Waiting for file changes before restarting...`,
402402
`Restarting ${inspect(file)}`,
403403
'{}',
404-
`Completed running ${inspect(file)}`,
404+
`Completed running ${inspect(file)}. Waiting for file changes before restarting...`,
405405
]);
406406
});
407407

@@ -412,13 +412,13 @@ console.log(dependency);
412412
assert.strictEqual(stderr, '');
413413
assert.deepStrictEqual(stdout, [
414414
'running',
415-
`Completed running ${inspect(file)}`,
415+
`Completed running ${inspect(file)}. Waiting for file changes before restarting...`,
416416
`Restarting ${inspect(file)}`,
417417
'running',
418-
`Completed running ${inspect(file)}`,
418+
`Completed running ${inspect(file)}. Waiting for file changes before restarting...`,
419419
`Restarting ${inspect(file)}`,
420420
'running',
421-
`Completed running ${inspect(file)}`,
421+
`Completed running ${inspect(file)}. Waiting for file changes before restarting...`,
422422
]);
423423
});
424424

@@ -435,10 +435,10 @@ console.log(values.random);
435435
assert.strictEqual(stderr, '');
436436
assert.deepStrictEqual(stdout, [
437437
random,
438-
`Completed running ${inspect(`${file} --random ${random}`)}`,
438+
`Completed running ${inspect(`${file} --random ${random}`)}. Waiting for file changes before restarting...`,
439439
`Restarting ${inspect(`${file} --random ${random}`)}`,
440440
random,
441-
`Completed running ${inspect(`${file} --random ${random}`)}`,
441+
`Completed running ${inspect(`${file} --random ${random}`)}. Waiting for file changes before restarting...`,
442442
]);
443443
});
444444

@@ -452,10 +452,10 @@ console.log(values.random);
452452
assert.notStrictEqual(pid, importPid);
453453
assert.deepStrictEqual(stdout, [
454454
'running',
455-
`Completed running ${inspect(file)}`,
455+
`Completed running ${inspect(file)}. Waiting for file changes before restarting...`,
456456
`Restarting ${inspect(file)}`,
457457
'running',
458-
`Completed running ${inspect(file)}`,
458+
`Completed running ${inspect(file)}. Waiting for file changes before restarting...`,
459459
]);
460460
});
461461

@@ -472,10 +472,10 @@ console.log(values.random);
472472

473473
assert.deepStrictEqual(stdout, [
474474
'running',
475-
`Completed running ${inspect(file)}`,
475+
`Completed running ${inspect(file)}. Waiting for file changes before restarting...`,
476476
`Restarting ${inspect(file)}`,
477477
'running',
478-
`Completed running ${inspect(file)}`,
478+
`Completed running ${inspect(file)}. Waiting for file changes before restarting...`,
479479
]);
480480
});
481481

@@ -521,10 +521,10 @@ console.log(values.random);
521521
assert.strictEqual(stderr, '');
522522
assert.deepStrictEqual(stdout, [
523523
'running',
524-
`Completed running ${inspect(file)}`,
524+
`Completed running ${inspect(file)}. Waiting for file changes before restarting...`,
525525
`Restarting ${inspect(file)}`,
526526
'running',
527-
`Completed running ${inspect(file)}`,
527+
`Completed running ${inspect(file)}. Waiting for file changes before restarting...`,
528528
]);
529529
});
530530

@@ -536,10 +536,10 @@ console.log(values.random);
536536
assert.strictEqual(stderr, '');
537537
assert.deepStrictEqual(stdout, [
538538
'running',
539-
`Completed running ${inspect(file)}`,
539+
`Completed running ${inspect(file)}. Waiting for file changes before restarting...`,
540540
`Restarting ${inspect(file)}`,
541541
'running',
542-
`Completed running ${inspect(file)}`,
542+
`Completed running ${inspect(file)}. Waiting for file changes before restarting...`,
543543
]);
544544
});
545545

@@ -567,11 +567,11 @@ console.log(values.random);
567567
assert.deepStrictEqual(stdout, [
568568
'hello',
569569
'running',
570-
`Completed running ${inspect(file)}`,
570+
`Completed running ${inspect(file)}. Waiting for file changes before restarting...`,
571571
`Restarting ${inspect(file)}`,
572572
'hello',
573573
'running',
574-
`Completed running ${inspect(file)}`,
574+
`Completed running ${inspect(file)}. Waiting for file changes before restarting...`,
575575
]);
576576
});
577577

@@ -599,11 +599,11 @@ console.log(values.random);
599599
assert.deepStrictEqual(stdout, [
600600
'hello',
601601
'running',
602-
`Completed running ${inspect(file)}`,
602+
`Completed running ${inspect(file)}. Waiting for file changes before restarting...`,
603603
`Restarting ${inspect(file)}`,
604604
'hello',
605605
'running',
606-
`Completed running ${inspect(file)}`,
606+
`Completed running ${inspect(file)}. Waiting for file changes before restarting...`,
607607
]);
608608
});
609609

@@ -631,11 +631,11 @@ console.log(values.random);
631631
assert.deepStrictEqual(stdout, [
632632
'hello',
633633
'running',
634-
`Completed running ${inspect(file)}`,
634+
`Completed running ${inspect(file)}. Waiting for file changes before restarting...`,
635635
`Restarting ${inspect(file)}`,
636636
'hello',
637637
'running',
638-
`Completed running ${inspect(file)}`,
638+
`Completed running ${inspect(file)}. Waiting for file changes before restarting...`,
639639
]);
640640
});
641641

@@ -663,11 +663,11 @@ console.log(values.random);
663663
assert.deepStrictEqual(stdout, [
664664
'hello',
665665
'running',
666-
`Completed running ${inspect(file)}`,
666+
`Completed running ${inspect(file)}. Waiting for file changes before restarting...`,
667667
`Restarting ${inspect(file)}`,
668668
'hello',
669669
'running',
670-
`Completed running ${inspect(file)}`,
670+
`Completed running ${inspect(file)}. Waiting for file changes before restarting...`,
671671
]);
672672
});
673673

@@ -679,10 +679,10 @@ console.log(values.random);
679679
assert.match(stderr, /listening on ws:\/\//);
680680
assert.deepStrictEqual(stdout, [
681681
'running',
682-
`Completed running ${inspect(file)}`,
682+
`Completed running ${inspect(file)}. Waiting for file changes before restarting...`,
683683
`Restarting ${inspect(file)}`,
684684
'running',
685-
`Completed running ${inspect(file)}`,
685+
`Completed running ${inspect(file)}. Waiting for file changes before restarting...`,
686686
]);
687687
});
688688

@@ -704,11 +704,11 @@ console.log(values.random);
704704
assert.deepStrictEqual(stdout, [
705705
'hello',
706706
'running',
707-
`Completed running ${inspect(file)}`,
707+
`Completed running ${inspect(file)}. Waiting for file changes before restarting...`,
708708
`Restarting ${inspect(file)}`,
709709
'hello',
710710
'running',
711-
`Completed running ${inspect(file)}`,
711+
`Completed running ${inspect(file)}. Waiting for file changes before restarting...`,
712712
]);
713713
});
714714

@@ -788,7 +788,7 @@ process.on('message', (message) => {
788788
`Restarting ${inspect(file)}`,
789789
'running',
790790
'Received: second message',
791-
`Completed running ${inspect(file)}`,
791+
`Completed running ${inspect(file)}. Waiting for file changes before restarting...`,
792792
]);
793793
});
794794
});

0 commit comments

Comments
 (0)