From 840e15900576c6d658e6a6d69b74358245259b32 Mon Sep 17 00:00:00 2001 From: Keegan Street Date: Sun, 28 Aug 2016 16:45:31 +1000 Subject: [PATCH] Printing "complete" output when no results are found --- lib/element-finder.js | 13 +++++++++++++ test/test.js | 5 +++++ 2 files changed, 18 insertions(+) diff --git a/lib/element-finder.js b/lib/element-finder.js index 16a2ec9..9c5524f 100755 --- a/lib/element-finder.js +++ b/lib/element-finder.js @@ -151,6 +151,7 @@ module.exports = function(options, progressCallback) { 'numberOfFiles': numberOfFiles, 'numberOfFilesWithMatches': numberOfFilesWithMatches, 'duration': duration, + 'selector': options.selector, 'message': '\nFound ' + pluralise(totalMatches, 'match', 'matches') + ' in ' + pluralise(numberOfFilesWithMatches, 'file', 'files') + ' (' + duration + ' seconds).' }); } @@ -175,6 +176,18 @@ module.exports = function(options, progressCallback) { for (i = 0; i < numberOfFiles; i += 1) { processFile(i, files[i]); } + if (totalMatches === 0) { + duration = (Date.now() - startTime) / 1000; + progressCallback({ + 'status': 'complete', + 'totalMatches': totalMatches, + 'numberOfFiles': numberOfFiles, + 'numberOfFilesWithMatches': numberOfFilesWithMatches, + 'duration': duration, + 'selector': options.selector, + 'message': '\nNo results found (' + duration + ' seconds).' + }); + } }; if (options.files) { diff --git a/test/test.js b/test/test.js index bd076e2..f402ceb 100644 --- a/test/test.js +++ b/test/test.js @@ -68,4 +68,9 @@ var CLIeasy = require('cli-easy'), .expect('should find 11 matches in 3 files', /Found 11 matches in 3 files./) .undiscuss() + .discuss('testing input that returns zero results') + .arg('-s ".made-up-classname-that-is-not-used"') + .expect('should find zero results', /No results found/) + .undiscuss() + .export(module);