Skip to content

Commit 81b7f1e

Browse files
committed
also rerun tests when 'r' is entered
'r' is 100% quicker to type than 'rs' 💥 Retain 'rs' for those with nodemon muscle memory.
1 parent 755849f commit 81b7f1e

File tree

3 files changed

+73
-71
lines changed

3 files changed

+73
-71
lines changed

docs/recipes/watch-mode.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ Dependency tracking works for required modules. Custom extensions and transpiler
6969

7070
## Manually rerunning all tests
7171

72-
You can quickly rerun all tests by typing <kbd>rs</kbd> on the console, followed by <kbd>Enter</kbd>. [Just like in `nodemon`](https://github.com/remy/nodemon#manual-restarting)!
72+
You can quickly rerun all tests by typing <kbd>r</kbd> on the console, followed by <kbd>Enter</kbd>.
7373

7474
## Debugging
7575

lib/watcher.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ Watcher.prototype.observeStdin = function (stdin) {
120120
stdin.setEncoding('utf8');
121121
stdin.on('data', function (data) {
122122
data = data.trim().toLowerCase();
123-
if (data !== 'rs') {
123+
if (data !== 'r' && data !== 'rs') {
124124
return;
125125
}
126126

test/watcher.js

Lines changed: 71 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -508,91 +508,93 @@ group('chokidar is installed', function (beforeEach, test, group) {
508508
});
509509
});
510510

511-
test('reruns initial tests when "rs" is entered on stdin', function (t) {
512-
t.plan(2);
513-
api.run.returns(Promise.resolve());
514-
start().observeStdin(stdin);
511+
["r", "rs"].forEach(function (input) {
512+
test('reruns initial tests when "' + input + '" is entered on stdin', function (t) {
513+
t.plan(2);
514+
api.run.returns(Promise.resolve());
515+
start().observeStdin(stdin);
515516

516-
stdin.write('rs\n');
517-
return delay().then(function () {
518-
t.ok(api.run.calledTwice);
517+
stdin.write(input + '\n');
518+
return delay().then(function () {
519+
t.ok(api.run.calledTwice);
519520

520-
stdin.write('\trs \n');
521-
return delay();
522-
}).then(function () {
523-
t.ok(api.run.calledThrice);
521+
stdin.write('\t' + input + ' \n');
522+
return delay();
523+
}).then(function () {
524+
t.ok(api.run.calledThrice);
525+
});
524526
});
525-
});
526527

527-
test('entering "rs" on stdin cancels any debouncing', function (t) {
528-
t.plan(7);
529-
api.run.returns(Promise.resolve());
530-
start().observeStdin(stdin);
528+
test('entering "' + input + '" on stdin cancels any debouncing', function (t) {
529+
t.plan(7);
530+
api.run.returns(Promise.resolve());
531+
start().observeStdin(stdin);
531532

532-
var before = clock.now;
533-
var done;
534-
api.run.returns(new Promise(function (resolve) {
535-
done = resolve;
536-
}));
533+
var before = clock.now;
534+
var done;
535+
api.run.returns(new Promise(function (resolve) {
536+
done = resolve;
537+
}));
537538

538-
add();
539-
stdin.write('rs\n');
540-
return delay().then(function () {
541-
// Processing "rs" caused a new run.
542-
t.ok(api.run.calledTwice);
539+
add();
540+
stdin.write(input + '\n');
541+
return delay().then(function () {
542+
// Processing "rs" caused a new run.
543+
t.ok(api.run.calledTwice);
543544

544-
// Try to advance the clock. This is *after* "rs" was processed. The
545-
// debounce timeout should have been canceled, so the clock can't have
546-
// advanced.
547-
clock.next();
548-
t.is(before, clock.now);
545+
// Try to advance the clock. This is *after* input was processed. The
546+
// debounce timeout should have been canceled, so the clock can't have
547+
// advanced.
548+
clock.next();
549+
t.is(before, clock.now);
549550

550-
add();
551-
// Advance clock *before* "rs" is received. Note that the previous run
552-
// hasn't finished yet.
553-
clock.next();
554-
stdin.write('rs\n');
551+
add();
552+
// Advance clock *before* input is received. Note that the previous run
553+
// hasn't finished yet.
554+
clock.next();
555+
stdin.write(input + '\n');
555556

556-
return delay();
557-
}).then(function () {
558-
// No new runs yet.
559-
t.ok(api.run.calledTwice);
560-
// Though the clock has advanced.
561-
t.is(clock.now - before, 10);
562-
before = clock.now;
557+
return delay();
558+
}).then(function () {
559+
// No new runs yet.
560+
t.ok(api.run.calledTwice);
561+
// Though the clock has advanced.
562+
t.is(clock.now - before, 10);
563+
before = clock.now;
563564

564-
var previous = done;
565-
api.run.returns(new Promise(function (resolve) {
566-
done = resolve;
567-
}));
565+
var previous = done;
566+
api.run.returns(new Promise(function (resolve) {
567+
done = resolve;
568+
}));
568569

569-
// Finish the previous run.
570-
previous();
570+
// Finish the previous run.
571+
previous();
571572

572-
return delay();
573-
}).then(function () {
574-
// There's only one new run.
575-
t.ok(api.run.calledThrice);
573+
return delay();
574+
}).then(function () {
575+
// There's only one new run.
576+
t.ok(api.run.calledThrice);
576577

577-
stdin.write('rs\n');
578-
return delay();
579-
}).then(function () {
580-
add();
578+
stdin.write(input + '\n');
579+
return delay();
580+
}).then(function () {
581+
add();
581582

582-
// Finish the previous run. This should cause a new run due to the "rs"
583-
// input.
584-
done();
583+
// Finish the previous run. This should cause a new run due to the
584+
// input.
585+
done();
585586

586-
return delay();
587-
}).then(function () {
588-
// Again there's only one new run.
589-
t.is(api.run.callCount, 4);
587+
return delay();
588+
}).then(function () {
589+
// Again there's only one new run.
590+
t.is(api.run.callCount, 4);
590591

591-
// Try to advance the clock. This is *after* "rs" was processed. The
592-
// debounce timeout should have been canceled, so the clock can't have
593-
// advanced.
594-
clock.next();
595-
t.is(before, clock.now);
592+
// Try to advance the clock. This is *after* input was processed. The
593+
// debounce timeout should have been canceled, so the clock can't have
594+
// advanced.
595+
clock.next();
596+
t.is(before, clock.now);
597+
});
596598
});
597599
});
598600

0 commit comments

Comments
 (0)