From fc0507ed742cb7ab54bcf60f88a0ea0c64b38289 Mon Sep 17 00:00:00 2001 From: Craig Taub Date: Fri, 4 Jan 2019 08:11:51 +0000 Subject: [PATCH] Fix message if no files found (#3650) * error and exit, dont warn * return after error dont exit yet * remove superflous message * update glob tests * update message * use errors only if no tests found * dont use error symbol. --- lib/cli/run-helpers.js | 14 +++++++++++--- lib/utils.js | 2 +- test/integration/glob.spec.js | 12 ++++++------ 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/lib/cli/run-helpers.js b/lib/cli/run-helpers.js index 5212d386db..95d1c2fc08 100644 --- a/lib/cli/run-helpers.js +++ b/lib/cli/run-helpers.js @@ -14,7 +14,6 @@ const path = require('path'); const utils = require('../utils'); const minimatch = require('minimatch'); const ansi = require('ansi-colors'); -const symbols = require('log-symbols'); const cwd = (exports.cwd = process.cwd()); @@ -138,13 +137,14 @@ exports.handleFiles = ({ spec = [] } = {}) => { let files = []; + const errors = []; spec.forEach(arg => { let newFiles; try { newFiles = utils.lookupFiles(arg, extension, recursive); } catch (err) { if (err.code === 'ERR_MOCHA_NO_FILES_MATCH_PATTERN') { - console.warn('Warning: %s: %O', err.message, err.pattern); + errors.push(err.message); return; } @@ -164,8 +164,16 @@ exports.handleFiles = ({ }); if (!files.length) { - console.error(ansi.red(`${symbols.error} No test files found`)); + // print messages as an error + errors.forEach(message => { + console.error(ansi.red(`Error: ${message}`)); + }); process.exit(1); + } else { + // print messages as an warning + errors.forEach(message => { + console.warn(ansi.yellow(`Warning: ${message}`)); + }); } const fileArgs = file.map(filepath => path.resolve(filepath)); diff --git a/lib/utils.js b/lib/utils.js index f2f2af4145..c6d42ba9a5 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -520,7 +520,7 @@ exports.lookupFiles = function lookupFiles(filepath, extensions, recursive) { files = glob.sync(filepath); if (!files.length) { throw createNoFilesMatchPatternError( - 'cannot find any files matching pattern "' + filepath + '"', + 'Cannot find any files matching pattern "' + filepath + '"', filepath ); } diff --git a/test/integration/glob.spec.js b/test/integration/glob.spec.js index 6aa7563bf5..da1f5f35c6 100644 --- a/test/integration/glob.spec.js +++ b/test/integration/glob.spec.js @@ -28,7 +28,7 @@ describe('globbing', function() { expect( results.stderr, 'to contain', - 'cannot find any files matching pattern "./*-none.js"' + 'Error: Cannot find any files matching pattern "./*-none.js"' ); }, done @@ -47,7 +47,7 @@ describe('globbing', function() { expect( results.stderr, 'to contain', - 'cannot find any files matching pattern' + 'Warning: Cannot find any files matching pattern' ); }, done @@ -77,7 +77,7 @@ describe('globbing', function() { expect( results.stderr, 'to contain', - 'cannot find any files matching pattern' + 'Error: Cannot find any files matching pattern "./*-none.js"' ); }, done @@ -96,7 +96,7 @@ describe('globbing', function() { expect( results.stderr, 'to contain', - 'cannot find any files matching pattern' + 'Warning: Cannot find any files matching pattern' ); }, done @@ -125,7 +125,7 @@ describe('globbing', function() { expect( results.stderr, 'to contain', - 'cannot find any files matching pattern' + 'Error: Cannot find any files matching pattern "./**/*-none.js"' ); }, done @@ -144,7 +144,7 @@ describe('globbing', function() { expect( results.stderr, 'to contain', - 'cannot find any files matching pattern' + 'Warning: Cannot find any files matching pattern' ); }, done