From cd256ac53c975d51ddabd3d80a9f909424f5d7e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stanis=C5=82aw=20Jaros?= Date: Sun, 17 Mar 2019 17:30:06 +0100 Subject: [PATCH] Print commands in watch mode --- lib/watcher.js | 3 +++ test/integration/watcher.js | 4 +++- test/watcher.js | 13 ++++++++++--- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/watcher.js b/lib/watcher.js index 8f9c8446a..2110809fb 100644 --- a/lib/watcher.js +++ b/lib/watcher.js @@ -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) { @@ -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) { @@ -123,6 +125,7 @@ class Watcher { }) .then(runStatus => { reporter.endRun(); + reporter.lineWriter.writeLine(END_MESSAGE); if (this.clearLogOnNextRun && ( runStatus.stats.failedHooks > 0 || diff --git a/test/integration/watcher.js b/test/integration/watcher.js index 780c03c50..faa1469bf 100644 --- a/test/integration/watcher.js +++ b/test/integration/watcher.js @@ -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; @@ -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, ''), ''), ''); } }); }); diff --git a/test/watcher.js b/test/watcher.js index 22df917ee..a0e06d7f5 100644 --- a/test/watcher.js +++ b/test/watcher.js @@ -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) => { @@ -71,7 +73,10 @@ group('chokidar', (beforeEach, test, group) => { debug = sinon.spy(); reporter = { - endRun: sinon.spy() + endRun: sinon.spy(), + lineWriter: { + writeLine: sinon.spy() + } }; api = { @@ -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 => { @@ -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); }); });