Skip to content

Print watch mode shortcut commands #1555

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/watcher.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';
const nodePath = require('path');
const chalk = require('chalk');
const debug = require('debug')('ava:watcher');
const diff = require('lodash.difference');
const chokidar = require('chokidar');
Expand All @@ -18,6 +19,7 @@ function rethrowAsync(err) {

const MIN_DEBOUNCE_DELAY = 10;
const INITIAL_DEBOUNCE_DELAY = 100;
const rerunMessage = chalk.gray.dim(`To rerun all tests, type 'r', followed by Enter\nTo update snapshots used in the previous tests, type 'u', followed by Enter\n`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at this in my terminal I think this should just be chalk.gray. But we then should also update the timestamp output in the mini & verbose loggers to not be dimmed.


class Debouncer {
constructor(watcher) {
Expand Down Expand Up @@ -126,6 +128,7 @@ class Watcher {
.then(runStatus => {
runStatus.previousFailCount = this.sumPreviousFailures(currentVector);
logger.finish(runStatus);
logger.write(rerunMessage);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately this doesn't work with the mini reporter. I think finish() should take an optional second parameter, call it footer perhaps, and both the mini and verbose loggers can then include this in their regular output.


const badCounts = runStatus.failCount + runStatus.rejectionCount + runStatus.exceptionCount;
this.clearLogOnNextRun = this.clearLogOnNextRun && badCounts === 0;
Expand Down
4 changes: 3 additions & 1 deletion test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,9 @@ test('watcher does not rerun test files when they write snapshot files', t => {
killed = true;
}, 500);
} else if (passedFirst && !killed) {
t.is(buffer.replace(/\s/g, ''), '');
const rerunMessage = `To rerun all tests, type 'r', followed by Enter\nTo update snapshots used in the previous tests, type 'u', followed by Enter\n`;
const rerunMessageWithoutWhitespace = rerunMessage.replace(/\s/g, '');
t.is(buffer.replace(/\s/g, ''), rerunMessageWithoutWhitespace);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@novemberborn I'm not sure if what I did (asserting this) is the right way to do this

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most tests use t.match for this. You could do an assertion for each line.

}
});
});
Expand Down
7 changes: 5 additions & 2 deletions test/watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ group('chokidar', (beforeEach, test, group) => {
finish: sinon.spy(),
section: sinon.spy(),
clear: sinon.stub().returns(true),
reset: sinon.spy()
reset: sinon.spy(),
write: sinon.spy()
};

api = {
Expand Down Expand Up @@ -210,7 +211,7 @@ group('chokidar', (beforeEach, test, group) => {
});

test('starts running the initial tests', t => {
t.plan(8);
t.plan(10);

let done;
api.run.returns(new Promise(resolve => {
Expand All @@ -223,6 +224,7 @@ group('chokidar', (beforeEach, test, group) => {
t.ok(logger.clear.notCalled);
t.ok(logger.reset.notCalled);
t.ok(logger.start.notCalled);
t.ok(logger.write.notCalled);
t.ok(api.run.calledOnce);
t.strictDeepEqual(api.run.firstCall.args, [files, defaultApiOptions]);

Expand All @@ -232,6 +234,7 @@ group('chokidar', (beforeEach, test, group) => {
return delay().then(() => {
t.ok(logger.finish.calledOnce);
t.is(logger.finish.firstCall.args[0], runStatus);
t.ok(logger.write.calledOnce);
});
});

Expand Down