Skip to content

Commit

Permalink
Print commands in watch mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanis艂aw Jaros authored and novemberborn committed Mar 17, 2019
1 parent 960f4cd commit cd256ac
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
3 changes: 3 additions & 0 deletions lib/watcher.js
Expand Up @@ -6,6 +6,7 @@ const chokidar = require('chokidar');
const flatten = require('arr-flatten');
const union = require('array-union');
const uniq = require('array-uniq');
const chalk = require('./chalk').get();
const AvaFiles = require('./ava-files');

function rethrowAsync(err) {
Expand All @@ -18,6 +19,7 @@ function rethrowAsync(err) {

const MIN_DEBOUNCE_DELAY = 10;
const INITIAL_DEBOUNCE_DELAY = 100;
const END_MESSAGE = chalk.gray('Type `r` and press enter to rerun tests\nType `u` and press enter to update snapshots\n');

class Debouncer {
constructor(watcher) {
Expand Down Expand Up @@ -123,6 +125,7 @@ class Watcher {
})
.then(runStatus => {
reporter.endRun();
reporter.lineWriter.writeLine(END_MESSAGE);

if (this.clearLogOnNextRun && (
runStatus.stats.failedHooks > 0 ||
Expand Down
4 changes: 3 additions & 1 deletion test/integration/watcher.js
Expand Up @@ -4,6 +4,8 @@ const {test} = require('tap');
const touch = require('touch');
const {execCli} = require('../helper/cli');

const END_MESSAGE = 'Type `r` and press enter to rerun tests\nType `u` and press enter to update snapshots\n';

test('watcher reruns test files when they changed', t => {
let killed = false;

Expand Down Expand Up @@ -101,7 +103,7 @@ 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, ''), '');
t.is(buffer.replace(/\s/g, '').replace(END_MESSAGE.replace(/\s/g, ''), ''), '');
}
});
});
Expand Down
13 changes: 10 additions & 3 deletions test/watcher.js
Expand Up @@ -10,6 +10,8 @@ const {test} = require('tap');
const AvaFiles = require('../lib/ava-files');
const {setImmediate} = require('../lib/now-and-timers');

require('../lib/chalk').set({});

// Helper to make using beforeEach less arduous
function makeGroup(test) {
return (desc, fn) => {
Expand Down Expand Up @@ -71,7 +73,10 @@ group('chokidar', (beforeEach, test, group) => {
debug = sinon.spy();

reporter = {
endRun: sinon.spy()
endRun: sinon.spy(),
lineWriter: {
writeLine: sinon.spy()
}
};

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

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

let done;
api.run.returns(new Promise(resolve => {
Expand All @@ -234,11 +239,13 @@ group('chokidar', (beforeEach, test, group) => {
t.ok(api.run.calledOnce);
t.strictDeepEqual(api.run.firstCall.args, [files, defaultApiOptions]);

// The endRun method is only called after the run promise fulfils
// The endRun and lineWriter.writeLine methods are only called after the run promise fulfils
t.ok(reporter.endRun.notCalled);
t.ok(reporter.lineWriter.writeLine.notCalled);
done();
return delay().then(() => {
t.ok(reporter.endRun.calledOnce);
t.ok(reporter.lineWriter.writeLine.calledOnce);
});
});

Expand Down

0 comments on commit cd256ac

Please sign in to comment.