From 7587b3b2ee031851e548b3fdb17f848fc500d9b9 Mon Sep 17 00:00:00 2001 From: Rizky Luthfianto Date: Tue, 17 Oct 2017 22:49:08 +0700 Subject: [PATCH 1/5] feat(watcher): print commands info --- lib/watcher.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/watcher.js b/lib/watcher.js index 3f5ed3ee7..17b95a25a 100644 --- a/lib/watcher.js +++ b/lib/watcher.js @@ -126,6 +126,7 @@ class Watcher { .then(runStatus => { runStatus.previousFailCount = this.sumPreviousFailures(currentVector); logger.finish(runStatus); + logger.write('[ava] To rerun tests, enter `r`\n[ava] To update snapshots used in the previous test run, enter `u`'); const badCounts = runStatus.failCount + runStatus.rejectionCount + runStatus.exceptionCount; this.clearLogOnNextRun = this.clearLogOnNextRun && badCounts === 0; From 81aed1ca936df8d5bee415efd64f360666dd08ff Mon Sep 17 00:00:00 2001 From: Rizky Luthfianto Date: Thu, 26 Oct 2017 22:25:48 +0700 Subject: [PATCH 2/5] Use color on rerunMessage and add sinon spy for logger.write --- lib/watcher.js | 5 ++++- test/watcher.js | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/watcher.js b/lib/watcher.js index 17b95a25a..01573d35d 100644 --- a/lib/watcher.js +++ b/lib/watcher.js @@ -1,4 +1,5 @@ 'use strict'; +const chalk = require('chalk'); const nodePath = require('path'); const debug = require('debug')('ava:watcher'); const diff = require('lodash.difference'); @@ -18,6 +19,8 @@ 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"); + class Debouncer { constructor(watcher) { @@ -126,7 +129,7 @@ class Watcher { .then(runStatus => { runStatus.previousFailCount = this.sumPreviousFailures(currentVector); logger.finish(runStatus); - logger.write('[ava] To rerun tests, enter `r`\n[ava] To update snapshots used in the previous test run, enter `u`'); + logger.write(rerunMessage); const badCounts = runStatus.failCount + runStatus.rejectionCount + runStatus.exceptionCount; this.clearLogOnNextRun = this.clearLogOnNextRun && badCounts === 0; diff --git a/test/watcher.js b/test/watcher.js index bb8e70bdc..a7dfe8e8f 100644 --- a/test/watcher.js +++ b/test/watcher.js @@ -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 = { From 502ff4f1b0498d97b8885ba9f81aec2898adcf97 Mon Sep 17 00:00:00 2001 From: Rizky Luthfianto Date: Thu, 26 Oct 2017 22:47:07 +0700 Subject: [PATCH 3/5] Use apostrophe instead of double quotes --- lib/watcher.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/watcher.js b/lib/watcher.js index 01573d35d..82538de41 100644 --- a/lib/watcher.js +++ b/lib/watcher.js @@ -1,6 +1,6 @@ 'use strict'; -const chalk = require('chalk'); const nodePath = require('path'); +const chalk = require('chalk'); const debug = require('debug')('ava:watcher'); const diff = require('lodash.difference'); const chokidar = require('chokidar'); @@ -19,8 +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"); - +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`); class Debouncer { constructor(watcher) { From 6de3a6e02a157e450815ba1afaf6171fe75c282f Mon Sep 17 00:00:00 2001 From: Rizky Luthfianto Date: Wed, 8 Nov 2017 23:39:35 +0700 Subject: [PATCH 4/5] test(watcher.js): Add assertion on logger.write call count --- test/watcher.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/watcher.js b/test/watcher.js index a7dfe8e8f..1fa3d08af 100644 --- a/test/watcher.js +++ b/test/watcher.js @@ -211,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 => { @@ -224,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]); @@ -233,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); }); }); From c90b54a5b3a00637fff262a879f70d0e6d42192b Mon Sep 17 00:00:00 2001 From: Rizky Luthfianto Date: Sat, 18 Nov 2017 17:30:10 +0700 Subject: [PATCH 5/5] test(cli.js): Add the watcher rerunMessage into assertion --- test/cli.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/cli.js b/test/cli.js index ed2805734..54fcb7c87 100644 --- a/test/cli.js +++ b/test/cli.js @@ -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); } }); });