Skip to content

Commit

Permalink
also rerun tests when 'r' is entered
Browse files Browse the repository at this point in the history
'r' is 100% quicker to type than 'rs' 💥

Retain 'rs' for those with nodemon muscle memory.
  • Loading branch information
novemberborn committed Mar 8, 2016
1 parent 755849f commit 81b7f1e
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 71 deletions.
2 changes: 1 addition & 1 deletion docs/recipes/watch-mode.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Dependency tracking works for required modules. Custom extensions and transpiler

## Manually rerunning all tests

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)!
You can quickly rerun all tests by typing <kbd>r</kbd> on the console, followed by <kbd>Enter</kbd>.

## Debugging

Expand Down
2 changes: 1 addition & 1 deletion lib/watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ Watcher.prototype.observeStdin = function (stdin) {
stdin.setEncoding('utf8');
stdin.on('data', function (data) {
data = data.trim().toLowerCase();
if (data !== 'rs') {
if (data !== 'r' && data !== 'rs') {
return;
}

Expand Down
140 changes: 71 additions & 69 deletions test/watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -508,91 +508,93 @@ group('chokidar is installed', function (beforeEach, test, group) {
});
});

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

stdin.write('rs\n');
return delay().then(function () {
t.ok(api.run.calledTwice);
stdin.write(input + '\n');
return delay().then(function () {
t.ok(api.run.calledTwice);

stdin.write('\trs \n');
return delay();
}).then(function () {
t.ok(api.run.calledThrice);
stdin.write('\t' + input + ' \n');
return delay();
}).then(function () {
t.ok(api.run.calledThrice);
});
});
});

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

var before = clock.now;
var done;
api.run.returns(new Promise(function (resolve) {
done = resolve;
}));
var before = clock.now;
var done;
api.run.returns(new Promise(function (resolve) {
done = resolve;
}));

add();
stdin.write('rs\n');
return delay().then(function () {
// Processing "rs" caused a new run.
t.ok(api.run.calledTwice);
add();
stdin.write(input + '\n');
return delay().then(function () {
// Processing "rs" caused a new run.
t.ok(api.run.calledTwice);

// Try to advance the clock. This is *after* "rs" was processed. The
// debounce timeout should have been canceled, so the clock can't have
// advanced.
clock.next();
t.is(before, clock.now);
// Try to advance the clock. This is *after* input was processed. The
// debounce timeout should have been canceled, so the clock can't have
// advanced.
clock.next();
t.is(before, clock.now);

add();
// Advance clock *before* "rs" is received. Note that the previous run
// hasn't finished yet.
clock.next();
stdin.write('rs\n');
add();
// Advance clock *before* input is received. Note that the previous run
// hasn't finished yet.
clock.next();
stdin.write(input + '\n');

return delay();
}).then(function () {
// No new runs yet.
t.ok(api.run.calledTwice);
// Though the clock has advanced.
t.is(clock.now - before, 10);
before = clock.now;
return delay();
}).then(function () {
// No new runs yet.
t.ok(api.run.calledTwice);
// Though the clock has advanced.
t.is(clock.now - before, 10);
before = clock.now;

var previous = done;
api.run.returns(new Promise(function (resolve) {
done = resolve;
}));
var previous = done;
api.run.returns(new Promise(function (resolve) {
done = resolve;
}));

// Finish the previous run.
previous();
// Finish the previous run.
previous();

return delay();
}).then(function () {
// There's only one new run.
t.ok(api.run.calledThrice);
return delay();
}).then(function () {
// There's only one new run.
t.ok(api.run.calledThrice);

stdin.write('rs\n');
return delay();
}).then(function () {
add();
stdin.write(input + '\n');
return delay();
}).then(function () {
add();

// Finish the previous run. This should cause a new run due to the "rs"
// input.
done();
// Finish the previous run. This should cause a new run due to the
// input.
done();

return delay();
}).then(function () {
// Again there's only one new run.
t.is(api.run.callCount, 4);
return delay();
}).then(function () {
// Again there's only one new run.
t.is(api.run.callCount, 4);

// Try to advance the clock. This is *after* "rs" was processed. The
// debounce timeout should have been canceled, so the clock can't have
// advanced.
clock.next();
t.is(before, clock.now);
// Try to advance the clock. This is *after* input was processed. The
// debounce timeout should have been canceled, so the clock can't have
// advanced.
clock.next();
t.is(before, clock.now);
});
});
});

Expand Down

0 comments on commit 81b7f1e

Please sign in to comment.